Skip to content

Commit c032f17

Browse files
authored
Merge pull request #468 from cglewis/master
closes #467; stubs for #465
2 parents 1453321 + 9c209ed commit c032f17

File tree

8 files changed

+207
-116
lines changed

8 files changed

+207
-116
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,20 @@ export controller_pass=pass
7777
BCF is now configured and ready for use with Poseidon, continue on to the [Starting Poseidon using Vent](#starting-poseidon-using-vent) section.
7878

7979
#### FAUCET Configuration
80-
Poseidon will connect to FAUCET using SSH, so you'll need to create an account that can SSH to the machine running FAUCET and that has rights to modify the configuration file `faucet.yaml` (currently Poseidon expects it to be in the default `/etc/ryu/faucet/faucet.yaml` location and `dps` must all be defined in this file for Poseidon to update the network posture correctly). The easiest way to set these values so that Poseidon can use them is in environment variables like so (assuming the controller is running at `192.168.1.10`):
80+
Unless Poseidon and FAUCET are running on the same host, Poseidon will connect to FAUCET using SSH. So you'll need to create an account that can SSH to the machine running FAUCET and that has rights to modify the configuration file `faucet.yaml` (currently Poseidon expects it to be in the default `/etc/ryu/faucet/faucet.yaml` location and `dps` must all be defined in this file for Poseidon to update the network posture correctly). The easiest way to set these values so that Poseidon can use them is in environment variables like so (assuming the controller is running at `192.168.1.10`):
8181

8282
```
8383
export controller_type=faucet
8484
export controller_uri=192.168.1.10
8585
export controller_user=user
8686
export controller_pass=pass
87+
export controller_log_file=/var/log/ryu/faucet/faucet.log
88+
export controller_config_file=/etc/ryu/faucet/faucet.yaml
8789
export controller_mirror_ports='{"switch1":3}' # a python dictionary of switch names (from faucet.yaml) and switch port numbers for mirroring to
8890
```
8991

92+
If Poseidon and FAUCET are running on the same host, only the `controller_type` and `controller_mirror_ports` need to be set.
93+
9094
FAUCET is now configured and ready for use with Poseidon, continue on to the [Starting Poseidon using Vent](#starting-poseidon-using-vent) section.
9195

9296
#### Starting Poseidon using Vent

helpers/run

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ docker run -it \
99
-e controller_user=$controller_user \
1010
-e controller_pass=$controller_pass \
1111
-e controller_type=$controller_type \
12+
-e controller_log_file=$controller_log_file \
13+
-e controller_config_file=$controller_config_file \
1214
-e collector_nic=$collector_nic \
1315
-e controller_mirror_ports=$controller_mirror_ports \
1416
-e max_concurrent_reinvestigations=$max_concurrent_reinvestigations \

poseidon/poseidonMonitor/NorthBoundControllerAbstraction/UpdateSwitchState.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ def __init__(self):
4444
self.retval = {}
4545
self.times = 0
4646
self.owner = None
47+
48+
# settings for all controllers
4749
self.controller = {}
4850
self.controller['URI'] = None
4951
self.controller['USER'] = None
5052
self.controller['PASS'] = None
5153
self.controller['TYPE'] = None
54+
55+
# settings for FAUCET
56+
self.controller['CONFIG_FILE'] = None
57+
self.controller['LOG_FILE'] = None
58+
self.controller['MIRROR_PORTS'] = None
59+
5260
self.sdnc = None
5361
self.first_time = True
5462
self.endpoints = Endpoint_Wrapper()
@@ -82,19 +90,24 @@ def first_run(self):
8290
self.controller['URI']))
8391
elif self.controller['TYPE'] == 'faucet':
8492
try:
85-
self.controller['URI'] = str(
86-
self.mod_configuration['controller_uri'])
87-
# TODO set defaults if these are not set
88-
self.controller['USER'] = str(
89-
self.mod_configuration['controller_user'])
90-
self.controller['PASS'] = str(
91-
self.mod_configuration['controller_pass'])
92-
self.controller['CONFIG_FILE'] = str(
93-
self.mod_configuration['controller_config_file'])
94-
self.controller['LOG_FILE'] = str(
95-
self.mod_configuration['controller_log_file'])
96-
self.controller['MIRROR_PORTS'] = ast.literal_eval(
97-
self.mod_configuration['controller_mirror_ports'])
93+
if 'controller_uri' in self.mod_configuration:
94+
self.controller['URI'] = str(
95+
self.mod_configuration['controller_uri'])
96+
if 'controller_user' in self.mod_configuration:
97+
self.controller['USER'] = str(
98+
self.mod_configuration['controller_user'])
99+
if 'controller_pass' in self.mod_configuration:
100+
self.controller['PASS'] = str(
101+
self.mod_configuration['controller_pass'])
102+
if 'controller_config_file' in self.mod_configuration:
103+
self.controller['CONFIG_FILE'] = str(
104+
self.mod_configuration['controller_config_file'])
105+
if 'controller_log_file' in self.mod_configuration:
106+
self.controller['LOG_FILE'] = str(
107+
self.mod_configuration['controller_log_file'])
108+
if 'controller_mirror_ports' in self.mod_configuration:
109+
self.controller['MIRROR_PORTS'] = ast.literal_eval(
110+
self.mod_configuration['controller_mirror_ports'])
98111
self.sdnc = FaucetProxy(host=self.controller['URI'],
99112
user=self.controller['USER'],
100113
pw=self.controller['PASS'],

poseidon/poseidonMonitor/NorthBoundControllerAbstraction/proxy/faucet/connection.py

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
class Connection:
3232

3333
def __init__(self,
34-
host,
34+
host=None,
3535
user=None,
3636
pw=None,
3737
config_file=None,
@@ -45,23 +45,24 @@ def __init__(self,
4545
self.config_file = config_file
4646
self.log_file = log_file
4747
self.ssh = None
48-
# ensure directories exist
49-
self.config_dir = '/etc/ryu/faucet'
50-
self.log_dir = '/var/log/ryu/faucet'
51-
try:
52-
if not os.path.exists(self.config_dir):
53-
os.makedirs(self.config_dir)
54-
except PermissionError:
55-
self.config_dir = os.path.join(os.getcwd(), 'faucet')
56-
if not os.path.exists(self.config_dir):
57-
os.makedirs(self.config_dir)
58-
try:
59-
if not os.path.exists(self.log_dir):
60-
os.makedirs(self.log_dir)
61-
except PermissionError:
62-
self.log_dir = os.path.join(os.getcwd(), 'faucet')
63-
if not os.path.exists(self.log_dir):
64-
os.makedirs(self.log_dir)
48+
if self.host:
49+
# ensure directories exist
50+
self.config_dir = '/etc/ryu/faucet'
51+
self.log_dir = '/var/log/ryu/faucet'
52+
try:
53+
if not os.path.exists(self.config_dir):
54+
os.makedirs(self.config_dir)
55+
except PermissionError:
56+
self.config_dir = os.path.join(os.getcwd(), 'faucet')
57+
if not os.path.exists(self.config_dir):
58+
os.makedirs(self.config_dir)
59+
try:
60+
if not os.path.exists(self.log_dir):
61+
os.makedirs(self.log_dir)
62+
except PermissionError:
63+
self.log_dir = os.path.join(os.getcwd(), 'faucet')
64+
if not os.path.exists(self.log_dir):
65+
os.makedirs(self.log_dir)
6566

6667
def _connect(self):
6768
# TODO better logging
@@ -83,39 +84,47 @@ def exec_command(self, command):
8384

8485
def receive_file(self, f_type):
8586
# TODO option to receive other files (config can be multiple files)
86-
self._connect()
87-
# TODO better logging
88-
try:
89-
scp = SCPClient(self.ssh.get_transport())
90-
if f_type == 'config':
91-
scp.get(self.config_file,
92-
local_path=os.path.join(self.config_dir,
93-
'faucet.yaml'))
94-
elif f_type == 'log':
95-
scp.get(self.log_file,
96-
local_path=os.path.join(self.log_dir, 'faucet.log'))
97-
else:
87+
if self.host:
88+
self._connect()
89+
# TODO better logging
90+
try:
91+
scp = SCPClient(self.ssh.get_transport())
92+
if f_type == 'config':
93+
scp.get(self.config_file,
94+
local_path=os.path.join(self.config_dir,
95+
'faucet.yaml'))
96+
elif f_type == 'log':
97+
scp.get(self.log_file,
98+
local_path=os.path.join(self.log_dir,
99+
'faucet.log'))
100+
else:
101+
pass
102+
scp.close()
103+
except Exception as e: # pragma: no cover
98104
pass
99-
scp.close()
100-
except Exception as e: # pragma: no cover
101-
pass
102-
self._disconnect()
105+
self._disconnect()
103106

104107
def send_file(self, f_type):
105108
# TODO option to send other files (config can be multiple files)
106-
self._connect()
107-
# TODO better logging
108-
try:
109-
scp = SCPClient(self.ssh.get_transport())
110-
if f_type == 'config':
111-
scp.put(os.path.join(self.config_dir, 'faucet.yaml'),
112-
self.config_file)
113-
elif f_type == 'log':
114-
scp.put(os.path.join(self.log_dir, 'faucet.log'),
115-
self.log_file)
116-
else:
109+
if self.host:
110+
self._connect()
111+
# TODO better logging
112+
try:
113+
scp = SCPClient(self.ssh.get_transport())
114+
if f_type == 'config':
115+
scp.put(os.path.join(self.config_dir, 'faucet.yaml'),
116+
self.config_file)
117+
elif f_type == 'log':
118+
scp.put(os.path.join(self.log_dir, 'faucet.log'),
119+
self.log_file)
120+
else:
121+
pass
122+
scp.close()
123+
except Exception as e: # pragma: no cover
117124
pass
118-
scp.close()
119-
except Exception as e: # pragma: no cover
120-
pass
121-
self._disconnect()
125+
self._disconnect()
126+
127+
def event_listener(self):
128+
# TODO - if using an event adapter from FAUCET, such as rabbbitmq
129+
event = None
130+
return event

poseidon/poseidonMonitor/NorthBoundControllerAbstraction/proxy/faucet/faucet.py

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class FaucetProxy(Connection, Parser):
3333

3434
def __init__(self,
35-
host,
35+
host=None,
3636
user=None,
3737
pw=None,
3838
config_file=None,
@@ -65,10 +65,13 @@ def format_endpoints(data):
6565
return ret_list
6666

6767
def get_endpoints(self):
68-
self.receive_file('log')
6968
retval = []
7069

71-
mac_table = self.log(os.path.join(self.log_dir, 'faucet.log'))
70+
if self.host:
71+
self.receive_file('log')
72+
mac_table = self.log(os.path.join(self.log_dir, 'faucet.log'))
73+
else:
74+
mac_table = self.log(self.log_file)
7275
module_logger.debug('get_endpoints found:')
7376
for mac in mac_table:
7477
if (mac_table[mac][0]['ip-address'] != 'None' and
@@ -116,20 +119,27 @@ def shutdown_ip(self, ip_addr, shutdown=True, mac_addr=None):
116119
shutdowns = []
117120
port = 0
118121
switch = None
119-
self.receive_file('config')
120-
if self.config(os.path.join(self.config_dir, 'faucet.yaml'),
121-
'shutdown', int(port), switch):
122-
self.send_file('config')
123-
# TODO
122+
if self.host:
123+
self.receive_file('config')
124+
if self.config(os.path.join(self.config_dir, 'faucet.yaml'),
125+
'shutdown', int(port), switch):
126+
self.send_file('config')
127+
else:
128+
self.config(self.config_file, 'shutdown', int(port), switch)
129+
# TODO check if config was successfully updated
124130
return shutdowns
125131

126132
def shutdown_endpoint(self):
127133
port = 0
128134
switch = None
129-
self.receive_file('config')
130-
if self.config(os.path.join(self.config_dir, 'faucet.yaml'),
131-
'shutdown', int(port), switch):
132-
self.send_file('config')
135+
if self.host:
136+
self.receive_file('config')
137+
if self.config(os.path.join(self.config_dir, 'faucet.yaml'),
138+
'shutdown', int(port), switch):
139+
self.send_file('config')
140+
else:
141+
self.config(self.config_file, 'shutdown', int(port), switch)
142+
# TODO check if config was successfully updated
133143

134144
def get_highest(self):
135145
pass
@@ -138,32 +148,47 @@ def get_seq_by_ip(self):
138148
pass
139149

140150
def mirror_ip(self, ip):
141-
self.receive_file('log')
142-
mac_table = self.log(os.path.join(self.log_dir, 'faucet.log'))
151+
if self.host:
152+
self.receive_file('log')
153+
mac_table = self.log(os.path.join(self.log_dir, 'faucet.log'))
154+
else:
155+
mac_table = self.log(self.log_file)
143156
port = 0
144157
switch = None
145158
for mac in mac_table:
146159
if ip == mac_table[mac][0]['ip-address']:
147160
port = mac_table[mac][0]['port']
148161
switch = mac_table[mac][0]['segment']
149162
if port and switch:
150-
self.receive_file('config')
151-
if self.config(os.path.join(self.config_dir, 'faucet.yaml'),
152-
'mirror', int(port), switch):
153-
self.send_file('config')
163+
if self.host:
164+
self.receive_file('config')
165+
if self.config(os.path.join(self.config_dir, 'faucet.yaml'),
166+
'mirror', int(port), switch):
167+
self.send_file('config')
168+
else:
169+
self.config(self.config_file, 'mirror', int(port), switch)
170+
# TODO check if config was successfully updated
154171

155172
def unmirror_ip(self, ip):
156173
port = 0
157174
switch = None
158-
self.receive_file('config')
159-
if self.config(os.path.join(self.config_dir, 'faucet.yaml'),
160-
'unmirror', int(port), switch):
161-
self.send_file('config')
175+
if self.host:
176+
self.receive_file('config')
177+
if self.config(os.path.join(self.config_dir, 'faucet.yaml'),
178+
'unmirror', int(port), switch):
179+
self.send_file('config')
180+
else:
181+
self.config(self.config_file, 'unmirror', int(port), switch)
182+
# TODO check if config was successfully updated
162183

163184
def mirror_traffic(self):
164185
port = 0
165186
switch = None
166-
self.receive_file('config')
167-
if self.config(os.path.join(self.config_dir, 'faucet.yaml'),
168-
'mirror', int(port), switch):
169-
self.send_file('config')
187+
if self.host:
188+
self.receive_file('config')
189+
if self.config(os.path.join(self.config_dir, 'faucet.yaml'),
190+
'mirror', int(port), switch):
191+
self.send_file('config')
192+
else:
193+
self.config(self.config_file, 'mirror', int(port), switch)
194+
# TODO check if config was successfully updated

0 commit comments

Comments
 (0)