def create_link_data(self, interface1, interface2, message_type): """ Create a wireless link/unlink data message. :param core.coreobj.PyCoreNetIf interface1: interface one :param core.coreobj.PyCoreNetIf interface2: interface two :param message_type: link message type :return: link data :rtype: LinkData """ return LinkData(message_type=message_type, node1_id=interface1.node.objid, node2_id=interface2.node.objid, network_id=self.wlan.objid, link_type=LinkTypes.WIRELESS.value)
def all_link_data(self, flags): """ Build link data objects for this network. Each link object describes a link between this network and a node. """ all_links = [] # build a link message from this network node to each node having a # connected interface for netif in self.netifs(sort=True): if not hasattr(netif, "node"): continue otherobj = netif.node uni = False if otherobj is None: # two layer-2 switches/hubs linked together via linknet() if not hasattr(netif, "othernet"): continue otherobj = netif.othernet if otherobj.objid == self.objid: continue netif.swapparams('_params_up') upstream_params = netif.getparams() netif.swapparams('_params_up') if netif.getparams() != upstream_params: uni = True unidirectional = 0 if uni: unidirectional = 1 interface2_ip4 = None interface2_ip4_mask = None interface2_ip6 = None interface2_ip6_mask = None for address in netif.addrlist: ip, sep, mask = address.partition('/') mask = int(mask) if ipaddress.is_ipv4_address(ip): family = AF_INET ipl = socket.inet_pton(family, ip) interface2_ip4 = ipaddress.IpAddress(af=family, address=ipl) interface2_ip4_mask = mask else: family = AF_INET6 ipl = socket.inet_pton(family, ip) interface2_ip6 = ipaddress.IpAddress(af=family, address=ipl) interface2_ip6_mask = mask link_data = LinkData(message_type=flags, node1_id=self.objid, node2_id=otherobj.objid, link_type=self.linktype, unidirectional=unidirectional, interface2_id=otherobj.getifindex(netif), interface2_mac=netif.hwaddr, interface2_ip4=interface2_ip4, interface2_ip4_mask=interface2_ip4_mask, interface2_ip6=interface2_ip6, interface2_ip6_mask=interface2_ip6_mask, delay=netif.getparam("delay"), bandwidth=netif.getparam("bw"), dup=netif.getparam("duplicate"), jitter=netif.getparam("jitter")) all_links.append(link_data) if not uni: continue netif.swapparams('_params_up') link_data = LinkData(message_type=0, node1_id=otherobj.objid, node2_id=self.objid, unidirectional=1, delay=netif.getparam("delay"), bandwidth=netif.getparam("bw"), dup=netif.getparam("duplicate"), jitter=netif.getparam("jitter")) netif.swapparams('_params_up') all_links.append(link_data) return all_links
def all_link_data(self, flags): """ Build CORE API TLVs for a point-to-point link. One Link message describes this network. """ all_links = [] if len(self._netif) != 2: return all_links if1, if2 = self._netif.items() if1 = if1[1] if2 = if2[1] unidirectional = 0 if if1.getparams() != if2.getparams(): unidirectional = 1 interface1_ip4 = None interface1_ip4_mask = None interface1_ip6 = None interface1_ip6_mask = None for address in if1.addrlist: ip, sep, mask = address.partition("/") mask = int(mask) if ipaddress.is_ipv4_address(ip): family = AF_INET ipl = socket.inet_pton(family, ip) interface1_ip4 = ipaddress.IpAddress(af=family, address=ipl) interface1_ip4_mask = mask else: family = AF_INET6 ipl = socket.inet_pton(family, ip) interface1_ip6 = ipaddress.IpAddress(af=family, address=ipl) interface1_ip6_mask = mask interface2_ip4 = None interface2_ip4_mask = None interface2_ip6 = None interface2_ip6_mask = None for address in if2.addrlist: ip, sep, mask = address.partition("/") mask = int(mask) if ipaddress.is_ipv4_address(ip): family = AF_INET ipl = socket.inet_pton(family, ip) interface2_ip4 = ipaddress.IpAddress(af=family, address=ipl) interface2_ip4_mask = mask else: family = AF_INET6 ipl = socket.inet_pton(family, ip) interface2_ip6 = ipaddress.IpAddress(af=family, address=ipl) interface2_ip6_mask = mask # TODO: not currently used # loss=netif.getparam("loss") link_data = LinkData( message_type=flags, node1_id=if1.node.objid, node2_id=if2.node.objid, link_type=self.linktype, unidirectional=unidirectional, delay=if1.getparam("delay"), bandwidth=if1.getparam("bw"), dup=if1.getparam("duplicate"), jitter=if1.getparam("jitter"), interface1_id=if1.node.getifindex(if1), interface1_mac=if1.hwaddr, interface1_ip4=interface1_ip4, interface1_ip4_mask=interface1_ip4_mask, interface1_ip6=interface1_ip6, interface1_ip6_mask=interface1_ip6_mask, interface2_id=if2.node.getifindex(if2), interface2_mac=if2.hwaddr, interface2_ip4=interface2_ip4, interface2_ip4_mask=interface2_ip4_mask, interface2_ip6=interface2_ip6, interface2_ip6_mask=interface2_ip6_mask, ) all_links.append(link_data) # build a 2nd link message for the upstream link parameters # (swap if1 and if2) if unidirectional: link_data = LinkData(message_type=0, node1_id=if2.node.objid, node2_id=if1.node.objid, delay=if1.getparam("delay"), bandwidth=if1.getparam("bw"), dup=if1.getparam("duplicate"), jitter=if1.getparam("jitter"), unidirectional=1, interface1_id=if2.node.getifindex(if2), interface2_id=if1.node.getifindex(if1)) all_links.append(link_data) return all_links