Commit 748a9aaa authored by Greg Rutz's avatar Greg Rutz

Adding and removing routes correctly

parent 2f57f057
......@@ -18,16 +18,16 @@
#
# Symbolic name is used in metis_ctrl commands
[eth0]
[eth3]
nexthop=8C-AE-4C-FD-CE-0D
nexthop=8C:AE:4C:FD:CE:0D
cost=1
routes=ccnx:/ipoc,ccnx:/test
symbolic=eth0
symbolic=eth3
[wlan0]
nexthop=AA-BB-CC-11-22-33
nexthop=4C:EB:42:98:15:ED
cost=10
routes=ccnx:/ipoc,ccnx:/test
symbolic=wlan0
......
......@@ -43,16 +43,13 @@ device_state = { 0: "Unknown",
120: "Failed"
}
def canonical_mac_address(addr):
return addr.lower().replace("-",":")
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
config = ConfigParser.RawConfigParser()
config.readfp(open("../mc.cfg"))
metis_ctrl_base = ["metis_control", "-k", "/home/grutz/.ccnx/.ccnx_keystore.pk12", "-p", "test"]
metis_ctrl_base = ["metis_control", "-k", "/home/grutz/.ccnx/.ccnx_keystore.p12", "-p", "test"]
metis_remove_route = ["remove", "route"]
metis_add_route = ["add", "route"]
metis_add_listener = ["add", "listener", "ether"]
......@@ -87,29 +84,29 @@ class NetworkInterface:
network_ifs = {}
def metis_ctrl_execute(cmdlist):
print "Executing cmd: ", cmdlist
call(cmdlist)
print "Executing cmd: ", cmdlist
call(cmdlist)
def metis_connect(ni):
print "Making Metis connection for device %s." % (ni.get_prop("Interface"))
mac = canonical_mac_address(ni.get_prop("HwAddress"))
print "Interface HW Address: %s" % hwaddr
print "Adding new routes..."
for prefix in routes:
metis_ctrl_execute(metis_ctrl_base + metis_add_route + [current_conn] + [prefix] + ["1"])
if_name = ni.get_prop("Interface")
print "Making Metis connection for device %s." % if_name
current_conn = connections[check_bssid]
else:
current_conn = None
sym = config.get(if_name, 'symbolic') + "conn"
cost = config.get(if_name, 'cost')
print "Adding routes..."
for prefix in config.get(if_name, 'routes').split(','):
metis_ctrl_execute(metis_ctrl_base + metis_add_route +
[sym] + [prefix] + [config.get(if_name, 'cost')])
def metis_disconnect(ni):
print "Metis disconnect for device %s." % (ni.get_prop("Interface"))
if_name = ni.get_prop("Interface")
print "Metis disconnect for device %s." % if_name
print "Removing routes"
for prefix in routes:
metis_ctrl_execute(metis_ctrl_base + metis_remove_route + [current_conn] + [prefix])
print "Removing routes..."
sym = config.get(if_name, 'symbolic') + "conn"
for prefix in config.get(if_name, 'routes').split(','):
metis_ctrl_execute(metis_ctrl_base + metis_remove_route +
[sym] + [prefix])
# Callback functions
def device_added_cb(device_path):
......@@ -184,21 +181,22 @@ for d in devices:
continue
# Only interfaces specified in our config file
if_name = ni.get_prop('Interface')
dev_cfg = config[if_name]
if (dev_cfg == None):
if_name = str(ni.get_prop('Interface'))
if not config.has_section(if_name):
continue;
# Add to our main list of interfaces
network_ifs[d] = ni;
if_state = ni.get_prop('State')
print "<<%s>>" % ni.get_prop('Interface')
print " path: %s" % d
print " name: %s" % if_name
print " type: %s" % device_types[device_type]
print " addr: %s" % mac
print " addr: %s" % ni.get_prop('HwAddress')
print " permaddr: %s" % ni.get_prop('PermHwAddress')
print " state: %s" % device_state[ni.get_prop('State')]
print " state: %s" % device_state[if_state]
print ""
match = bus.add_signal_receiver(device_state_change_cb,
......@@ -208,17 +206,19 @@ for d in devices:
path=d, path_keyword="path")
dev_matches[d] = match
sym = config.get(if_name, 'symbolic')
# Add Metis listeners and connection for each and optionally, add routes if
# interface is currently connected
print "Adding listener..."
metis_ctrl_execute(metis_ctrl_base + metis_add_listener + [dev_cfg['symbolic']])
metis_ctrl_execute(metis_ctrl_base + metis_add_listener +
[sym + "list"] + [if_name] + ["0xA0A0"])
print "Adding connection..."
metis_ctrl_execute(metis_ctrl_base + metis_add_connection + [dev_cfg['symbolic']] +
[dev_cfg['nexthop']] + [if_name])
metis_ctrl_execute(metis_ctrl_base + metis_add_connection +
[sym + "conn"] + [config.get(if_name, 'nexthop')] + [if_name])
# Add route if currently connected
if device_state == 100:
# Add routes if currently connected
if if_state == 100:
metis_connect(ni)
gobject.MainLoop().run()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment