Commit 2f57f057 authored by Greg Rutz's avatar Greg Rutz

Update to new config file format

parent 6a27e9c1
[Routes]
# Each section identifies a network interface name that we will
# track (e.g. eth0, wlan0, etc.).
#
# MAC Addresses can be delimited with either '-' or ':' chars
# AA:BB:cc:00:11:22 or AA-BB-cc-00-11-22
#
# Cost values are relative for all interfaces and determine the
# tendency of Metis to use that interface for forwarding interests.
# Lower cost interfaces will have more interests designated to them.
# For example, imaging an interface (eth0) with cost 1 and another
# interface (eth1) with cost 10. If the same routes are assigned
# to both eth1 and eth0, eth0 will be designated approximately 10
# interests for every interest sent to eth1
#
# Routes for each interface are comma-delimited and should each start
# with the standard ccnx: URI protocol indicator
#
# Symbolic name is used in metis_ctrl commands
prefix=ccnx:/ipoc
[eth0]
[Connections]
nexthop=8C-AE-4C-FD-CE-0D
cost=1
routes=ccnx:/ipoc,ccnx:/test
symbolic=eth0
# Maps ethernet MAC addresses for wired links to their corresponding
# connection MAC address at the next hop Metis daemon
#
# Note: Must use '-' character to separate MAC octets
#
# LocalMAC=NextHopMAC
[wlan0]
8C-AE-4C-FD-CE-0E=8C-AE-4C-FD-CE-0D
80-1F-02-AC-E2-9F=4C-EB-42-98-15-ED
nexthop=AA-BB-CC-11-22-33
cost=10
routes=ccnx:/ipoc,ccnx:/test
symbolic=wlan0
......@@ -43,23 +43,20 @@ 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"))
connections = dict(config.items("Connections"))
routes = dict(config.items("Routes")).values()
print "Connections: ", connections
print "Routes: ", routes
metis_ctrl_base = ["metis_control", "-k", "/home/grutz/.ccnx/.ccnx_keystore.pk12", "-p", "test"]
metis_remove_route = ["remove", "route"]
metis_add_route = ["add", "route"]
metis_add_listener = ["add", "listener", "ether"]
metis_add_connection = ["add", "connection", "ether"]
current_conn = None
class NetworkInterface:
......@@ -73,7 +70,6 @@ class NetworkInterface:
# Returns a property value for this device. The base device properties are
# checked first, followed by the device subtype
def get_prop(self, propname):
baseprops = self.deviceprops_if.GetAll(_NETMGR_DEVICE_IF)
if propname in baseprops:
return baseprops[propname]
......@@ -85,6 +81,9 @@ class NetworkInterface:
return devprops[propname]
return None
def set_prop(self, propname, value):
self.deviceprops_if.Set(_NETMGR_DEVICE_IF, propname, value)
network_ifs = {}
def metis_ctrl_execute(cmdlist):
......@@ -93,38 +92,24 @@ def metis_ctrl_execute(cmdlist):
def metis_connect(ni):
print "Making Metis connection for device %s." % (ni.get_prop("Interface"))
hwaddr = ni.get_prop("HwAddress")
mac = canonical_mac_address(ni.get_prop("HwAddress"))
print "Interface HW Address: %s" % hwaddr
# Get BSSID of connected access point for wifi interfaces
if (ni.device_type == 2):
ap_path = ni.get_prop("ActiveAccessPoint")
ap = bus.get_object(_NETMGR_SERVICE, ap_path)
ap_props_if = dbus.Interface(ap, _DBUS_PROPERTIES)
bssid = ap_props_if.Get(_NETMGR_ACCESS_POINT_IF, "HwAddress")
print "Connected AP BSSID is %s" % bssid
global current_conn
if current_conn:
print "Removing routes"
for prefix in routes:
metis_ctrl_execute(metis_ctrl_base + metis_remove_route + [current_conn] + [prefix])
check_bssid = bssid.lower().replace(":","-")
if check_bssid in connections:
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]
print "Adding connections..."
metis_ctrl_execute(metis_ctrl_base + metis_add_connection + [current_conn] + [bssid] + ["wlan0"])
print "Adding new routes..."
for prefix in routes:
metis_ctrl_execute(metis_ctrl_base + metis_add_route + [current_conn] + [prefix] + ["1"])
else:
current_conn = None
def metis_disconnect(ni):
print "Metis disconnect for device %s." % (ni.get_prop("Interface"))
print "Removing routes"
for prefix in routes:
metis_ctrl_execute(metis_ctrl_base + metis_remove_route + [current_conn] + [prefix])
# Callback functions
def device_added_cb(device_path):
......@@ -154,11 +139,15 @@ def device_removed_cb(device_path):
# Look for change to the "activated" state
def device_state_change_cb(new_state, old_state, reason, path):
global network_ifs
ni = network_ifs[path]
print "%s: %s -> %s (Reason: %d)" % (ni.get_prop("Interface"), device_state[old_state], device_state[new_state], reason)
if new_state == 100:
if old_state != 100 and new_state == 100:
metis_connect(ni)
elif old_state == 100 and new_state != 100:
metis_disconnect(ni)
# Register for NetworkManager signals
nm_matches = []
......@@ -190,18 +179,24 @@ for d in devices:
ni = NetworkInterface(d)
# Only wired and WiFi devices for right now
device_type = ni.get_prop("DeviceType")
device_type = ni.get_prop('DeviceType')
if (not device_type == 1 and not device_type == 2):
continue
# Only interfaces specified in our config file
if_name = ni.get_prop('Interface')
dev_cfg = config[if_name]
if (dev_cfg == None):
continue;
# Add to our main list of interfaces
network_ifs[d] = ni;
print "<<%s>>" % ni.get_prop('Interface')
print " path: %s" % d
print " name: %s" % ni.get_prop('Interface')
print " name: %s" % if_name
print " type: %s" % device_types[device_type]
print " addr: %s" % ni.get_prop('HwAddress')
print " addr: %s" % mac
print " permaddr: %s" % ni.get_prop('PermHwAddress')
print " state: %s" % device_state[ni.get_prop('State')]
print ""
......@@ -213,6 +208,18 @@ for d in devices:
path=d, path_keyword="path")
dev_matches[d] = match
# 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']])
print "Adding connection..."
metis_ctrl_execute(metis_ctrl_base + metis_add_connection + [dev_cfg['symbolic']] +
[dev_cfg['nexthop']] + [if_name])
# Add route if currently connected
if device_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