Commit fa54bce7 authored by Binh Nguyen's avatar Binh Nguyen

Clean up comments in simeca_controller

parent d1fd84f0
# Copyright (C) 2011 Nippon Telegraph and Telephone Corporation. #Copyright Binh Nguyen University of Utah (binh@cs.utah.edu)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. #you may not use this file except in compliance with the License.
# You may obtain a copy of the License at #You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software #Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, #distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# implied. #See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and #limitations under the License.
# limitations under the License.
from ryu.base import app_manager from ryu.base import app_manager
from ryu.controller import ofp_event from ryu.controller import ofp_event
...@@ -61,7 +60,6 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -61,7 +60,6 @@ class SMORE_controller(app_manager.RyuApp):
XML = "/opt/simeca/xml" XML = "/opt/simeca/xml"
XML_TEMPLATE = "%s/input-template-penb.xml" % (XML) XML_TEMPLATE = "%s/input-template-penb.xml" % (XML)
OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION] OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
#OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
_LISTEN_INF = "eth2" #Todo: should be SGW's net_d interface _LISTEN_INF = "eth2" #Todo: should be SGW's net_d interface
ev = None ev = None
bridge = "tcp:127.0.0.1" bridge = "tcp:127.0.0.1"
...@@ -118,12 +116,8 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -118,12 +116,8 @@ class SMORE_controller(app_manager.RyuApp):
access_switch_name = access_switch_ulr.split('.')[0] access_switch_name = access_switch_ulr.split('.')[0]
access_num = access_switch_ulr.split('.')[0][6:] access_num = access_switch_ulr.split('.')[0][6:]
#print "accnum=%s"%access_num
#regex = r"net-d-enb" + access_num + r" -> (.*) -> (.*) -> (.*)"
logical_to_mac["net-d-enb"] = ":".join(re.findall(r'.{1,2}',re.search(r"net-d-enb" + access_num + r" -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(3))) logical_to_mac["net-d-enb"] = ":".join(re.findall(r'.{1,2}',re.search(r"net-d-enb" + access_num + r" -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(3)))
logical_to_mac["offload"] = ":".join(re.findall(r'.{1,2}',re.search(r'offload -> (.*) -> (.*) -> (.*)',physical_logical_inf_map).group(3))) logical_to_mac["offload"] = ":".join(re.findall(r'.{1,2}',re.search(r'offload -> (.*) -> (.*) -> (.*)',physical_logical_inf_map).group(3)))
#print "Logical interfaces to MAC mapping:"
#print "net-d -> %s\nnet-d-mme -> %s\noffload -> %s\n" % (self._logical_to_mac["net-d"], self._logical_to_mac["net-d-mme"], self._logical_to_mac["offload"])
''' '''
Retrieve port number for the logical interfaces using MAC address. Retrieve port number for the logical interfaces using MAC address.
...@@ -133,7 +127,6 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -133,7 +127,6 @@ class SMORE_controller(app_manager.RyuApp):
port_desc = subprocess.check_output(['ssh -o StrictHostKeyChecking=no %s "cd %s && sudo ./ovs_port_desc.sh"' % (access_switch_ulr, self._SCRIPTS)], shell=True) port_desc = subprocess.check_output(['ssh -o StrictHostKeyChecking=no %s "cd %s && sudo ./ovs_port_desc.sh"' % (access_switch_ulr, self._SCRIPTS)], shell=True)
info["net-d"] = int(re.search(r'(.*)\((.*)\): addr:%s'%logical_to_mac["net-d"],port_desc).group(1)) info["net-d"] = int(re.search(r'(.*)\((.*)\): addr:%s'%logical_to_mac["net-d"],port_desc).group(1))
self._LISTEN_INF = re.search(r'(.*)\((.*)\): addr:%s'%logical_to_mac["net-d"],port_desc).group(2) self._LISTEN_INF = re.search(r'(.*)\((.*)\): addr:%s'%logical_to_mac["net-d"],port_desc).group(2)
#self._info["net-d"] = re.search(r'(.*)\((.*): addr:%s'%self._logical_to_mac["net-d"],port_desc).group(1)
info["net-d-enb"] = int(re.search(r'(.*)\((.*): addr:%s'%logical_to_mac["net-d-enb"],port_desc).group(1)) info["net-d-enb"] = int(re.search(r'(.*)\((.*): addr:%s'%logical_to_mac["net-d-enb"],port_desc).group(1))
info["offload"] = int(re.search(r'(.*)\((.*): addr:%s'%logical_to_mac["offload"],port_desc).group(1)) info["offload"] = int(re.search(r'(.*)\((.*): addr:%s'%logical_to_mac["offload"],port_desc).group(1))
...@@ -149,17 +142,12 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -149,17 +142,12 @@ class SMORE_controller(app_manager.RyuApp):
info["net-d-enb-mac"] = logical_to_mac["net-d-enb"] info["net-d-enb-mac"] = logical_to_mac["net-d-enb"]
self.access_switches[access_switch_name] = info self.access_switches[access_switch_name] = info
#print "Access %s ..." % access_switch_name
#print self.access_switches[access_switch_name]
def _get_port_interface_map_tor_switch(self, tor_switch_ulr): def _get_port_interface_map_tor_switch(self, tor_switch_ulr):
logical_to_mac = {} logical_to_mac = {}
physical_logical_inf_map = subprocess.check_output(['ssh -o StrictHostKeyChecking=no %s "cd %s && ./get_interface_map.pl"'% (tor_switch_ulr, self._SCRIPTS)], shell=True) physical_logical_inf_map = subprocess.check_output(['ssh -o StrictHostKeyChecking=no %s "cd %s && ./get_interface_map.pl"'% (tor_switch_ulr, self._SCRIPTS)], shell=True)
logical_to_mac['offload'] = ":".join(re.findall(r'.{1,2}',re.search(r'offload -> (.*) -> (.*) -> (.*)',physical_logical_inf_map).group(3))) logical_to_mac['offload'] = ":".join(re.findall(r'.{1,2}',re.search(r'offload -> (.*) -> (.*) -> (.*)',physical_logical_inf_map).group(3)))
logical_to_mac['net-tor21'] = ":".join(re.findall(r'.{1,2}',re.search(r"net-tor21 -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(3))) logical_to_mac['net-tor21'] = ":".join(re.findall(r'.{1,2}',re.search(r"net-tor21 -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(3)))
#logical_to_mac['net-tor22'] = ":".join(re.findall(r'.{1,2}',re.search(r'net-tor22 -> (.*) -> (.*) -> (.*)',physical_logical_inf_map).group(3)))
#print "Logical interfaces to MAC mapping:"
#print "net-d -> %s\nnet-d-mme -> %s\noffload -> %s\n" % (self._logical_to_mac["net-d"], self._logical_to_mac["net-d-mme"], self._logical_to_mac["offload"])
''' '''
Retrieve port number for the logical interfaces using MAC address. Retrieve port number for the logical interfaces using MAC address.
...@@ -168,12 +156,9 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -168,12 +156,9 @@ class SMORE_controller(app_manager.RyuApp):
logical_to_portnumber = {} logical_to_portnumber = {}
port_desc = subprocess.check_output(['ssh -o StrictHostKeyChecking=no %s "cd %s && sudo ./ovs_port_desc.sh"' % (tor_switch_ulr, self._SCRIPTS)], shell=True) port_desc = subprocess.check_output(['ssh -o StrictHostKeyChecking=no %s "cd %s && sudo ./ovs_port_desc.sh"' % (tor_switch_ulr, self._SCRIPTS)], shell=True)
logical_to_portnumber["net-tor21"] = int(re.search(r'(.*)\((.*): addr:%s'%logical_to_mac["net-tor21"],port_desc).group(1)) logical_to_portnumber["net-tor21"] = int(re.search(r'(.*)\((.*): addr:%s'%logical_to_mac["net-tor21"],port_desc).group(1))
#logical_to_portnumber["net-tor22"] = int(re.search(r'(.*)\((.*): addr:%s'%logical_to_mac["net-tor22"],port_desc).group(1))
logical_to_portnumber["offload"] = int(re.search(r'(.*)\((.*): addr:%s'%logical_to_mac["offload"],port_desc).group(1)) logical_to_portnumber["offload"] = int(re.search(r'(.*)\((.*): addr:%s'%logical_to_mac["offload"],port_desc).group(1))
self.tor_switch = logical_to_portnumber self.tor_switch = logical_to_portnumber
#print "Tor ..."
#print self.tor_switch
def _get_port_interface_map_hsw_switch(self, hsw_switch_ulr): def _get_port_interface_map_hsw_switch(self, hsw_switch_ulr):
logical_to_mac = {} logical_to_mac = {}
...@@ -197,8 +182,6 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -197,8 +182,6 @@ class SMORE_controller(app_manager.RyuApp):
logical_to_portnumber["net-server"] = int(re.search(r'(.*)\((.*): addr:%s'%logical_to_mac["net-server"],port_desc).group(1)) logical_to_portnumber["net-server"] = int(re.search(r'(.*)\((.*): addr:%s'%logical_to_mac["net-server"],port_desc).group(1))
self.hsw_switches[hsw_switch_name] = logical_to_portnumber self.hsw_switches[hsw_switch_name] = logical_to_portnumber
#print "hsw switch %s ..." % (hsw_switch_name)
#print self.hsw_switches[hsw_switch_name]
def _get_server_info(self, server_ulr): def _get_server_info(self, server_ulr):
info = {} info = {}
...@@ -209,14 +192,10 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -209,14 +192,10 @@ class SMORE_controller(app_manager.RyuApp):
except: except:
server_num = "1" server_num = "1"
#print server_num
info['net-server-mac'] = ":".join(re.findall(r'.{1,2}',re.search(r"net-server" + server_num + r" -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(3))) info['net-server-mac'] = ":".join(re.findall(r'.{1,2}',re.search(r"net-server" + server_num + r" -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(3)))
print physical_logical_inf_map #print physical_logical_inf_map
#info['net-server-mac'] = ":".join(re.findall(r'.{1,2}',re.search(r"net-server -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(3)))
info['net-server-inf'] = re.search(r"net-server" + server_num + r" -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(1) info['net-server-inf'] = re.search(r"net-server" + server_num + r" -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(1)
#info['net-server-inf'] = re.search(r"net-server -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(1)
info['ip'] = re.search(r"net-server" + server_num + r" -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(2) info['ip'] = re.search(r"net-server" + server_num + r" -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(2)
#info['ip'] = re.search(r"net-server -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(2)
self.servers[server_name] = info self.servers[server_name] = info
def _get_interface_to_portnumber(self): def _get_interface_to_portnumber(self):
...@@ -228,8 +207,6 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -228,8 +207,6 @@ class SMORE_controller(app_manager.RyuApp):
for lan in ["net-tor2", "net-server"]: for lan in ["net-tor2", "net-server"]:
for hsw in self.hsw_switches: for hsw in self.hsw_switches:
self.interface_to_portnumber["%s-%s"%(hsw,lan)] = self.hsw_switches[hsw][lan] self.interface_to_portnumber["%s-%s"%(hsw,lan)] = self.hsw_switches[hsw][lan]
#print "Interface name to portnumber ..."
#print self.interface_to_portnumber
def _hex_to_int(self, str): def _hex_to_int(self, str):
try: try:
...@@ -258,12 +235,8 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -258,12 +235,8 @@ class SMORE_controller(app_manager.RyuApp):
name = child.find('name').text name = child.find('name').text
dpid = child.find('dpid').text dpid = child.find('dpid').text
name_to_olddpid[name] = dpid name_to_olddpid[name] = dpid
#print "Olddpid ..."
#print name_to_olddpid
for name in name_to_olddpid: for name in name_to_olddpid:
name_to_newdpid[name] = self.switchname_to_dpid[name] name_to_newdpid[name] = self.switchname_to_dpid[name]
#print "Newdpid ..."
#print name_to_newdpid
#replace dpid #replace dpid
for name in name_to_olddpid: for name in name_to_olddpid:
...@@ -283,11 +256,6 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -283,11 +256,6 @@ class SMORE_controller(app_manager.RyuApp):
self.G=nx.DiGraph() self.G=nx.DiGraph()
self.domain = subprocess.check_output(["hostname | sed s/`hostname -s`.//"], shell=True).rstrip() self.domain = subprocess.check_output(["hostname | sed s/`hostname -s`.//"], shell=True).rstrip()
#self.switches = kwargs['switches']
#print "DPSET= %s" % self.dpset
#print "Init..."
##self.dpset = Dpset()
#print self.dpset
#Get switch dpid #Get switch dpid
self._get_switchname_dpid() self._get_switchname_dpid()
...@@ -296,54 +264,33 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -296,54 +264,33 @@ class SMORE_controller(app_manager.RyuApp):
self._get_port_interface_map_access_switch("access1.%s"% self.domain) self._get_port_interface_map_access_switch("access1.%s"% self.domain)
self._get_port_interface_map_access_switch("access2.%s"%self.domain) self._get_port_interface_map_access_switch("access2.%s"%self.domain)
self._get_port_interface_map_access_switch("access3.%s"%self.domain) self._get_port_interface_map_access_switch("access3.%s"%self.domain)
#self._get_port_interface_map_access_switch("access4.%s"%self.domain)
#self._get_port_interface_map_hsw_switch("hsw1.%s"%self.domain)
#self._get_port_interface_map_hsw_switch("hsw2.%s"%self.domain)
self._get_port_interface_map_hsw_switch("hsw1.%s"%self.domain) self._get_port_interface_map_hsw_switch("hsw1.%s"%self.domain)
self._get_port_interface_map_tor_switch("tor.%s"%self.domain) self._get_port_interface_map_tor_switch("tor.%s"%self.domain)
#self._get_server_info("server1.%s"%self.domain)
#self._get_server_info("server2.%s"%self.domain)
self._get_server_info("server1.%s"%self.domain) self._get_server_info("server1.%s"%self.domain)
self._get_interface_to_portnumber() self._get_interface_to_portnumber()
#Construct an xml file describing the network. #Construct an xml file describing the network.
self._write_dpid_to_xml("input.xml") self._write_dpid_to_xml("input.xml")
#sys.exit(0)
self.enb1_port = int(self.access_switches['access1']['net-d-enb']) self.enb1_port = int(self.access_switches['access1']['net-d-enb'])
self.enb2_port =int(self.access_switches['access2']['net-d-enb']) self.enb2_port =int(self.access_switches['access2']['net-d-enb'])
self.sgw_port = int(self.access_switches['access1']['net-d']) self.sgw_port = int(self.access_switches['access1']['net-d'])
self.offload_port = int(self.access_switches['access1']['offload']) self.offload_port = int(self.access_switches['access1']['offload'])
self.gtp_port = int(self.access_switches['access1']['gtp']) self.gtp_port = int(self.access_switches['access1']['gtp'])
#print "%d %d %d %d %d" % (self.enb1_port, self.enb2_port, self.sgw_port, self.offload_port, self.gtp_port)
#self.enb1_port = int(self._logical_to_portnumber["net-d-enb1"])
#self.enb2_port = int(self._logical_to_portnumber["net-d-enb2"])
#self.sgw_port = int(self._logical_to_portnumber["net-d"])
#self.offload_port = int(self._logical_to_portnumber["offload"])
#self.gtp_port = int(self._logical_to_portnumber["gtp"])
self._LISTEN_INF = re.search(r'net-d -> (.*) -> (.*) ->',subprocess.check_output(['cd %s && ./get_interface_map.pl' % (self._SCRIPTS)], shell=True)).group(1) self._LISTEN_INF = re.search(r'net-d -> (.*) -> (.*) ->',subprocess.check_output(['cd %s && ./get_interface_map.pl' % (self._SCRIPTS)], shell=True)).group(1)
#print "SMORE monitor listening to interface %s of ovs node ..." % self._LISTEN_INF
@set_ev_cls(event.EventSwitchEnter) @set_ev_cls(event.EventSwitchEnter)
def get_topology_data(self, ev): def get_topology_data(self, ev):
LOG.debug("In get_topology...") LOG.debug("In get_topology...")
switch_list = get_switch(self.topology_api_app, None) switch_list = get_switch(self.topology_api_app, None)
#print "Switch list ... "
#print [switch.hardware for switch in switch_list]
switches=[switch.dp.id for switch in switch_list] switches=[switch.dp.id for switch in switch_list]
links_list = get_link(self.topology_api_app, None) links_list = get_link(self.topology_api_app, None)
#print links_list
links=[(link.src.dpid,link.dst.dpid,{'port':link.src.port_no}) for link in links_list] links=[(link.src.dpid,link.dst.dpid,{'port':link.src.port_no}) for link in links_list]
#print links
self.G.add_nodes_from(switches) self.G.add_nodes_from(switches)
self.G.add_edges_from(links) self.G.add_edges_from(links)
#print "Discovered graphs:"
#print self.G.nodes()
#print self.G.edges(data=True)
#print "Switch 17779081116 = %s" % self.dpset.get(17779081116)
def __del__(self): def __del__(self):
...@@ -354,47 +301,27 @@ class SMORE_controller(app_manager.RyuApp): ...@@ -354,47 +301,27 @@ class SMORE_controller(app_manager.RyuApp):
sniffer = Sniffer(dpset, access_switches, tor_switch, hsw_switches, listen_inf) sniffer = Sniffer(dpset, access_switches, tor_switch, hsw_switches, listen_inf)
sniffer.start_sniffing(listen_inf) sniffer.start_sniffing(listen_inf)
#print "start thread sniffer %s"%listen_inf
def _start_sniffer_now(self, dpset, switchname_to_dpid, enb1_port, enb2_port, sgw_port, offload_port, gtp_port, listen_inf, access_switches, servers, hsw_switches): def _start_sniffer_now(self, dpset, switchname_to_dpid, enb1_port, enb2_port, sgw_port, offload_port, gtp_port, listen_inf, access_switches, servers, hsw_switches):
print "start sniffer in SMORE_controller\n" print "start sniffer in SMORE_controller\n"
#sniffer = Sniffer(dpset, switchname_to_dpid, enb1_port, enb2_port, sgw_port, offload_port, gtp_port, listen_inf, access_switches, servers, hsw_switches)
#sniffer.start_sniffing(listen_inf)
@set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER) @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
def switch_features_handler(self, ev): def switch_features_handler(self, ev):
#self.dpset.add(Dp(ev.msg.datapath_id, ev.msg.datapath, ev.msg.datapath.ofproto, ev.msg.datapath.ofproto_parser))
#print "Collected switches len = %s" % self.dpset.dpset
LOG.info("Collecting switches list: %s" % self.dpset.get_all()) LOG.info("Collecting switches list: %s" % self.dpset.get_all())
LOG.info("Waiting for %d switches..." % (len(self.switch_names)-len(self.dpset.get_all()))) LOG.info("Waiting for %d switches..." % (len(self.switch_names)-len(self.dpset.get_all())))
#RestIoTApi(dpset=self.dpset, wsgi=self.wsgi, switchname_to_dpid=self.switchname_to_dpid, enb_inf=self.enb1_port, enb2_inf=self.enb2_port,sgw_inf=self.sgw_port, offload_inf=self.offload_port,gtp_inf=self.gtp_port, listen_inf=self._LISTEN_INF,access_switches=self.access_switches,servers=self.servers, hsw_switches=self.hsw_switches);
#print "DPSET = %s" % self.dpset.get_all_dpid()
#if (len(self.dpset.get_all_dpid()) == len(self.switch_names)):
#RestIoTApi(dpset=self.dpset, wsgi=self.wsgi, switchname_to_dpid=self.switchname_to_dpid, enb_inf=self.enb1_port, enb2_inf=self.enb2_port,sgw_inf=self.sgw_port, offload_inf=self.offload_port,gtp_inf=self.gtp_port, listen_inf=self._LISTEN_INF,access_switches=self.access_switches,servers=self.servers, hsw_switches=self.hsw_switches);
if (len(self.dpset.get_all()) == len(self.switch_names)-1): if (len(self.dpset.get_all()) == len(self.switch_names)-1):
try: try:
LOG.info("START RestIoTApi LISTENER ...") LOG.info("START RestIoTApi LISTENER ...")
#LOG.debug("Access switches: %s" % self.access_switches)
RestIoTApi(dpset=self.dpset, wsgi=self.wsgi, switchname_to_dpid=self.switchname_to_dpid, enb_inf=self.enb1_port, enb2_inf=self.enb2_port,sgw_inf=self.sgw_port, offload_inf=self.offload_port,gtp_inf=self.gtp_port, listen_inf=self._LISTEN_INF,access_switches=self.access_switches,servers=self.servers, hsw_switches=self.hsw_switches); RestIoTApi(dpset=self.dpset, wsgi=self.wsgi, switchname_to_dpid=self.switchname_to_dpid, enb_inf=self.enb1_port, enb2_inf=self.enb2_port,sgw_inf=self.sgw_port, offload_inf=self.offload_port,gtp_inf=self.gtp_port, listen_inf=self._LISTEN_INF,access_switches=self.access_switches,servers=self.servers, hsw_switches=self.hsw_switches);
#print "Starting Sniffer ... on interface %s" %self._LISTEN_INF
#thread.start_new_thread( self._start_sniffer_now, (self.dpset,self.switchname_to_dpid, self.enb1_port, self.enb2_port,self.sgw_port, self.offload_port,self.gtp_port, self._LISTEN_INF, self.access_switches, self.servers, self.hsw_switches,) )
#thread.start_new_thread( self._start_sniffer, (self.dpset, self.switchname_to_dpid, self.access_switches, self.tor_switch, self.hsw_switches, self._LISTEN_INF) )
except Exception, e: except Exception, e:
print e print e
print "Error: unable to start sniffer" print "Error: unable to start sniffer"
#sniffer = Sniffer(self.bridge, self.ovs_ip, self.enb_port, self.sgw_port, self.offload_port,ev)
#sniffer.start_sniffing(self._LISTEN_INF)
#@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
#def _packet_in_handler(self, ev):
#print "packet in"
#print ""
if __name__ == "__main__": if __name__ == "__main__":
......
Copyright (c) Binh Nguyen University of Utah (binh@cs.utah.edu)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#Copyright Binh Nguyen University of Utah (binh@cs.utah.edu)
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
#!/usr/bin/python #!/usr/bin/python
from ryu.controller.handler import CONFIG_DISPATCHER from ryu.controller.handler import CONFIG_DISPATCHER
...@@ -104,13 +118,6 @@ class AccessSwitch: ...@@ -104,13 +118,6 @@ class AccessSwitch:
ssh_p = subprocess.Popen(["ssh", self._ENB2_NODE, "ifconfig | grep -B1 192.168.6.90"], stdout=subprocess.PIPE) ssh_p = subprocess.Popen(["ssh", self._ENB2_NODE, "ifconfig | grep -B1 192.168.6.90"], stdout=subprocess.PIPE)
self._enb2_net_d_mac = re.search(r'HWaddr (.*)',ssh_p.communicate()[0]).group(1).split()[0] self._enb2_net_d_mac = re.search(r'HWaddr (.*)',ssh_p.communicate()[0]).group(1).split()[0]
#ssh_p = subprocess.Popen(["ssh", self._ALICE_NODE, "ifconfig | grep -B1 192.168.3.100 | head -1 | cut -d\" \" -f1"], stdout=subprocess.PIPE)
#self._ALICE_AN_LTE_INTERFACE = ssh_p.communicate()[0].rstrip()
#ssh_p = subprocess.Popen(["ssh", self._BOB_NODE, "ifconfig | grep -B1 192.168.3.101 | head -1 | cut -d\" \" -f1"], stdout=subprocess.PIPE)
#self._BOB_AN_LTE_INTERFACE = ssh_p.communicate()[0].rstrip()
#print "ALICE_AN_LTE_INTERFACE=%s, BOB_AN_LTE_INTERFACE=%s" % (self._ALICE_AN_LTE_INTERFACE, self._BOB_AN_LTE_INTERFACE)
#print "enb-net-d-mac = %s, sgw_net_d_mme_mac = %s, off1_offload_mac= = %s" % (self._enb_net_d_mac, self._sgw_net_d_mme_mac, self._off1_offload_mac)
''' '''
Set default route for offloading node (after _get_MACs()) Set default route for offloading node (after _get_MACs())
...@@ -121,29 +128,14 @@ class AccessSwitch: ...@@ -121,29 +128,14 @@ class AccessSwitch:
self._off1_offload_dev = ssh_p.communicate()[0] self._off1_offload_dev = ssh_p.communicate()[0]
ssh_p = subprocess.Popen(["ssh", self._OFFLOAD_NODE, "sudo ip route add 192.168.3.0/24 dev %s" % self._off1_offload_dev], stdout=subprocess.PIPE) ssh_p = subprocess.Popen(["ssh", self._OFFLOAD_NODE, "sudo ip route add 192.168.3.0/24 dev %s" % self._off1_offload_dev], stdout=subprocess.PIPE)
ssh_p.communicate() ssh_p.communicate()
#ssh_p = subprocess.Popen(["ssh", self._BOB_NODE, "sudo ifconfig %s mtu 1400 up" % self._BOB_AN_LTE_INTERFACE], stdout=subprocess.PIPE)
#ssh_p.communicate()
#ssh_p = subprocess.Popen(["ssh", self._ALICE_NODE, "sudo ifconfig %s mtu 1400 up" % self._ALICE_AN_LTE_INTERFACE], stdout=subprocess.PIPE)
#ssh_p.communicate()
#ssh_p = subprocess.Popen(["ssh", self._OFFLOAD_NODE, "ifconfig | grep -B1 192.168.10.11"], stdout=subprocess.PIPE)
#self._off1_offload_mac = re.search(r'HWaddr (.*)',ssh_p.communicate()[0]).group(1).split()[0]
#ssh_p = subprocess.Popen(["ssh", self._OFFLOAD_NODE, "sudo ip route add 192.168.3.0/24 dev %s" % self._off1_offload_mac], stdout=subprocess.PIPE)
def _build_database(self): def _build_database(self):
#if os.path.isfile(self._OFFLOAD_DB) and os.path.isfile(self._USER_DB):
#offload_db = open(self._OFFLOAD_DB)
if os.path.isfile(self._USER_DB): if os.path.isfile(self._USER_DB):
user_db = open(self._USER_DB) user_db = open(self._USER_DB)
#Get registered offload IPs
#line = offload_db.readline()
#while line:
# if line.split()[0] != "":
# self._offload_db.append(line.split()[0])
# line = offload_db.readline()
line = user_db.readline() line = user_db.readline()
while line: while line:
...@@ -861,15 +853,6 @@ class AccessSwitch: ...@@ -861,15 +853,6 @@ class AccessSwitch:
ovs-ofctl add-flow br0 in_port=$GTP,priority=2,actions=output:$sgw_inf ovs-ofctl add-flow br0 in_port=$GTP,priority=2,actions=output:$sgw_inf
''' '''
print "*****CONTROLLER: Pushing UPLINK flows for UE %s, offloading server %s, sgw-gtpid %s ....." % (ue_ip,offload_ip,sgw_teid) print "*****CONTROLLER: Pushing UPLINK flows for UE %s, offloading server %s, sgw-gtpid %s ....." % (ue_ip,offload_ip,sgw_teid)
#uplink_flow_to_gtp = 'in_port=%s,priority=3,eth_type=%s,nw_proto=17,tp_dst=%d,actions=output:%d' %\
#(self.enb_inf, self._IP_TYPE, self._GTP_PORT, self._GTP)
#uplink_flow_gtp = 'in_port=%d,priority=3,tun_id=%s,tun_src=%s,tun_dst=%s,actions=mod_dl_dst:%s,output:%d'%\
#(self._GTP, sgw_teid, ue_ip, offload_ip, self._off1_offload_mac, self._DECAP_PORT)
#uplink_flow_from_gtp = 'in_port=%d,priority=3,eth_type=%s,nw_src=%s,nw_dst=%s,actions=output:%s' %\
#(self._DECAP_PORT, self._IP_TYPE, ue_ip, offload_ip, self.offload_inf)
#uplink_normal_gtp = "in_port=%d,priority=2,actions=output:%s" % (self._GTP, self.sgw_inf)
#1 #1
#match = self.parser.OFPMatch(in_port=self.enb_inf,eth_type=self._IP_TYPE,nw_proto=17,tp_dst=self._GTP_PORT) #match = self.parser.OFPMatch(in_port=self.enb_inf,eth_type=self._IP_TYPE,nw_proto=17,tp_dst=self._GTP_PORT)
...@@ -920,17 +903,10 @@ class AccessSwitch: ...@@ -920,17 +903,10 @@ class AccessSwitch:
ovs-ofctl add-flow br0 in_port=$ENCAP,priority=2,eth_type=$IP_TYPE,actions=output:$enb_inf ovs-ofctl add-flow br0 in_port=$ENCAP,priority=2,eth_type=$IP_TYPE,actions=output:$enb_inf
''' '''
print "******Pushing DOWNLINK flows for eNB GTPID %s, eNB IP %s, sgw IP %s ....." % (enb_teid, enb_ip, sgw_ip) print "******Pushing DOWNLINK flows for eNB GTPID %s, eNB IP %s, sgw IP %s ....." % (enb_teid, enb_ip, sgw_ip)
#downlink_flow = 'in_port=%s,priority=2,eth_type=%s,actions=mod_dl_dst:%s,mod_dl_src=%s,set_field:%s->tun_id,set_field:%s->tun_dst,set_field:%s->tun_src,output:%d' %\
#(self.offload_inf, self._IP_TYPE, self._enb_net_d_mac, self._sgw_net_d_mme_mac, enb_teid, enb_ip, sgw_ip, self._ENCAP_PORT)
#downlink_flow_gtp = 'in_port=%d,priority=2,eth_type=%s,actions=output:%s' %\
#(self._ENCAP_PORT, self._IP_TYPE, self.enb_inf)
#1 #1
match = self.parser.OFPMatch(in_port=self.offload_inf,eth_type=self._IP_TYPE) match = self.parser.OFPMatch(in_port=self.offload_inf,eth_type=self._IP_TYPE)
actions = [] actions = []
#actions.append(self.parser.OFPActionSetField(dl_dst=self._enb_net_d_mac,dl_src=self._sgw_net_d_mme_mac,tunnel_id=enb_teid,tun_dst=enb_ip,tun_src=sgw_ip)
#actions.append(self.parser.OFPActionSetField(tunnel_id=enb_teid,tun_dst=enb_ip,tun_src=sgw_ip))
actions.append(self.parser.OFPActionSetField(eth_dst=self._enb_net_d_mac)) actions.append(self.parser.OFPActionSetField(eth_dst=self._enb_net_d_mac))
actions.append(self.parser.OFPActionSetField(eth_src=self._sgw_net_d_mme_mac)) actions.append(self.parser.OFPActionSetField(eth_src=self._sgw_net_d_mme_mac))
actions.append(self.parser.OFPActionSetField(tunnel_id=enb_teid)) actions.append(self.parser.OFPActionSetField(tunnel_id=enb_teid))
......
#Copyright Binh Nguyen University of Utah (binh@cs.utah.edu)
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
#!/usr/bin/python #!/usr/bin/python
from ryu.controller.handler import CONFIG_DISPATCHER from ryu.controller.handler import CONFIG_DISPATCHER
...@@ -63,10 +77,6 @@ class AccessSwitchGtp: ...@@ -63,10 +77,6 @@ class AccessSwitchGtp:
#Get MAC #Get MAC
self._get_MACs() self._get_MACs()
#Delete old flows on ALL access_switches
#self._del_flows_ryu()
#Push bridgin flows on ALL access_switches
#self._push_flows_bridging_ryu()
''' '''
Get MAC addresses of SGW, ENBs associated with AccessSwitches. Get MAC addresses of SGW, ENBs associated with AccessSwitches.
...@@ -100,18 +110,14 @@ class AccessSwitchGtp: ...@@ -100,18 +110,14 @@ class AccessSwitchGtp:
inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
actions)] actions)]
#print "Match %s" % matches
#print "Actions %s" % actions
if isinstance(matches, list): if isinstance(matches, list):
for match in matches: for match in matches:
mod = parser.OFPFlowMod(datapath=datapath, priority=priority, mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
match=match, instructions=inst) match=match, instructions=inst)
datapath.send_msg(mod) datapath.send_msg(mod)
#print "sent match=%s, instruction=%s, to datapath=%s"%(matches, inst, datapath)
else: else:
mod = parser.OFPFlowMod(datapath=datapath, priority=priority, mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
match=matches, instructions=inst) match=matches, instructions=inst)
#print "sent match=%s, instruction=%s, to datapath=%s"%(matches, inst, datapath)
datapath.send_msg(mod) datapath.send_msg(mod)
def _get_dp_from_switch_name(self, switch_name): def _get_dp_from_switch_name(self, switch_name):
...@@ -151,15 +157,6 @@ class AccessSwitchGtp: ...@@ -151,15 +157,6 @@ class AccessSwitchGtp:
'''
def _set_default_gateway_in_offload_node(self):
#print "MANUALLY ADD ARP"
ssh_p = subprocess.Popen(["ssh", self._OFFLOAD_NODE, "ifconfig | grep -B1 192.168.8.10"], stdout=subprocess.PIPE)
self._off1_offload_interface = re.search(r'(.*) Link encap:',ssh_p.communicate()[0]).group(1).split()[0]
#print "off1_offload_interface = %s" % self._off1_offload_interface
p = subprocess.Popen(["ssh", self._OFFLOAD_NODE,"sudo ip route add 192.168.3.0/24 dev %s" % (self._off1_offload_interface)], stdout=subprocess.PIPE)
p.communicate()
'''
#flows for src enb (input_port) to dst enb (output_port) #flows for src enb (input_port) to dst enb (output_port)
#def _push_flows_P2P_ryu(self, input_port, output_port, sgw_teid, enb_teid, sgw_ip, enb_ip, sgw_mac, enb_mac, src_ip, dst_ip): #def _push_flows_P2P_ryu(self, input_port, output_port, sgw_teid, enb_teid, sgw_ip, enb_ip, sgw_mac, enb_mac, src_ip, dst_ip):
...@@ -186,62 +183,6 @@ class AccessSwitchGtp: ...@@ -186,62 +183,6 @@ class AccessSwitchGtp:
'''
#Bridging, lower priority
1. sudo ovs-ofctl add-flow br0 in_port=$as1['net-d-enb'],priority=2,actions=output:$netd_port
3. sudo ovs-ofctl add-flow br0 in_port=$as2['net-d-enb'],priority=2,actions=output:$netd_port
2. sudo ovs-ofctl add-flow br0 in_port=$netd_port,priority=2,actions=output:$as1['net-d-enb'],output:$as2['net-d-enb']
'''
#print "******P2P: Pushing bridging flows, low priority*****"
#1,2
#as1
#match = []
#actions = []
#match.append(ofp.OFPMatch(in_port=as1['net-d-enb']))
#actions.append(ofp.OFPActionOutput(as1['net-d']))
#self._add_flow(dp1,2,match,actions)
#as2
#match = []
#actions = []
#match.append(ofp.OFPMatch(in_port=as2['net-d-enb']))
#actions.append(ofp.OFPActionOutput(as2['net-d']))
#self._add_flow(dp2,2,match,actions)
#3
#as1
#match = ofp.OFPMatch(in_port=as1['net-d'])
#actions = []
#actions.append(ofp.OFPActionOutput(as1['net-d-enb']))
#self._add_flow(dp1,2,match,actions)
#as2
#match = ofp.OFPMatch(in_port=as2['net-d'])
#actions = []
#actions.append(ofp.OFPActionOutput(as2['net-d-enb']))
#self._add_flow(dp2,2,match,actions)
'''
#Normal traffic, low priority
4. sudo ovs-ofctl add-flow br0 in_port=$gtp_port,priority=2,actions=output:$netd_port
'''
#print "******P2P: Pushing flow for normal traffic, low priority*****"
#4
#as1
#match = ofp.OFPMatch(in_port=as1['gtp_port'])
#actions = []
#actions.append(ofp.OFPActionOutput(as1['net-d']))
#self._add_flow(dp1,2,match,actions)
#as2
#match = ofp.OFPMatch(in_port=as2['gtp_port'])
#actions = []
#actions.append(ofp.OFPActionOutput(as2['net-d']))
#self._add_flow(dp2,2,match,actions)
''' '''
#alice->bob SGW->ENB2 #alice->bob SGW->ENB2
5. sudo ovs-ofctl add-flow br0 in_port=$as1['net-d-enb'],priority=3,eth_type=$IP_TYPE,nw_proto=17,tp_dst=$GTP_PORT,actions=output:$gtp_port 5. sudo ovs-ofctl add-flow br0 in_port=$as1['net-d-enb'],priority=3,eth_type=$IP_TYPE,nw_proto=17,tp_dst=$GTP_PORT,actions=output:$gtp_port
...@@ -334,72 +275,6 @@ class AccessSwitchGtp: ...@@ -334,72 +275,6 @@ class AccessSwitchGtp:
#
#Shortespath routing takes care of the rest here: output to shortestpath port
#Need to do locationrouting.installLocationRoute()
'''
#7: encap at as2 (already there?)
match = ofp.OFPMatch(in_port=as1['gtp_decap_port'], eth_type=ether.ETH_TYPE_IP, ipv4_src=src_ip, ipv4_dst=dst_ip)
actions = []
actions.append(ofp.OFPActionSetField(eth_dst=as2['enb-mac']))
actions.append(ofp.OFPActionSetField(eth_src=as2['sgw-mac']))
actions.append(ofp.OFPActionSetField(tunnel_id=enb2_teid))
actions.append(ofp.OFPActionSetField(tun_dst=enb2_location_ip))
actions.append(ofp.OFPActionSetField(tun_src=sgw_ip))
actions.append(ofp.OFPActionOutput(switch['gtp_encap_port']))
self._add_flow(dp,3,match,actions)
#8: output at as2 (already there?)
match = ofp.OFPMatch(in_port=switch['gtp_encap_port'], eth_type=ether.ETH_TYPE_IP, ipv4_src=sgw_ip, ipv4_dst=enb2_ip)
#match = ofp.OFPMatch(in_port=switch['gtp_encap_port'], eth_type=ether.ETH_TYPE_IP)
actions = []
#actions.append(ofp.OFPActionSetField(udp_src=self._GTP_APP_PORT))
#actions.append(ofp.OFPActionSetField(udp_dst=self._GTP_APP_PORT))
actions.append(ofp.OFPActionOutput(as2['net-d-enb']))
self._add_flow(dp,3,match,actions)
'''
'''
#alice->bob reply SGW->ENB1
9. sudo ovs-ofctl add-flow br0 in_port=$as2['net-d-enb'],priority=3,eth_type=$IP_TYPE,nw_proto=17,tp_dst=$GTP_PORT,actions=output:$gtp_port
10. sudo ovs-ofctl add-flow br0 in_port=$gtp_port,priority=3,tun_id=$SGW2_TEID,tun_src=$BOB_IP,tun_dst=$ALICE_IP,actions=output:$gtp_decap_port
11. sudo ovs-ofctl add-flow br0 in_port=$gtp_decap_port,priority=3,eth_type=$IP_TYPE,nw_src=$BOB_IP,nw_dst=$ALICE_IP,actions=mod_dl_dst:$ENB1_MAC,mod_dl_src=$SGW_MAC,"set_field:$ENB1_TEID->tun_id","set_field:$ENB1_IP->tun_dst","set_field:$SGW_IP->tun_src",output:$gtp_encap_port
12. sudo ovs-ofctl add-flow br0 in_port=$gtp_encap_port,priority=3,eth_type=$IP_TYPE,nw_src=$SGW_IP,nw_dst=$ENB1_IP,actions=mod_tp_dst:$GTP_PORT,mod_tp_src:$GTP_PORT,output:$as1['net-d-enb']
'''
#print "******P2P: Pushing flows from Alice to Bob, SGW->eNB1 direction*****"
#9
#match = ofp.OFPMatch(in_port=as2['net-d-enb'], eth_type=ether.ETH_TYPE_IP, ip_proto=17, udp_dst=self._GTP_APP_PORT)
#actions = []
#actions.append(ofp.OFPActionOutput(self._GTP))
#self._add_flow(dp,3,match,actions)
#10
#match = ofp.OFPMatch(in_port=self._GTP, tunnel_id=sgw2_teid, tun_src=dst_ip, tun_dst=src_ip)
#actions = []
#actions.append(ofp.OFPActionOutput(switch['gtp_decap_port']))
#self._add_flow(dp,3,match,actions)
#11
#match = ofp.OFPMatch(in_port=switch['gtp_decap_port'], eth_type=ether.ETH_TYPE_IP, ipv4_src=dst_ip, ipv4_dst=src_ip)
#actions = []
#actions.append(ofp.OFPActionSetField(eth_dst=as1['enb-mac']))
#actions.append(ofp.OFPActionSetField(eth_src=sgw_mac))
#actions.append(ofp.OFPActionSetField(tunnel_id=enb1_teid))
#actions.append(ofp.OFPActionSetField(tun_dst=enb1_ip))
#actions.append(ofp.OFPActionSetField(tun_src=sgw_ip))
#actions.append(ofp.OFPActionOutput(switch['gtp_encap_port']))
#self._add_flow(dp,3,match,actions)
#12
#print "xx2"
#match = ofp.OFPMatch(in_port=switch['gtp_encap_port'], eth_type=ether.ETH_TYPE_IP, ipv4_src=sgw_ip, ipv4_dst=enb1_ip)
#actions = []
#actions.append(ofp.OFPActionSetField(udp_src=self._GTP_APP_PORT))
#actions.append(ofp.OFPActionSetField(udp_dst=self._GTP_APP_PORT))