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

Adding and removing routes correctly

parent 2f57f057
...@@ -18,16 +18,16 @@ ...@@ -18,16 +18,16 @@
# #
# Symbolic name is used in metis_ctrl commands # 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 cost=1
routes=ccnx:/ipoc,ccnx:/test routes=ccnx:/ipoc,ccnx:/test
symbolic=eth0 symbolic=eth3
[wlan0] [wlan0]
nexthop=AA-BB-CC-11-22-33 nexthop=4C:EB:42:98:15:ED
cost=10 cost=10
routes=ccnx:/ipoc,ccnx:/test routes=ccnx:/ipoc,ccnx:/test
symbolic=wlan0 symbolic=wlan0
......
...@@ -43,16 +43,13 @@ device_state = { 0: "Unknown", ...@@ -43,16 +43,13 @@ device_state = { 0: "Unknown",
120: "Failed" 120: "Failed"
} }
def canonical_mac_address(addr):
return addr.lower().replace("-",":")
DBusGMainLoop(set_as_default=True) DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus() bus = dbus.SystemBus()
config = ConfigParser.RawConfigParser() config = ConfigParser.RawConfigParser()
config.readfp(open("../mc.cfg")) 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_remove_route = ["remove", "route"]
metis_add_route = ["add", "route"] metis_add_route = ["add", "route"]
metis_add_listener = ["add", "listener", "ether"] metis_add_listener = ["add", "listener", "ether"]
...@@ -91,25 +88,25 @@ def metis_ctrl_execute(cmdlist): ...@@ -91,25 +88,25 @@ def metis_ctrl_execute(cmdlist):
call(cmdlist) call(cmdlist)
def metis_connect(ni): def metis_connect(ni):
print "Making Metis connection for device %s." % (ni.get_prop("Interface")) if_name = ni.get_prop("Interface")
mac = canonical_mac_address(ni.get_prop("HwAddress")) print "Making Metis connection for device %s." % if_name
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"])
current_conn = connections[check_bssid] sym = config.get(if_name, 'symbolic') + "conn"
cost = config.get(if_name, 'cost')
else: print "Adding routes..."
current_conn = None 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): 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" print "Removing routes..."
for prefix in routes: sym = config.get(if_name, 'symbolic') + "conn"
metis_ctrl_execute(metis_ctrl_base + metis_remove_route + [current_conn] + [prefix]) for prefix in config.get(if_name, 'routes').split(','):
metis_ctrl_execute(metis_ctrl_base + metis_remove_route +
[sym] + [prefix])
# Callback functions # Callback functions
def device_added_cb(device_path): def device_added_cb(device_path):
...@@ -184,21 +181,22 @@ for d in devices: ...@@ -184,21 +181,22 @@ for d in devices:
continue continue
# Only interfaces specified in our config file # Only interfaces specified in our config file
if_name = ni.get_prop('Interface') if_name = str(ni.get_prop('Interface'))
dev_cfg = config[if_name] if not config.has_section(if_name):
if (dev_cfg == None):
continue; continue;
# Add to our main list of interfaces # Add to our main list of interfaces
network_ifs[d] = ni; network_ifs[d] = ni;
if_state = ni.get_prop('State')
print "<<%s>>" % ni.get_prop('Interface') print "<<%s>>" % ni.get_prop('Interface')
print " path: %s" % d print " path: %s" % d
print " name: %s" % if_name print " name: %s" % if_name
print " type: %s" % device_types[device_type] 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 " permaddr: %s" % ni.get_prop('PermHwAddress')
print " state: %s" % device_state[ni.get_prop('State')] print " state: %s" % device_state[if_state]
print "" print ""
match = bus.add_signal_receiver(device_state_change_cb, match = bus.add_signal_receiver(device_state_change_cb,
...@@ -208,17 +206,19 @@ for d in devices: ...@@ -208,17 +206,19 @@ for d in devices:
path=d, path_keyword="path") path=d, path_keyword="path")
dev_matches[d] = match dev_matches[d] = match
sym = config.get(if_name, 'symbolic')
# Add Metis listeners and connection for each and optionally, add routes if # Add Metis listeners and connection for each and optionally, add routes if
# interface is currently connected # interface is currently connected
print "Adding listener..." 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..." print "Adding connection..."
metis_ctrl_execute(metis_ctrl_base + metis_add_connection + [dev_cfg['symbolic']] + metis_ctrl_execute(metis_ctrl_base + metis_add_connection +
[dev_cfg['nexthop']] + [if_name]) [sym + "conn"] + [config.get(if_name, 'nexthop')] + [if_name])
# Add route if currently connected # Add routes if currently connected
if device_state == 100: if if_state == 100:
metis_connect(ni) metis_connect(ni)
gobject.MainLoop().run() 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