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");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#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.
#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.
from ryu.base import app_manager
from ryu.controller import ofp_event
......@@ -61,7 +60,6 @@ class SMORE_controller(app_manager.RyuApp):
XML = "/opt/simeca/xml"
XML_TEMPLATE = "%s/input-template-penb.xml" % (XML)
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
ev = None
bridge = "tcp:127.0.0.1"
......@@ -118,12 +116,8 @@ class SMORE_controller(app_manager.RyuApp):
access_switch_name = access_switch_ulr.split('.')[0]
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["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.
......@@ -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)
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._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["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):
info["net-d-enb-mac"] = logical_to_mac["net-d-enb"]
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):
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)
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-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.
......@@ -168,12 +156,9 @@ class SMORE_controller(app_manager.RyuApp):
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)
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))
self.tor_switch = logical_to_portnumber
#print "Tor ..."
#print self.tor_switch
def _get_port_interface_map_hsw_switch(self, hsw_switch_ulr):
logical_to_mac = {}
......@@ -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))
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):
info = {}
......@@ -209,14 +192,10 @@ class SMORE_controller(app_manager.RyuApp):
except:
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)))
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)))
#print physical_logical_inf_map
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 -> (.*) -> (.*) -> (.*)",physical_logical_inf_map).group(2)
self.servers[server_name] = info
def _get_interface_to_portnumber(self):
......@@ -228,8 +207,6 @@ class SMORE_controller(app_manager.RyuApp):
for lan in ["net-tor2", "net-server"]:
for hsw in self.hsw_switches:
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):
try:
......@@ -258,12 +235,8 @@ class SMORE_controller(app_manager.RyuApp):
name = child.find('name').text
dpid = child.find('dpid').text
name_to_olddpid[name] = dpid
#print "Olddpid ..."
#print name_to_olddpid
for name in name_to_olddpid:
name_to_newdpid[name] = self.switchname_to_dpid[name]
#print "Newdpid ..."
#print name_to_newdpid
#replace dpid
for name in name_to_olddpid:
......@@ -283,11 +256,6 @@ class SMORE_controller(app_manager.RyuApp):
self.G=nx.DiGraph()
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
self._get_switchname_dpid()
......@@ -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("access2.%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_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_interface_to_portnumber()
#Construct an xml file describing the network.
self._write_dpid_to_xml("input.xml")
#sys.exit(0)
self.enb1_port = int(self.access_switches['access1']['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.offload_port = int(self.access_switches['access1']['offload'])
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)
#print "SMORE monitor listening to interface %s of ovs node ..." % self._LISTEN_INF
@set_ev_cls(event.EventSwitchEnter)
def get_topology_data(self, ev):
LOG.debug("In get_topology...")
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]
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]
#print links
self.G.add_nodes_from(switches)
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):
......@@ -354,47 +301,27 @@ class SMORE_controller(app_manager.RyuApp):
sniffer = Sniffer(dpset, access_switches, tor_switch, hsw_switches, 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):
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)
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("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):
try:
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);
#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:
print e
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__":
......
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
from ryu.controller.handler import CONFIG_DISPATCHER
......@@ -104,13 +118,6 @@ class AccessSwitch:
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]
#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())
......@@ -121,29 +128,14 @@ class AccessSwitch:
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.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):
#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):
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()
while line:
......@@ -861,15 +853,6 @@ class AccessSwitch:
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)
#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
#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:
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)
#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
match = self.parser.OFPMatch(in_port=self.offload_inf,eth_type=self._IP_TYPE)
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_src=self._sgw_net_d_mme_mac))
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
from ryu.controller.handler import CONFIG_DISPATCHER
......@@ -63,10 +77,6 @@ class AccessSwitchGtp:
#Get MAC
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.
......@@ -100,18 +110,14 @@ class AccessSwitchGtp:
inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
actions)]
#print "Match %s" % matches
#print "Actions %s" % actions
if isinstance(matches, list):
for match in matches:
mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
match=match, instructions=inst)
datapath.send_msg(mod)
#print "sent match=%s, instruction=%s, to datapath=%s"%(matches, inst, datapath)
else:
mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
match=matches, instructions=inst)
#print "sent match=%s, instruction=%s, to datapath=%s"%(matches, inst, datapath)
datapath.send_msg(mod)
def _get_dp_from_switch_name(self, switch_name):
......@@ -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)
#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:
'''
#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
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:
#
#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))
#actions.append(ofp.OFPActionOutput(as1['net-d-enb']))
#self._add_flow(dp,3,match,actions)
#flows for uplink (ovs->offloading server), assuming OFFLOAD SERVER's MAC is known
def push_flows_uplink_ryu(self, switch_name, sgw_teid, ue_ip, server_ip, server_mac):
'''
......@@ -441,21 +316,15 @@ class AccessSwitchGtp:
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, on switch %s ....." % (enb_teid, enb_ip, sgw_ip, switch_name)
#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' %\
#(switch['offload'], ether.ETH_TYPE_IP, switch['enb_mac'], switch['sgw_mac'], enb_teid, enb_ip, sgw_ip, switch['gtp_encap_port'])
switch = self.access_switches[switch_name]
dp, of, ofp = self._get_dp_from_switch_name(switch_name)
#downlink_flow_gtp = 'in_port=%d,priority=2,eth_type=%s,actions=output:%s' %\
#(switch['gtp_encap_port'], ether.ETH_TYPE_IP, switch['net-d-enb'])
#1
#match = ofp.OFPMatch(in_port=switch['offload'],eth_type=ether.ETH_TYPE_IP, ipv4_dst=enb_location_ip)
#either in_port=switch['offload'] or in_port=switch['net-d']
match = ofp.OFPMatch(in_port=switch['offload'],eth_type=ether.ETH_TYPE_IP, ipv4_dst=enb_location_ip)
actions = []
#actions.append(ofp.OFPActionSetField(dl_dst=switch['enb_mac'],dl_src=switch['sgw_mac'],tunnel_id=enb_teid,tun_dst=enb_ip,tun_src=sgw_ip)
#actions.append(ofp.OFPActionSetField(tunnel_id=enb_teid,tun_dst=enb_ip,tun_src=sgw_ip))
actions.append(ofp.OFPActionSetField(eth_dst=switch['enb_mac']))
actions.append(ofp.OFPActionSetField(eth_src=switch['sgw_mac']))
actions.append(ofp.OFPActionSetField(ipv4_dst=ue_ip))
......@@ -463,20 +332,10 @@ class AccessSwitchGtp:
actions.append(ofp.OFPActionSetField(tun_dst=enb_ip))
actions.append(ofp.OFPActionSetField(tun_src=sgw_ip))
actions.append(ofp.OFPActionOutput(switch['gtp_encap_port']))
#self._add_flow(dp,2,match,actions)
self._add_flow(dp,3,match,actions)
#2
#print "YYYYYYYYYYYYYYYYYYYYYYY"
#match = ofp.OFPMatch(in_port=switch['gtp_encap_port'],eth_type=ether.ETH_TYPE_IP)
#actions = []
##actions.append(ofp.OFPActionSetField(udp_src=2152))
##actions.append(ofp.OFPActionSetField(udp_dst=2152))
#actions.append(ofp.OFPActionOutput(switch['net-d-enb']))
#self._add_flow(dp,3,match,actions)
#3 normal traffic
#2 normal traffic
match = ofp.OFPMatch(in_port=switch['gtp_encap_port'],eth_type=ether.ETH_TYPE_IP)
actions = []
actions.append(ofp.OFPActionOutput(switch['net-d-enb']))
......
#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.
#
#An entry after matching init and response msgs.
#This entry contains information to:
......
#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.
#
#Detach request message
#
......
#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
import logging
......@@ -318,9 +332,6 @@ class Dispatcher(ControllerBase):
print "******Pushed APRS flows on server switch %s ....." % (hsw_name)
#def __init__ (self, dpset, switchname_to_dpid, access_switches, tor_switch, hsw_switches, ev):
#def __init__ (self, dpset, switchname_to_dpid, enb_inf, enb2_inf, sgw_inf, offload_inf, gtp_inf, listen_inf, access_switches, servers, hsw_switches):
#def __init__ (self, dpset, switchname_to_dpid, enb_inf, enb2_inf, sgw_inf, offload_inf, gtp_inf, listen_inf, access_switches, servers, hsw_switches):
#TODO: move the init functions to ofctl_rest_api
......@@ -331,96 +342,7 @@ class Dispatcher(ControllerBase):
self.waiters = data['waiters']
self.dpset = data['dpset']
self.record_list = []
#self.tshark_xml = open ("tshark.xml","w")
#Install tshark if needed.
#self._install_pkg ("tshark")
'''
#only access 1
print "xxx %d"%switchname_to_dpid['access1']
self.datapath = dpset.get(int(self.switchname_to_dpid['access1']))
if self.datapath is not None:
self.ofproto = self.datapath.ofproto
self.parser = self.datapath.ofproto_parser
else:
time.sleep(2)
self.datapath = dpset.get(int(self.switchname_to_dpid['access1']))
self.ofproto = self.datapath.ofproto
self.parser = self.datapath.ofproto_parser
'''
"""
self._get_enb_location_ip_map('ENB.data')
#print self.enb_location_ip_map
self._get_ue_ip_server_name_map('SERVER.data')
self.locationrouting = LocationRouting(self.dpset, self.access_switches, self.switchname_to_dpid)
self.access_switch_gtp = AccessSwitchGtp(self.dpset, self.switchname_to_dpid, self.access_switches)
self.attached_ue_ip = open('../iot-controller-eval/e2e_delay_exp/ATTACHED_IP.data','w',0)
self.p2p_existed_ip = open('../iot-controller-eval/e2e_delay_exp/P2P_IP.data','w',0)
#test
#for i in range(1,300):
# self._allocate_ipv4('0011040')
#self._get_MACs()
self._set_default_route_servers()
self._build_database()
self._del_flows_ryu()
self._push_arp_server()
self.access_switch_gtp.push_flows_bridging_ryu()
"""
#for enb_cellid in self.enb_location_ip_map:
# self._set_default_route_enb_prefix('192.190.0.0/16', enb_cellid)
'''
TEST
'''
#self.parse_xml_file('attach-s1ho-charlie.xml')
#print "Done!"
#time.sleep(10000)
#sys.exit(1)
'''
ue_ip='192.235.235.68'
ue_imsi="001011234567892"
enb1_cellid="00011040"
enb2_cellid="00011050"
enb1_teid=int('0x00000013',16)
sgw1_teid=16
sgw2_teid=16
enb2_teid=int('0x00001C8C',16)
enb1_ip='192.168.4.90'
enb2_ip='192.168.4.91'
sgw_ip='192.168.4.20'
self._installHoFlows(ue_ip, ue_imsi, enb1_cellid , enb2_cellid, enb1_teid, sgw1_teid, enb2_teid, sgw2_teid, sgw_ip, enb1_ip, enb2_ip)
'''
'''
#test
ue1_ip="192.53.53.157"
ue2_ip="192.249.249.60"