def __route_serialize(self, route): return { 'src_host': { 'tenant_id': mul.nbapi_uuid_to_str(route.src_host.tenant_id), 'network_id': mul.nbapi_uuid_to_str(route.src_host.network_id), 'dl_src': mul.nbapi_parse_mac_to_str(route.src_host.host_flow.dl_src), 'nw_src': mul.nbapi_fab_parse_nw_addr_to_str(route.src_host.host_flow), 'switch_dpid': '0x%lx' % route.src_host.switch_id.datapath_id, 'port': '%hu' % route.src_host.host_flow.in_port }, 'dst_host': { 'tenant_id': mul.nbapi_uuid_to_str(route.dst_host.tenant_id), 'network_id': mul.nbapi_uuid_to_str(route.dst_host.network_id), 'dl_src': mul.nbapi_parse_mac_to_str(route.dst_host.host_flow.dl_src), 'nw_src': mul.nbapi_fab_parse_nw_addr_to_str(route.dst_host.host_flow), 'switch_dpid': '0x%lx' % route.dst_host.switch_id.datapath_id, 'port': '%hu' % route.dst_host.host_flow.in_port }, 'route_link': eval(route.str_route) }
def __delete_host(self, tenant_id, network_id, host_ip): ret = {} try: hosts = mul.get_fabric_host_all(1) check = 0 for host in hosts: host_flow = host.host_flow if str(tenant_id) == str(mul.nbapi_uuid_to_str( host.tenant_id)) and str(network_id) == str( mul.nbapi_uuid_to_str(host.network_id) ) and str(host_ip) == str( mul.nbapi_fab_parse_nw_addr_to_str(host_flow)): host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) check = mul.delete_fabric_host(str(tenant_id), str(network_id), str(host_ip), str(host_mac)) if check == 1: ret.update({'delete host': 'success'}) break elif check == -1: raise Exception, 'Malformed tenant_id' elif check == -2: raise Exception, 'Malformed network_id' elif check == -3: raise Exception, 'Malformed host_ip(nw_src)' elif check == -4: raise Exception, 'Malformed host_mac(dl_src)' elif check == -5: raise Exception, 'failed to delete host' if check == 0: raise Exception, 'no such host' except Exception, e: ret.update({'fail': 'failed to delete host', 'reason': str(e)})
def __delete_host(self, tenant_id, network_id, host_ip): ret = {} try: hosts = mul.get_fabric_host_all(1) check = 0 for host in hosts: host_flow = host.host_flow if ( str(tenant_id) == str(mul.nbapi_uuid_to_str(host.tenant_id)) and str(network_id) == str(mul.nbapi_uuid_to_str(host.network_id)) and str(host_ip) == str(mul.nbapi_fab_parse_nw_addr_to_str(host_flow)) ): host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) check = mul.delete_fabric_host(str(tenant_id), str(network_id), str(host_ip), str(host_mac)) if check == 1: ret.update({"delete host": "success"}) break elif check == -1: raise Exception, "Malformed tenant_id" elif check == -2: raise Exception, "Malformed network_id" elif check == -3: raise Exception, "Malformed host_ip(nw_src)" elif check == -4: raise Exception, "Malformed host_mac(dl_src)" elif check == -5: raise Exception, "failed to delete host" if check == 0: raise Exception, "no such host" except Exception, e: ret.update({"fail": "failed to delete host", "reason": str(e)})
def __delete_host(self, tenant_id, network_id, host_ip): try: hosts = mul.get_fabric_host_all(1, 0) ret = {} check = 0 for host in hosts: host_flow = host.host_flow if str(tenant_id) == str(mul.nbapi_uuid_to_str(host.tenant_id)) and str(network_id) == str(mul.nbapi_uuid_to_str(host.network_id)) and str(host_ip) == str(mul.nbapi_fab_parse_nw_addr_to_str(host_flow)): host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) check = mul.delete_fabric_host(str(tenant_id), str(network_id), str(host_ip), str(host_mac)) if check == 1: ret.update({'delete host' : 'success'}) break elif check == -1: raise Exception , 'Malformed tenant_id' elif check == -2: raise Exception , 'Malformed network_id' elif check == -3: raise Exception , 'Malformed host_ip(nw_src)' elif check == -4: raise Exception , 'Malformed host_mac(dl_src)' elif check == -5: raise Exception , 'failed to delete host' if check == 0: raise Exception , 'no such host' except Exception, e: ret.update({'fail' : 'failed to delete host', 'reason' : str(e)})
def __make_flow_id(self, dpid, flow, mask, priority): #dpid, resp): dl_src = dl_dst = nw_src = nw_dst = "" dl_src = mul.nbapi_parse_mac_to_str(flow.dl_src) dl_dst = mul.nbapi_parse_mac_to_str(flow.dl_dst) dl_src_mask = mul.nbapi_parse_mac_to_str(mask.dl_src) dl_dst_mask = mul.nbapi_parse_mac_to_str(mask.dl_dst) if mask.dl_type and (flow.dl_type == 0x86dd): nw_src = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 0) if nw_src == "-1": nw_src = "----:----:----:----:----:----:----:---/80" nw_src = str(nw_src).replace(":", "").replace("/", "") nw_dst = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 1) if nw_dst == "-1": nw_dst = "----:----:----:----:----:----:----:----/80" nw_dst = str(nw_dst).replace(":", "").replace("/", "") else: str_sip = mul.nbapi_parse_nw_addr_to_str(flow, mask, 0) str_dip = mul.nbapi_parse_nw_addr_to_str(flow, mask, 1) for sip in str(str_sip).replace("/", ".").split("."): nw_src += "%02x" % int(sip) for dip in str(str_dip).replace("/", ".").split("."): nw_dst += "%02x" % int(dip) if str_sip == "-1": nw_src = "--------20" if str_dip == "-1": nw_dst = "--------20" flow_id = "%016x" % dpid + "%02x" % flow.table_id + "%04x" % priority flow_id += dl_src.replace( ':', '') if dl_src_mask != '00:00:00:00:00:00' else '------------' flow_id += dl_dst.replace( ':', '') if dl_dst_mask != '00:00:00:00:00:00' else '------------' flow_id += "%04x" % flow.dl_type if mask.dl_type else '----' flow_id += "%03x" % flow.dl_vlan if mask.dl_vlan else '---' flow_id += "%01d" % flow.dl_vlan_pcp if mask.dl_vlan_pcp else '-' flow_id += "%05x" % flow.mpls_label if mask.mpls_label else '-----' flow_id += "%01d" % flow.mpls_tc if mask.mpls_tc else '-' flow_id += "%01d" % flow.mpls_bos if mask.mpls_bos else '-' flow_id += "%04x" % flow.in_port if mask.in_port else '----' flow_id += "%02x" % flow.nw_proto if mask.nw_proto else '--' flow_id += "%02x" % flow.nw_tos if mask.nw_tos else '--' flow_id += "%04x" % flow.tp_dst if mask.tp_dst else '----' flow_id += "%04x" % flow.tp_src if mask.tp_src else '----' flow_id += nw_src + nw_dst return flow_id
def __make_flow_id(self, dpid, flow, mask, priority):#dpid, resp): dl_src = dl_dst = nw_src = nw_dst = "" dl_src = mul.nbapi_parse_mac_to_str(flow.dl_src) dl_dst = mul.nbapi_parse_mac_to_str(flow.dl_dst) dl_src_mask = mul.nbapi_parse_mac_to_str(mask.dl_src) dl_dst_mask = mul.nbapi_parse_mac_to_str(mask.dl_dst) if mask.dl_type and (flow.dl_type == 0x86dd): nw_src = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 0) if nw_src == "-1": nw_src = "----:----:----:----:----:----:----:---/80" nw_src = str(nw_src).replace(":","").replace("/","") nw_dst = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 1) if nw_dst == "-1": nw_dst = "----:----:----:----:----:----:----:----/80" nw_dst = str(nw_dst).replace(":","").replace("/","") else: str_sip = mul.nbapi_parse_nw_addr_to_str(flow, mask, 0) str_dip = mul.nbapi_parse_nw_addr_to_str(flow, mask, 1) for sip in str(str_sip).replace("/",".").split("."): nw_src += "%02x" % int(sip) for dip in str(str_dip).replace("/",".").split("."): nw_dst += "%02x" % int(dip) if str_sip == "-1": nw_src = "--------20" if str_dip == "-1": nw_dst = "--------20" flow_id = "%016x" %dpid + "%02x" %flow.table_id + "%04x" %priority flow_id += dl_src.replace(':','') if dl_src_mask != '00:00:00:00:00:00' else '------------' flow_id += dl_dst.replace(':','') if dl_dst_mask != '00:00:00:00:00:00' else '------------' flow_id += "%04x" %flow.dl_type if mask.dl_type else '----' flow_id += "%03x" %flow.dl_vlan if mask.dl_vlan else '---' flow_id += "%01d" %flow.dl_vlan_pcp if mask.dl_vlan_pcp else '-' flow_id += "%05x" %flow.mpls_label if mask.mpls_label else '-----' flow_id += "%01d" %flow.mpls_tc if mask.mpls_tc else '-' flow_id += "%01d" %flow.mpls_bos if mask.mpls_bos else '-' flow_id += "%04x" %flow.in_port if mask.in_port else '----' flow_id += "%02x" %flow.nw_proto if mask.nw_proto else '--' flow_id += "%02x" %flow.nw_tos if mask.nw_tos else '--' flow_id += "%04x" %flow.tp_dst if mask.tp_dst else '----' flow_id += "%04x" %flow.tp_src if mask.tp_src else '----' flow_id += nw_src + nw_dst return flow_id
def __ofp_phy_port_serialization(self, resp): return { 'port_no': resp.port_no, 'hw_addr': mul.nbapi_parse_mac_to_str(resp.hw_addr), 'name': unicode(str(resp.name), errors='ignore'), 'config': 'PORT_DOWN' if resp.config & 0x1 else 'PORT_UP' , 'state': 'LINK_DOWN' if resp.state & 0x1 else 'LINK_UP' , 'curr': resp.curr, 'advertised': resp.advertised, 'supported': resp.supported, 'peer': resp.peer }
def __ofp_phy_port_serialization(self, resp): return { 'port_no': resp.port_no, 'hw_addr': mul.nbapi_parse_mac_to_str(resp.hw_addr), 'name': unicode(str(resp.name), errors='ignore'), 'config': 'PORT_DOWN' if resp.config & 0x1 else 'PORT_UP', 'state': 'LINK_DOWN' if resp.state & 0x1 else 'LINK_UP', 'curr': resp.curr, 'advertised': resp.advertised, 'supported': resp.supported, 'peer': resp.peer }
def __flow_struct_serialization(self, flow, mask): dl_src = mul.nbapi_parse_mac_to_str(flow.dl_src) dl_dst = mul.nbapi_parse_mac_to_str(flow.dl_dst) dl_src_mask = mul.nbapi_parse_mac_to_str(mask.dl_src) dl_dst_mask = mul.nbapi_parse_mac_to_str(mask.dl_dst) ret = { 'table_id' : flow.table_id } if dl_src_mask != "00:00:00:00:00:00" : ret.update({'dl_src' : dl_src}) if dl_dst_mask != "00:00:00:00:00:00" : ret.update({'dl_dst' : dl_dst}) if mask.dl_type : ret.update({'dl_type' : '0x%lx' % flow.dl_type}) if mask.dl_vlan : ret.update({'dl_vlan' : flow.dl_vlan}) if mask.dl_vlan_pcp : ret.update({'dl_vlan_pcp' : flow.dl_vlan_pcp}) if mask.mpls_label : ret.update({'mpls_label' : flow.mpls_label}) if mask.mpls_tc : ret.update({'mpls_tc' : flow.mpls_tc}) if mask.mpls_bos : ret.update({'mpls_bos' : flow.mpls_bos}) if mask.in_port : ret.update({'in_port' : flow.in_port}) #if mask.dl_type and (flow.dl_type is mul.ETH_TYPE_IP or mul.ETH_TYPE_ARP or mul.ETH_TYPE_IPV6): if mask.dl_type and (flow.dl_type is 0x0800 or 0x0806 or 0x86dd): if mask.nw_proto : ret.update({'nw_proto': flow.nw_proto}) if mask.nw_tos : ret.update({'nw_tos' : flow.nw_tos}) if mask.tp_dst : ret.update({'tp_dst' : flow.tp_dst}) if mask.tp_src : ret.update({'tp_src' : flow.tp_src}) if flow.dl_type == 0x86dd: nw_src = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 0) nw_dst = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 1) if nw_dst != '-1' : ret.update({'nw_dst6' : nw_dst}) if nw_src != '-1' : ret.update({'nw_src6' : nw_src}) else: nw_src = mul.nbapi_parse_nw_addr_to_str(flow, mask, 0) nw_dst = mul.nbapi_parse_nw_addr_to_str(flow, mask, 1) if nw_dst != '-1' : ret.update({'nw_dst': nw_dst}) if nw_src != '-1' : ret.update({'nw_src': nw_src}) return ret
def __flow_struct_serialization(self, flow, mask): dl_src = mul.nbapi_parse_mac_to_str(flow.dl_src) dl_dst = mul.nbapi_parse_mac_to_str(flow.dl_dst) dl_src_mask = mul.nbapi_parse_mac_to_str(mask.dl_src) dl_dst_mask = mul.nbapi_parse_mac_to_str(mask.dl_dst) ret = {'table_id': flow.table_id} if dl_src_mask != "00:00:00:00:00:00": ret.update({'dl_src': dl_src}) if dl_dst_mask != "00:00:00:00:00:00": ret.update({'dl_dst': dl_dst}) if mask.dl_type: ret.update({'dl_type': '0x%lx' % flow.dl_type}) if mask.dl_vlan: ret.update({'dl_vlan': flow.dl_vlan}) if mask.dl_vlan_pcp: ret.update({'dl_vlan_pcp': flow.dl_vlan_pcp}) if mask.mpls_label: ret.update({'mpls_label': flow.mpls_label}) if mask.mpls_tc: ret.update({'mpls_tc': flow.mpls_tc}) if mask.mpls_bos: ret.update({'mpls_bos': flow.mpls_bos}) if mask.in_port: ret.update({'in_port': flow.in_port}) #if mask.dl_type and (flow.dl_type is mul.ETH_TYPE_IP or mul.ETH_TYPE_ARP or mul.ETH_TYPE_IPV6): if mask.dl_type and (flow.dl_type is 0x0800 or 0x0806 or 0x86dd): if mask.nw_proto: ret.update({'nw_proto': flow.nw_proto}) if mask.nw_tos: ret.update({'nw_tos': flow.nw_tos}) if mask.tp_dst: ret.update({'tp_dst': flow.tp_dst}) if mask.tp_src: ret.update({'tp_src': flow.tp_src}) if flow.dl_type == 0x86dd: nw_src = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 0) nw_dst = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 1) if nw_dst != '-1': ret.update({'nw_dst6': nw_dst}) if nw_src != '-1': ret.update({'nw_src6': nw_src}) else: nw_src = mul.nbapi_parse_nw_addr_to_str(flow, mask, 0) nw_dst = mul.nbapi_parse_nw_addr_to_str(flow, mask, 1) if nw_dst != '-1': ret.update({'nw_dst': nw_dst}) if nw_src != '-1': ret.update({'nw_src': nw_src}) return ret
def get(self): #, tenant_id=None, network_id=None, host_id=None): logger.debug("request url - %s", self.get_request_uri()) hosts = mul.get_fabric_host_all(1) logger.debug(str(len(hosts))) ret = [] for host in hosts: host_flow = host.host_flow host_ip = mul.nbapi_fab_parse_nw_addr_to_str(host_flow) host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) res_d = { 'tenant_id': mul.nbapi_uuid_to_str(host.tenant_id), 'network_id': mul.nbapi_uuid_to_str(host.network_id), 'dl_src': host_mac, 'nw_src': host_ip, 'switch_dpid': '0x%lx' % host.switch_id.datapath_id, 'port': '%4hu' % host_flow.in_port } ret.append(res_d) self.finish({'hosts': ret})
def get(self): # , tenant_id=None, network_id=None, host_id=None): logger.debug("request url - %s", self.get_request_uri()) hosts = mul.get_fabric_host_all(1) logger.debug(str(len(hosts))) ret = [] for host in hosts: host_flow = host.host_flow host_ip = mul.nbapi_fab_parse_nw_addr_to_str(host_flow) host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) res_d = { "tenant_id": mul.nbapi_uuid_to_str(host.tenant_id), "network_id": mul.nbapi_uuid_to_str(host.network_id), "dl_src": host_mac, "nw_src": host_ip, "switch_dpid": "0x%lx" % host.switch_id.datapath_id, "port": "%4hu" % host_flow.in_port, } ret.append(res_d) self.finish({"hosts": ret})
def get(self):#, tenant_id=None, network_id=None, host_id=None): logger.debug("request url - %s", self.get_request_uri()) hosts = mul.get_fabric_host_all(1) logger.debug(str(len(hosts))) ret = [] for host in hosts: host_flow = host.host_flow host_ip = mul.nbapi_fab_parse_nw_addr_to_str(host_flow) host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) res_d = { 'tenant_id' : mul.nbapi_uuid_to_str(host.tenant_id), 'network_id' : mul.nbapi_uuid_to_str(host.network_id), 'dl_src' : host_mac, 'nw_src' : host_ip, 'switch_dpid' : '0x%lx' % host.switch_id.datapath_id, 'port' : '%4hu' %host_flow.in_port } ret.append(res_d) self.finish({'hosts' : ret })