def parse_granted_flowspaces(gfs): gfs_list=[] for fs in gfs: fs_dict = dict( flowspace=dict(), openflow=dict() ) fs_dict['openflow']=[] fs_dict['flowspace']=dict( mac_src_s=int_to_mac(fs.mac_src_s), mac_src_e=int_to_mac(fs.mac_src_e), mac_dst_s=int_to_mac(fs.mac_dst_s), mac_dst_e=int_to_mac(fs.mac_dst_e), eth_type_s=fs.eth_type_s, eth_type_e=fs.eth_type_e, vlan_id_s=fs.vlan_id_s, vlan_id_e=fs.vlan_id_e, ip_src_s=int_to_dotted_ip(fs.ip_src_s), ip_dst_s=int_to_dotted_ip(fs.ip_dst_s), ip_src_e=int_to_dotted_ip(fs.ip_src_e), ip_dst_e=int_to_dotted_ip(fs.ip_dst_e), ip_proto_s=fs.ip_proto_s, ip_proto_e=fs.ip_proto_e, tp_src_s=fs.tp_src_s, tp_dst_s=fs.tp_dst_s, tp_src_e=fs.tp_src_e, tp_dst_e=fs.tp_dst_e, ) openflow_dict=dict( dpid=fs.dpid, direction=fs.direction, port_number_s=fs.port_number_s, port_number_e=fs.port_number_e, ) existing_fs = False for prev_dict_list in gfs_list: prev_dict = prev_dict_list[0] if fs_dict['flowspace'] == prev_dict['flowspace']: if openflow_dict not in prev_dict['openflow']: prev_dict['openflow'].append(openflow_dict) existing_fs = True break if not existing_fs: fs_dict['openflow'].append(openflow_dict) fs_list = [fs_dict] gfs_list.append(fs_list) return gfs_list
def parse_granted_flowspaces(gfs): gfs_list = [] for fs in gfs: fs_dict = dict(flowspace=dict(), openflow=dict()) fs_dict['openflow'] = [] fs_dict['flowspace'] = dict( mac_src_s=int_to_mac(fs.mac_src_s), mac_src_e=int_to_mac(fs.mac_src_e), mac_dst_s=int_to_mac(fs.mac_dst_s), mac_dst_e=int_to_mac(fs.mac_dst_e), eth_type_s=fs.eth_type_s, eth_type_e=fs.eth_type_e, vlan_id_s=fs.vlan_id_s, vlan_id_e=fs.vlan_id_e, ip_src_s=int_to_dotted_ip(fs.ip_src_s), ip_dst_s=int_to_dotted_ip(fs.ip_dst_s), ip_src_e=int_to_dotted_ip(fs.ip_src_e), ip_dst_e=int_to_dotted_ip(fs.ip_dst_e), ip_proto_s=fs.ip_proto_s, ip_proto_e=fs.ip_proto_e, tp_src_s=fs.tp_src_s, tp_dst_s=fs.tp_dst_s, tp_src_e=fs.tp_src_e, tp_dst_e=fs.tp_dst_e, ) openflow_dict = dict( dpid=fs.dpid, direction=fs.direction, port_number_s=fs.port_number_s, port_number_e=fs.port_number_e, ) existing_fs = False for prev_dict_list in gfs_list: prev_dict = prev_dict_list[0] if fs_dict['flowspace'] == prev_dict['flowspace']: if openflow_dict not in prev_dict['openflow']: prev_dict['openflow'].append(openflow_dict) existing_fs = True break if not existing_fs: fs_dict['openflow'].append(openflow_dict) fs_list = [fs_dict] gfs_list.append(fs_list) return gfs_list
def __unicode__(self): expression = "" if (self.mac_src_s == self.mac_src_e): expression = expression + ("MAC Source Addr: %s, " % (int_to_mac(self.mac_src_s))) elif (self.mac_src_s > 0 or self.mac_src_e < 0xFFFFFFFFFFFF): expression = expression + ("MAC Source Addr: %s-%s, " % (int_to_mac(self.mac_src_s), int_to_mac(self.mac_src_e))) if (self.mac_dst_s == self.mac_dst_e): expression = expression + ("MAC Destination Addr: %s, " % (int_to_mac(self.mac_dst_s))) elif (self.mac_dst_s > 0 or self.mac_dst_e < 0xFFFFFFFFFFFF): expression = expression + ("MAC Destination Addr: %s-%s, " % (int_to_mac(self.mac_dst_s), int_to_mac(self.mac_dst_e))) if (self.eth_type_s == self.eth_type_e): expression = expression + ("Eth Type: 0x%x, " % (self.eth_type_s)) elif (self.eth_type_s > 0 or self.eth_type_e < 0xFFFF): expression = expression + ("Eth Type: 0x%x-0x%x, " % (self.eth_type_s,self.eth_type_e)) if (self.vlan_id_s == self.vlan_id_e): expression = expression + ("VALN id: %d, " % (self.vlan_id_s)) elif (self.vlan_id_s > 0 or self.vlan_id_e < 0xFFF): expression = expression + ("VALN id: %d-%d, " % (self.vlan_id_s,self.vlan_id_e)) if (self.ip_src_s == self.ip_src_e): expression = expression + ("IP Source Addr: %s, " % (int_to_dotted_ip(self.ip_src_s))) elif (self.ip_src_s > 0 or self.ip_src_e < 0xFFFFFFFF): expression = expression + ("IP Source Addr: %s-%s, " % (int_to_dotted_ip(self.ip_src_s), int_to_dotted_ip(self.ip_src_e))) if (self.ip_dst_s == self.ip_dst_e): expression = expression + ("IP Destination Addr: %s, " % (int_to_dotted_ip(self.ip_dst_s))) elif (self.ip_dst_s > 0 or self.ip_dst_e < 0xFFFFFFFF): expression = expression + ("IP Destination Addr: %s-%s, " % (int_to_dotted_ip(self.ip_dst_s), int_to_dotted_ip(self.ip_dst_e))) if (self.ip_proto_s == self.ip_proto_e): expression = expression + ("IP Protocol Number: %s, " % (self.ip_proto_s)) elif (self.ip_proto_s > 0 or self.ip_proto_e < 0xFF): expression = expression + ("IP Protocol Number: %s-%s, " % (self.ip_proto_s, self.ip_proto_e)) if (self.tp_src_s == self.tp_src_e): expression = expression + ("Transport Source Port: %s, " % (self.tp_src_s)) elif (self.tp_src_s > 0 or self.tp_src_e < 0xFFFF): expression = expression + ("Transport Source Port: %s-%s, " % (self.tp_src_s, self.tp_src_e)) if (self.tp_dst_s == self.tp_dst_e): expression = expression + ("Transport Destination Port: %s, " % (self.tp_dst_s)) if (self.tp_dst_s > 0 or self.tp_dst_e < 0xFFFF): expression = expression + ("Transport Destination Port: %s-%s, " % (self.tp_dst_s, self.tp_dst_e)) if expression == "": expression = "All" return expression
def __unicode__(self): expression = "" if self.mac_src_s == self.mac_src_e: expression = expression + ("MAC Source Addr: %s, " % (int_to_mac(self.mac_src_s))) elif self.mac_src_s > 0 or self.mac_src_e < 0xFFFFFFFFFFFF: expression = expression + ( "MAC Source Addr: %s-%s, " % (int_to_mac(self.mac_src_s), int_to_mac(self.mac_src_e)) ) if self.mac_dst_s == self.mac_dst_e: expression = expression + ("MAC Destination Addr: %s, " % (int_to_mac(self.mac_dst_s))) elif self.mac_dst_s > 0 or self.mac_dst_e < 0xFFFFFFFFFFFF: expression = expression + ( "MAC Destination Addr: %s-%s, " % (int_to_mac(self.mac_dst_s), int_to_mac(self.mac_dst_e)) ) if self.eth_type_s == self.eth_type_e: expression = expression + ("Eth Type: 0x%x, " % (self.eth_type_s)) elif self.eth_type_s > 0 or self.eth_type_e < 0xFFFF: expression = expression + ("Eth Type: 0x%x-0x%x, " % (self.eth_type_s, self.eth_type_e)) if self.vlan_id_s == self.vlan_id_e: expression = expression + ("VALN id: %d, " % (self.vlan_id_s)) elif self.vlan_id_s > 0 or self.vlan_id_e < 0xFFF: expression = expression + ("VALN id: %d-%d, " % (self.vlan_id_s, self.vlan_id_e)) if self.ip_src_s == self.ip_src_e: expression = expression + ("IP Source Addr: %s, " % (int_to_dotted_ip(self.ip_src_s))) elif self.ip_src_s > 0 or self.ip_src_e < 0xFFFFFFFF: expression = expression + ( "IP Source Addr: %s-%s, " % (int_to_dotted_ip(self.ip_src_s), int_to_dotted_ip(self.ip_src_e)) ) if self.ip_dst_s == self.ip_dst_e: expression = expression + ("IP Destination Addr: %s, " % (int_to_dotted_ip(self.ip_dst_s))) elif self.ip_dst_s > 0 or self.ip_dst_e < 0xFFFFFFFF: expression = expression + ( "IP Destination Addr: %s-%s, " % (int_to_dotted_ip(self.ip_dst_s), int_to_dotted_ip(self.ip_dst_e)) ) if self.ip_proto_s == self.ip_proto_e: expression = expression + ("IP Protocol Number: %s, " % (self.ip_proto_s)) elif self.ip_proto_s > 0 or self.ip_proto_e < 0xFF: expression = expression + ("IP Protocol Number: %s-%s, " % (self.ip_proto_s, self.ip_proto_e)) if self.tp_src_s == self.tp_src_e: expression = expression + ("Transport Source Port: %s, " % (self.tp_src_s)) elif self.tp_src_s > 0 or self.tp_src_e < 0xFFFF: expression = expression + ("Transport Source Port: %s-%s, " % (self.tp_src_s, self.tp_src_e)) if self.tp_dst_s == self.tp_dst_e: expression = expression + ("Transport Destination Port: %s, " % (self.tp_dst_s)) if self.tp_dst_s > 0 or self.tp_dst_e < 0xFFFF: expression = expression + ("Transport Destination Port: %s-%s, " % (self.tp_dst_s, self.tp_dst_e)) if expression == "": expression = "All" return expression
def create_ofv3_rspec(slice_id, project_name, project_description, slice_name, slice_description, controller_url, owner_email, owner_password, switch_slivers, experimentflowspaces): #set namespaces xmlns = "http://www.geni.net/resources/rspec/3" xs = "http://www.w3.org/2001/XMLSchema-instance" openflow = "http://www.geni.net/resources/rspec/ext/openflow/3" schemaLocation = "http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd http://www.geni.net/resources/rspec/ext/openflow/3 http://www.geni.net/resources/rspec/ext/openflow/3/of-resv.xsd" #initialize the rspec xml with the proper namespaces and set its type to 'request' rspec = etree.Element("rspec", attrib={"{"+xs+"}schemaLocation" : schemaLocation, 'type': 'request'}, nsmap={None:xmlns, 'xs':xs, 'openflow':openflow}) #add openflow sliver to rspec ofsliver = etree.SubElement(rspec, "{"+openflow+"}sliver") ofsliver.set("description", project_description) ofsliver.set("email", owner_email) ofsliver.set("ref", "sample experiment reference") #add controllers to rspec ofcontrollers = [] for i in range(3): ofcontrollers.append(etree.SubElement(ofsliver, "{"+openflow+"}conroller")) #primary controller ofcontrollers[0].set("url", controller_url) ofcontrollers[0].set("type", "primary") #monitor controller ofcontrollers[1].set("url", "tcp:monitor.example.foam.ocf.fp7-ofelia.eu:6634") ofcontrollers[1].set("type", "monitor") #backup controller ofcontrollers[2].set("url", "tcp:backup.example.foam.ocf.fp7-ofelia.eu:6633") ofcontrollers[2].set("type", "backup") #add sliver group to rspec ofgroup = etree.SubElement(ofsliver, "{"+openflow+"}group") ofgroup.set("name", slice_name) #determine the datapaths and ports of the sliver group ofdpids = [] ofdpports = dict() for experimentflowspace in experimentflowspaces: #check if we have already registered the datapath if (experimentflowspace.dpid in ofdpids) is False: ofdpids.append(experimentflowspace.dpid) ofdpports[experimentflowspace.dpid] = [] #now we can associate the ports with the datapath for port_number in range(experimentflowspace.port_number_s, experimentflowspace.port_number_e): ofdpports[experimentflowspace.dpid].append(port_number) ofdpports[experimentflowspace.dpid].append(experimentflowspace.port_number_e) #because range ignores end number #add datapaths and ports to rspec ofgroupdatapaths = [] ofgroupdpports = [] i=0 j=0 for dpid in dpids: ofgroupdatapaths.append(etree.SubElement(ofgroup, "{"+openflow+"}datapath")) #ofgroupatapaths[i].set("component_id", "urn:publicid:IDN+openflow:foam:foam.example.net+datapath+"+str(dpid)) #ofgroupdatapaths[i].set("component_manager_id", "urn:publicid:IDN+openflow:foam:foam.example.net+authority+am") ofgroupatapaths[i].set("component_id", "urn:publicid:IDN+openflow:fp7-ofelia.eu:ocf:foam+datapath+"+str(dpid)) ofgroupdatapaths[i].set("component_manager_id", "urn:publicid:IDN+openflow:fp7-ofelia.eu:ocf:foam+authority+am") for dpp in ofdpports[dpid]: ofgroupdpports.append(etree.SubElement(ofgroupdatapaths[i], "{"+openflow+"}port")) ofgroupdpports[j].set("num", dpp) #we will see about the name attribute j = j + 1 i=i+1 #translate experiment flowspaces to "match" structures ofmatch = [] ofmatchdatapaths = [] ofmatchdpports = [] ofmatchdppackets = [] ofmatchdppktfsfields = [] i = 0 j = 0 k = 0 for experimentflowspace in experimentflowspaces: ofmatch.append(etree.SubElement(ofsliver, "{"+openflow+"}match")) #match datapath + ports ofmatchdatapaths.append(etree.SubElement(ofmatch[i], "{"+openflow+"}datapath")) #ofmatchdatapaths[i].set("component_id", "urn:publicid:IDN+openflow:foam:foam.example.net+datapath+"+str(experimentflowspace.dpid)) #ofmatchdatapaths[i].set("component_manager_id", "urn:publicid:IDN+openflow:foam:foam.example.net+authority+am") ofmatchdatapaths[i].set("component_id", "urn:publicid:IDN+openflow:fp7-ofelia.eu:ocf:foam+datapath+"+str(experimentflowspace.dpid)) ofmatchdatapaths[i].set("component_manager_id", "urn:publicid:IDN+openflow:fp7-ofelia.eu:ocf:foam+authority+am") ofmatchdatapaths[i].set("dpid", str(experimentflowspace.dpid)) for port_number in range(experimentflowspace.port_number_s, experimentflowspace.port_number_e): ofmatchdpports.append(etree.SubElement(ofmatchdatapaths[i], "{"+openflow+"}port")) ofmatchdpports[j].set("num", port_number) j=j+1 ofmatchdpports.append(etree.SubElement(ofmatchdatapaths[i], "{"+openflow+"}port")) ofmatchdpports[j].set("num", experimentflowspace.port_number_e) j=j+1 #match packet (flowspace) ofmatchdppackets.append(etree.SubElement(ofmatch[i], "{"+openflow+"}packet")) for ch_name, (to_str, from_str, width, om_name, of_name) in om_ch_translate.attr_funcs.items(): if (of_name != "in_port"): #ignore port number it is already taken into account before om_start = "%s_s"%(om_name) om_end = "%s_e"%(om_name) fieldName = of_name fieldValue = "" field_start_value_int = experimentflowspace.om_start field_end_value_int = experimentflowspace.om_end ofmatchdppktfsfields.append(etree.SubElement(ofmatchdppackets[i], "{"+openflow+"}"+fieldName)) if (fieldName is "dl_src"): if len(range(field_start_value_int,field_end_value_int)) is 0: #single value fieldValue = int_to_mac(field_start_value_int) else: for dl_src in range(field_start_value_int,field_end_value_int): #range (discrete values) fieldValue = fieldValue + int_to_mac(dl_src) +", " fieldValue = fieldValue + int_to_mac(field_end_value_int) elif (fieldName is "dl_dst"): if len(range(field_start_value_int,field_end_value_int)) is 0: #single value fieldValue = int_to_mac(field_start_value_int) else: for dl_dst in range(field_start_value_int,field_end_value_int): #range (discrete values) fieldValue = fieldValue + int_to_mac(dl_dst) +", " fieldValue = fieldValue + int_to_mac(field_end_value_int) elif (fieldName is "dl_type"): if len(range(field_start_value_int,field_end_value_int)) is 0: #single value fieldValue = int_to_mac(field_start_value_int) else: for dl_type in range(field_start_value_int,field_end_value_int): #range (discrete values) fieldValue = fieldValue + str(hex(dl_dst)) +", " fieldValue = fieldValue + hex(field_end_value_int) elif (fieldName is "dl_vlan"): if len(range(field_start_value_int,field_end_value_int)) is 0: #single value fieldValue = str(field_start_value_int) else: #range (continuous) fieldValue = str(field_start_value_int) + "-" + str(field_end_value_int) elif (fieldName is "nw_proto"): if len(range(field_start_value_int,field_end_value_int)) is 0: #single value fieldValue = str(field_start_value_int) else: #range (continuous) fieldValue = str(field_start_value_int) + "-" + str(field_end_value_int) elif (fieldName is "nw_src"): #translate from "-" range to "/" : network address plus netmask [netIP, netBitNum] = extract_IP_mask_from_IP_range(int_to_dotted_ip(field_start_value_int), int_to_dotted_ip(field_end_value_int)) fieldValue = netIP + "/" + str(netBitNum) elif (fieldName is "nw_dst"): #translate from "-" range to "/" : network address plus netmask [netIP, netBitNum] = extract_IP_mask_from_IP_range(int_to_dotted_ip(field_start_value_int), int_to_dotted_ip(field_end_value_int)) fieldValue = netIP + "/" + str(netBitNum) elif (fieldName is "tp_src"): if len(range(field_start_value_int,field_end_value_int)) is 0: #single value fieldValue = str(field_start_value_int) else: #range (continuous) fieldValue = str(field_start_value_int) + "-" + str(field_end_value_int) elif (fieldName is "tp_dst"): if len(range(field_start_value_int,field_end_value_int)) is 0: #single value fieldValue = str(field_start_value_int) else: #range (continuous) fieldValue = str(field_start_value_int) + "-" + str(field_end_value_int) #assign the proper values to fields ofmatchdppktfsfields[k].set(fieldName, fieldValue) k = k + 1 i = i+1 #print final rspec for debugging purposes print(etree.tostring(rspec,encoding='UTF-8',xml_declaration=True)) #return the rspec as a string return etree.tostring(rspec,encoding='UTF-8',xml_declaration=True)
def create_ofv3_rspec(slice_id, project_name, project_description, slice_name, slice_description, controller_url, owner_email, owner_password, switch_slivers, experimentflowspaces): #set namespaces xmlns = "http://www.geni.net/resources/rspec/3" #xmlns = "opt/foam/schemas" xs = "http://www.w3.org/2001/XMLSchema-instance" #openflow = "http://www.geni.net/resources/rspec/ext/openflow/3" openflow = "/opt/ofelia/ofam/local/schemas" #schemaLocation = "http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd http://www.geni.net/resources/rspec/ext/openflow/3 http://www.geni.net/resources/rspec/ext/openflow/3/of-resv.xsd" schemaLocation = "http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd /opt/ofelia/ofam/local/schemas /opt/ofelia/ofam/local/schemas/of-resv-3.xsd" #initialize the rspec xml with the proper namespaces and set its type to 'request' rspec = etree.Element("rspec", attrib={ "{" + xs + "}schemaLocation": schemaLocation, 'type': 'request' }, nsmap={ None: xmlns, 'xs': xs, 'openflow': openflow }) #add openflow sliver to rspec ofsliver = etree.SubElement(rspec, "{" + openflow + "}sliver") ofsliver.set( "description", "project:" + project_description + "|slice:" + slice_description) ofsliver.set("email", owner_email) ofsliver.set("ref", "sample experiment reference") #add controllers to rspec ofcontrollers = [] for i in range(3): ofcontrollers.append( etree.SubElement(ofsliver, "{" + openflow + "}controller")) #primary controller ofcontrollers[0].set("url", controller_url) ofcontrollers[0].set("type", "primary") #monitor controller ofcontrollers[1].set("url", "tcp:monitor.example.foam.ocf.fp7-ofelia.eu:6634") ofcontrollers[1].set("type", "monitor") #backup controller ofcontrollers[2].set("url", "tcp:backup.example.foam.ocf.fp7-ofelia.eu:6633") ofcontrollers[2].set("type", "backup") #add sliver group to rspec ofgroup = etree.SubElement(ofsliver, "{" + openflow + "}group") ofgroup.set("name", slice_name) #determine the datapaths and ports of the sliver group ofdpids = [] ofdpports = dict() for experimentflowspace in experimentflowspaces: if (experimentflowspace.dpid is None): raise Exception("No dpid is specified for this flowspace!") #check if we have already registered the datapath if (experimentflowspace.dpid in ofdpids) is False: ofdpids.append(experimentflowspace.dpid) ofdpports[experimentflowspace.dpid] = [] #now we can associate the ports with the datapath if (experimentflowspace.port_number_s is None): raise Exception( "No port on a dpid is specified for this flowspace!") if (experimentflowspace.port_number_e is not None): for port_number in xrange(experimentflowspace.port_number_s, experimentflowspace.port_number_e): ofdpports[experimentflowspace.dpid].append(port_number) ofdpports[experimentflowspace.dpid].append( experimentflowspace.port_number_e ) #because range ignores end number else: ofdpports[experimentflowspace.dpid].append( experimentflowspace.port_number_s) #add datapaths and ports to rspec ofgroupdatapaths = [] ofgroupdpports = [] i = 0 j = 0 for dpid in ofdpids: ofgroupdatapaths.append( etree.SubElement(ofgroup, "{" + openflow + "}datapath")) #ofgroupatapaths[i].set("component_id", "urn:publicid:IDN+openflow:foam:foam.example.net+datapath+"+str(dpid)) #ofgroupdatapaths[i].set("component_manager_id", "urn:publicid:IDN+openflow:foam:foam.example.net+authority+am") ofgroupdatapaths[i].set("component_id", "urn:publicid:IDN+openflow:foam:" + str(THIS_SITE_TAG) + "+datapath+" + str(dpid)) #careful with site-tag ofgroupdatapaths[i].set( "component_manager_id", "urn:publicid:IDN+openflow:foam:" + str(THIS_SITE_TAG) + "+authority+am") #careful with site-tag for dpp in ofdpports[dpid]: ofgroupdpports.append( etree.SubElement(ofgroupdatapaths[i], "{" + openflow + "}port")) ofgroupdpports[j].set( "num", str(dpp)) #we will see about the name attribute j = j + 1 i = i + 1 #translate experiment flowspaces to "match" structures ofmatch = [] ofmatchdatapaths = [] ofmatchdpports = [] ofmatchdppackets = [] ofmatchdppktfsfields = [] i = 0 j = 0 k = 0 for experimentflowspace in experimentflowspaces: ofmatch.append(etree.SubElement(ofsliver, "{" + openflow + "}match")) #match datapath + ports ofmatchdatapaths.append( etree.SubElement(ofmatch[i], "{" + openflow + "}datapath")) #ofmatchdatapaths[i].set("component_id", "urn:publicid:IDN+openflow:foam:foam.example.net+datapath+"+str(experimentflowspace.dpid)) #ofmatchdatapaths[i].set("component_manager_id", "urn:publicid:IDN+openflow:foam:foam.example.net+authority+am") ofmatchdatapaths[i].set( "component_id", "urn:publicid:IDN+openflow:foam:" + str(THIS_SITE_TAG) + "+datapath+" + str(experimentflowspace.dpid)) ofmatchdatapaths[i].set( "component_manager_id", "urn:publicid:IDN+openflow:foam:" + str(THIS_SITE_TAG) + "+authority+am") ofmatchdatapaths[i].set("dpid", str(experimentflowspace.dpid)) if (experimentflowspace.port_number_e is not None): for port_number in xrange(experimentflowspace.port_number_s, experimentflowspace.port_number_e): ofmatchdpports.append( etree.SubElement(ofmatchdatapaths[i], "{" + openflow + "}port")) ofmatchdpports[j].set("num", str(port_number)) j = j + 1 ofmatchdpports.append( etree.SubElement(ofmatchdatapaths[i], "{" + openflow + "}port")) ofmatchdpports[j].set("num", str(experimentflowspace.port_number_e)) j = j + 1 else: ofmatchdpports.append( etree.SubElement(ofmatchdatapaths[i], "{" + openflow + "}port")) ofmatchdpports[j].set("num", str(experimentflowspace.port_number_s)) #match packet (flowspace) ofmatchdppackets.append( etree.SubElement(ofmatch[i], "{" + openflow + "}packet")) for ch_name, (to_str, from_str, width, om_name, of_name) in om_ch_translate.attr_funcs.items(): if (of_name != "in_port" ): #ignore port number it is already taken into account before om_start = "%s_s" % (om_name) om_end = "%s_e" % (om_name) fieldName = of_name fieldValue = "" field_start_value_int = getattr(experimentflowspace, om_start) field_end_value_int = getattr(experimentflowspace, om_end) #full_wildcard_flag = True if (field_start_value_int == 0) and (field_end_value_int == (2**width - 1)): continue if (fieldName is "dl_src"): if len(xrange(field_start_value_int, field_end_value_int)) is 0: #single value fieldValue = int_to_mac(field_start_value_int) else: for dl_src in xrange( field_start_value_int, field_end_value_int): #range (discrete values) fieldValue = fieldValue + int_to_mac(dl_src) + ", " fieldValue = fieldValue + int_to_mac( field_end_value_int) elif (fieldName is "dl_dst"): if len(xrange(field_start_value_int, field_end_value_int)) is 0: #single value fieldValue = int_to_mac(field_start_value_int) else: for dl_dst in xrange( field_start_value_int, field_end_value_int): #range (discrete values) fieldValue = fieldValue + int_to_mac(dl_dst) + ", " fieldValue = fieldValue + int_to_mac( field_end_value_int) elif (fieldName is "dl_type"): if len(xrange(field_start_value_int, field_end_value_int)) is 0: #single value fieldValue = int_to_mac(field_start_value_int) else: for dl_type in xrange( field_start_value_int, field_end_value_int): #range (discrete values) fieldValue = fieldValue + str(hex(dl_type)) + ", " fieldValue = fieldValue + hex(field_end_value_int) elif (fieldName is "dl_vlan"): if len(xrange(field_start_value_int, field_end_value_int)) is 0: #single value fieldValue = str(field_start_value_int) else: #range (continuous) fieldValue = str(field_start_value_int) + "-" + str( field_end_value_int) elif (fieldName is "nw_proto"): if len(xrange(field_start_value_int, field_end_value_int)) is 0: #single value fieldValue = str(field_start_value_int) else: #range (continuous) fieldValue = str(field_start_value_int) + "-" + str( field_end_value_int) elif ( fieldName is "nw_src" ): #translate from "-" range to "/" : network address plus netmask [netIP, netBitNum] = extract_IP_mask_from_IP_range( int_to_dotted_ip(field_start_value_int), int_to_dotted_ip(field_end_value_int)) fieldValue = netIP + "/" + str(netBitNum) elif ( fieldName is "nw_dst" ): #translate from "-" range to "/" : network address plus netmask [netIP, netBitNum] = extract_IP_mask_from_IP_range( int_to_dotted_ip(field_start_value_int), int_to_dotted_ip(field_end_value_int)) fieldValue = netIP + "/" + str(netBitNum) elif (fieldName is "tp_src"): if len(xrange(field_start_value_int, field_end_value_int)) is 0: #single value fieldValue = str(field_start_value_int) else: #range (continuous) fieldValue = str(field_start_value_int) + "-" + str( field_end_value_int) elif (fieldName is "tp_dst"): if len(xrange(field_start_value_int, field_end_value_int)) is 0: #single value fieldValue = str(field_start_value_int) else: #range (continuous) fieldValue = str(field_start_value_int) + "-" + str( field_end_value_int) #assign the proper values to fields ofmatchdppktfsfields.append( etree.SubElement(ofmatchdppackets[i], "{" + openflow + "}" + fieldName)) ofmatchdppktfsfields[k].set("value", fieldValue) k = k + 1 i = i + 1 #store final rspec for debugging purposes string_rspec = etree.tostring(rspec, encoding='UTF-8', xml_declaration=True, pretty_print=True) # file_dir_path = "~/debug_rspecs_created/" # if not os.path.exists(file_dir_path): # os.makedirs(file_dir_path) # filename = str(slice_id) + '.rspec' # f = open(os.path.join(file_dir_path, filename), 'w') # f.write(string_rspec) # f.close() #return rspec as a string return string_rspec