def run(self): self._client = self._create_ctrl_client() resp = self._client.getRouteTableDetails() if not resp: print("No Route Table Details Found") return for entry in resp: suffix = "" if (entry.isConnected): suffix += " (connected)" print("Network Address: %s/%d %s" % (utils.ip_ntop( entry.dest.ip.addr), entry.dest.prefixLength, suffix)) for clAndNxthops in entry.nextHopMulti: print(" Nexthops from client %d" % clAndNxthops.clientId) for nextHop in clAndNxthops.nextHopAddrs: print(" %s" % utils.ip_ntop(nextHop.addr)) print(" Action: %s" % entry.action) if len(entry.fwdInfo) > 0: print(" Forwarding via:") for ifAndIp in entry.fwdInfo: print( " (i/f %d) %s" % (ifAndIp.interfaceID, utils.ip_ntop(ifAndIp.ip.addr))) else: print(" No Forwarding Info") print()
def printRouteDetailEntry(entry): suffix = "" if (entry.isConnected): suffix += " (connected)" print("Network Address: %s/%d %s" % (utils.ip_ntop(entry.dest.ip.addr), entry.dest.prefixLength, suffix)) for clAndNxthops in entry.nextHopMulti: print(" Nexthops from client %d" % clAndNxthops.clientId) for nextHop in clAndNxthops.nextHopAddrs: print(" %s" % nexthop_to_str(nextHop)) print(" Action: %s" % entry.action) if entry.nextHops and len(entry.nextHops) > 0: print(" Forwarding via:") for nextHop in entry.nextHops: w = "x{}".format(nextHop.weight) if nextHop.weight else "" print(" (i/f %s) %s%s" % (nextHop.address.ifName, utils.ip_ntop( nextHop.address.addr), w)) elif len(entry.fwdInfo) > 0: print(" Forwarding via:") for ifAndIp in entry.fwdInfo: print(" (i/f %d) %s" % (ifAndIp.interfaceID, utils.ip_ntop(ifAndIp.ip.addr))) else: print(" No Forwarding Info") print(" Admin Distance: %s" % entry.adminDistance) print()
def printRouteDetailEntry(entry, vlan_aggregate_port_map, vlan_port_map): suffix = "" if entry.isConnected: suffix += " (connected)" print("Network Address: %s/%d %s" % (utils.ip_ntop(entry.dest.ip.addr), entry.dest.prefixLength, suffix)) for clAndNxthops in entry.nextHopMulti: print(" Nexthops from client %d" % clAndNxthops.clientId) if clAndNxthops.nextHopAddrs: for address in clAndNxthops.nextHopAddrs: print(" %s" % utils.nexthop_to_str(NextHopThrift(address=address))) elif clAndNxthops.nextHops: for nextHop in clAndNxthops.nextHops: print(" %s" % utils.nexthop_to_str(nextHop)) print(" Action: %s" % entry.action) if entry.nextHops and len(entry.nextHops) > 0: print(" Forwarding via:") for nextHop in entry.nextHops: print(" {}".format( utils.nexthop_to_str(nextHop, vlan_aggregate_port_map, vlan_port_map))) elif len(entry.fwdInfo) > 0: print(" Forwarding via:") for ifAndIp in entry.fwdInfo: print(" (i/f %d) %s" % (ifAndIp.interfaceID, utils.ip_ntop(ifAndIp.ip.addr))) else: print(" No Forwarding Info") print(" Admin Distance: %s" % entry.adminDistance) print()
def printIpRoute(self, addr, vrf): resp = self._client.getIpRoute(addr, vrf) print('Route to ' + addr.addr + ', Vrf: %d' % vrf) netAddr = utils.ip_ntop(resp.dest.ip.addr) prefix = resp.dest.prefixLength if netAddr and resp.nextHopAddrs: print('N/w: %s/%d' % (netAddr, prefix)) for nexthops in resp.nextHopAddrs: print('\t\tvia: ' + utils.ip_ntop(nexthops.addr)) else: print('No Route to destination')
def run(self): self._client = self._create_ctrl_client() resp = self._client.getRouteTable() if not resp: print("No Route Table Entries Found") return for entry in resp: print("Network Address: %s/%d" % (utils.ip_ntop(entry.dest.ip.addr), entry.dest.prefixLength)) # Need to check the nextHopAddresses for nhop in entry.nextHopAddrs: print("\tvia %s" % utils.ip_ntop(nhop.addr))
def run(self): with self._create_agent_client() as client: resp = client.getAclTable() if not resp: print("No Acl Entries Found") return resp = sorted(resp, key=lambda x: (x.priority)) for entry in resp: print("Acl: %s" % entry.name) print(" priority: %d" % entry.priority) if entry.srcIp.addr: print( " src ip: %s/%d" % (utils.ip_ntop(entry.srcIp.addr), entry.srcIpPrefixLength)) if entry.dstIp.addr: print( " dst ip: %s/%d" % (utils.ip_ntop(entry.dstIp.addr), entry.dstIpPrefixLength)) if entry.proto: print(" proto: %d(%s)" % (entry.proto, self.getProtoString(entry.proto))) if entry.srcPort: print(" src port: %d" % entry.srcPort) if entry.dstPort: print(" dst port: %d" % entry.dstPort) if entry.ipFrag: print(" ip fragment: %d" % entry.ipFrag) if entry.dscp: print(" dscp: %d" % entry.dscp) if entry.ipType: print(" ip type: %d" % entry.ipType) if entry.icmpType: print(" icmp type: %d" % entry.icmpType) if entry.icmpCode: print(" icmp code: %d" % entry.icmpCode) if entry.ttl: print(" icmp code: %d" % entry.ttl) if entry.l4SrcPort: print(" L4 src port: %d(%s)" % (entry.l4SrcPort, socket.getservbyport(entry.l4SrcPort))) if entry.l4DstPort: print(" L4 dst port: %d(%s)" % (entry.l4DstPort, socket.getservbyport(entry.l4DstPort))) if entry.dstMac: print(" dst mac: %s" % entry.dstMac) print(" action: %s" % entry.actionType) print()
def run(self, client_id, ipv4, ipv6): with self._create_agent_client() as client: if client_id is None: resp = client.getRouteTable() else: resp = client.getRouteTableByClient(client_id) if not resp: print("No Route Table Entries Found") return for entry in resp: if ipv6 and not ipv4 and len(entry.dest.ip.addr) == 4: continue if ipv4 and not ipv6 and len(entry.dest.ip.addr) == 16: continue print("Network Address: %s/%d" % (utils.ip_ntop( entry.dest.ip.addr), entry.dest.prefixLength)) # Need to check the nextHopAddresses if entry.nextHops: for nextHop in entry.nextHops: w = "x{}".format( nextHop.weight) if nextHop.weight else "" print("\tvia %s%s" % (nexthop_to_str(nextHop.address), w)) else: for nextHop in entry.nextHopAddrs: print("\tvia %s" % nexthop_to_str(nextHop))
def run(self, client_id, ipv4, ipv6): with self._create_agent_client() as client: if client_id is None: resp = client.getRouteTable() else: resp = client.getRouteTableByClient(client_id) if not resp: print("No Route Table Entries Found") return for entry in resp: if ipv6 and not ipv4 and len(entry.dest.ip.addr) == 4: continue if ipv4 and not ipv6 and len(entry.dest.ip.addr) == 16: continue prefix = utils.ip_ntop(entry.dest.ip.addr) prefix_mask_len = entry.dest.prefixLength ucmp_active = " (UCMP Active)" if is_ucmp_active( entry.nextHops) else "" print( f"Network Address: {prefix}/{prefix_mask_len}{ucmp_active}" ) # Need to check the nextHopAddresses if entry.nextHops: for nextHop in entry.nextHops: weight = " - weight {}".format( nextHop.weight) if ucmp_active else "" print("\tvia %s%s" % (nexthop_to_str(nextHop.address), weight)) else: for nextHop in entry.nextHopAddrs: print("\tvia %s" % nexthop_to_str(nextHop))
def run(self, ip, vrf): addr = Address(addr=ip, type=AddressType.V4) if not addr.addr: print('No ip address provided') return self._client = self._create_ctrl_client() resp = self._client.getIpRoute(addr, vrf) print('Route to ' + addr.addr + ', Vrf: %d' % vrf) netAddr = utils.ip_ntop(resp.dest.ip.addr) prefix = resp.dest.prefixLength if netAddr and resp.nextHopAddrs: print('N/w: %s/%d' % (netAddr, prefix)) for nexthops in resp.nextHopAddrs: print('\t\tvia: ' + utils.ip_ntop(nexthops.addr)) else: print('No Route to destination')
def run(self, flushType, network, vlan): if (isinstance(network, ipaddress.IPv6Network) and network.prefixlen == 128) or (isinstance(network, ipaddress.IPv4Network) and network.prefixlen == 32): self._flush_entry(str(network.network_address), vlan) return with self._create_agent_client() as client: if flushType == FlushType.arp: table = client.getArpTable() elif flushType == FlushType.ndp: table = client.getNdpTable() else: print("Invaid flushType") exit(1) num_entries = 0 for entry in table: if (ipaddress.ip_address(utils.ip_ntop(entry.ip.addr)) in ipaddress.ip_network(network)) and ( vlan == 0 or vlan == entry.vlanID): num_entries += client.flushNeighborEntry( entry.ip, entry.vlanID) print("Flushed {} entries".format(num_entries))
def run(self, interface): self._client = self._create_agent_client() resp = self._client.getInterfaceDetail(interface) if not resp: print("No interface details found for interface") return print("\nAddress:") for addr in resp.address: print("\t%s/%d" % (utils.ip_ntop(addr.ip.addr), addr.prefixLength))
def printRouteDetailEntry(entry): suffix = "" if (entry.isConnected): suffix += " (connected)" print("Network Address: %s/%d %s" % (utils.ip_ntop(entry.dest.ip.addr), entry.dest.prefixLength, suffix)) for clAndNxthops in entry.nextHopMulti: print(" Nexthops from client %d" % clAndNxthops.clientId) for nextHop in clAndNxthops.nextHopAddrs: print(" %s" % utils.ip_ntop(nextHop.addr)) print(" Action: %s" % entry.action) if len(entry.fwdInfo) > 0: print(" Forwarding via:") for ifAndIp in entry.fwdInfo: print(" (i/f %d) %s" % (ifAndIp.interfaceID, utils.ip_ntop(ifAndIp.ip.addr))) else: print(" No Forwarding Info") print()
def printRouteDetailEntry(entry): suffix = "" if (entry.isConnected): suffix += " (connected)" print("Network Address: %s/%d %s" % (utils.ip_ntop(entry.dest.ip.addr), entry.dest.prefixLength, suffix)) for clAndNxthops in entry.nextHopMulti: print(" Nexthops from client %d" % clAndNxthops.clientId) for nextHop in clAndNxthops.nextHopAddrs: print(" %s" % nexthop_to_str(nextHop)) print(" Action: %s" % entry.action) if len(entry.fwdInfo) > 0: print(" Forwarding via:") for ifAndIp in entry.fwdInfo: print(" (i/f %d) %s" % (ifAndIp.interfaceID, utils.ip_ntop(ifAndIp.ip.addr))) else: print(" No Forwarding Info") print(" Admin Distance: %s" % entry.adminDistance) print()
def _interface_details(self, interface): resp = self._client.getInterfaceDetail(interface) if not resp: print("No interface details found for interface") return print("%s\tInterface ID: %d" % (resp.interfaceName, resp.interfaceId)) print(" Vlan: %d\t\t\tRouter Id: %d" % (resp.vlanId, resp.routerId)) print(" Mac Address: %s" % resp.mac) print(" IP Address:") for addr in resp.address: print("\t%s/%d" % (utils.ip_ntop(addr.ip.addr), addr.prefixLength))
def run(self, client_id, ipv4, ipv6): with ExitStack() as stack: agent_client = stack.enter_context(self._create_agent_client()) qsfp_client = stack.enter_context(self._create_qsfp_client()) if client_id is None: resp = agent_client.getRouteTable() else: resp = agent_client.getRouteTableByClient(client_id) if not resp: print("No Route Table Entries Found") return # Getting the port/agg to VLAN map in order to display them vlan_port_map = utils.get_vlan_port_map( agent_client, qsfp_client, colors=False, details=False ) vlan_aggregate_port_map = utils.get_vlan_aggregate_port_map(agent_client) for entry in resp: if ipv6 and not ipv4 and len(entry.dest.ip.addr) == 4: continue if ipv4 and not ipv6 and len(entry.dest.ip.addr) == 16: continue prefix = utils.ip_ntop(entry.dest.ip.addr) prefix_mask_len = entry.dest.prefixLength ucmp_active = " (UCMP Active)" if is_ucmp_active(entry.nextHops) else "" print(f"Network Address: {prefix}/{prefix_mask_len}{ucmp_active}") # Need to check the nextHopAddresses if entry.nextHops: for nextHop in entry.nextHops: print( "\tvia %s" % ( utils.nexthop_to_str( nextHop, vlan_aggregate_port_map=vlan_aggregate_port_map, vlan_port_map=vlan_port_map, ucmp_active=ucmp_active, ) ) ) else: for address in entry.nextHopAddrs: print( "\tvia %s" % utils.nexthop_to_str(NextHopThrift(address=address)) )
def _print_table(self, entries, width, ports): tmpl = "{:" + str(width) + "} {:18} {:<10} {:18} {!s:12} {}" print(tmpl.format( "IP Address", "MAC Address", "Port", "VLAN", "State", "TTL")) for entry in sorted(entries, key=lambda e: e.ip.addr): port_identifier = entry.port if entry.port in ports and ports[entry.port].name: port_identifier = ports[entry.port].name ip = utils.ip_ntop(entry.ip.addr) vlan_field = '{} ({})'.format(entry.vlanName, entry.vlanID) ttl = '{}s'.format(entry.ttl // 1000) if entry.ttl else '?' state = entry.state if entry.state else 'NA' print(tmpl.format(ip, entry.mac, port_identifier, vlan_field, state, ttl))
def _interface_details(self, client, interface): resp = client.getInterfaceDetail(interface) if not resp: print("No interface details found for interface") return print("{}\tInterface ID: {}".format(resp.interfaceName, resp.interfaceId)) print(" Vlan: {}\t\t\tRouter Id: {}".format(resp.vlanId, resp.routerId)) print(" MTU: {}".format(resp.mtu)) print(" Mac Address: {}".format(resp.mac)) print(" IP Address:") for addr in resp.address: print("\t{}/{}".format(utils.ip_ntop(addr.ip.addr), addr.prefixLength))
def _interface_details(self, interface): resp = self._client.getInterfaceDetail(interface) if not resp: print("No interface details found for interface") return print("{}\tInterface ID: {}".format( resp.interfaceName, resp.interfaceId)) print(" Vlan: {}\t\t\tRouter Id: {}".format( resp.vlanId, resp.routerId)) print(" MTU: {}".format(resp.mtu)) print(" Mac Address: {}".format(resp.mac)) print(" IP Address:") for addr in resp.address: print("\t{}/{}".format(utils.ip_ntop(addr.ip.addr), addr.prefixLength))
def print_table(self, entries, name, width, client=None): if client is None: client = self._create_agent_client() tmpl = "{:" + str(width) + "} {:18} {:<10} {:18} {!s:12} {}" print(tmpl.format( "IP Address", "MAC Address", "Port", "VLAN", "State", "TTL")) ports = client.getAllPortInfo() for entry in sorted(entries, key=lambda e: e.ip.addr): port_identifier = entry.port if entry.port in ports and ports[entry.port].name: port_identifier = ports[entry.port].name ip = utils.ip_ntop(entry.ip.addr) vlan_field = '{} ({})'.format(entry.vlanName, entry.vlanID) ttl = '{}s'.format(entry.ttl // 1000) if entry.ttl else '?' state = entry.state if entry.state else 'NA' print(tmpl.format(ip, entry.mac, port_identifier, vlan_field, state, ttl))
def run(self, client_id, ipv4, ipv6): with self._create_agent_client() as client: if client_id is None: resp = client.getRouteTable() else: resp = client.getRouteTableByClient(client_id) if not resp: print("No Route Table Entries Found") return for entry in resp: if ipv6 and not ipv4 and len(entry.dest.ip.addr) == 4: continue if ipv4 and not ipv6 and len(entry.dest.ip.addr) == 16: continue print("Network Address: %s/%d" % (utils.ip_ntop(entry.dest.ip.addr), entry.dest.prefixLength)) # Need to check the nextHopAddresses for nextHop in entry.nextHopAddrs: print("\tvia %s" % nexthop_to_str(nextHop))
def print_table(self, entries, name, width, client=None): if client is None: client = self._create_ctrl_client() tmpl = "{:" + str(width) + "} {:18} {:>4} {:18} {!s:12} {}" print(tmpl.format( "IP Address", "MAC Address", "Port", "VLAN", "State", "TTL")) port_list = client.getAllPortInfo() for port_info in sorted(port_list.values(), key=utils.port_sort_fn): port_data = port_info.portId for entry in entries: if port_data == entry.port: ip = utils.ip_ntop(entry.ip.addr) vlan_field = '{} ({})'.format(entry.vlanName, entry.vlanID) if port_info.name: port_data = port_info.name ttl = entry.ttl // 1000 if entry.ttl else '?' state = entry.state if entry.state else 'NA' print(tmpl.format(ip, entry.mac, entry.port, vlan_field, state, '{}s'.format(ttl)))
def print_table(self, entries, name, width, client=None): if client is None: client = self._create_ctrl_client() tmpl = "{:" + str(width) + "} {:18} {:>4} {:18} {!s:12} {}" print( tmpl.format("IP Address", "MAC Address", "Port", "VLAN", "State", "TTL")) port_list = client.getAllPortInfo() for port_info in sorted(port_list.values(), key=utils.port_sort_fn): port_data = port_info.portId for entry in entries: if port_data == entry.port: ip = utils.ip_ntop(entry.ip.addr) vlan_field = '{} ({})'.format(entry.vlanName, entry.vlanID) if port_info.name: port_data = port_info.name ttl = entry.ttl // 1000 if entry.ttl else '?' state = entry.state if entry.state else 'NA' print( tmpl.format(ip, entry.mac, entry.port, vlan_field, state, '{}s'.format(ttl)))
def nexthop_to_str(nh): ip_str = utils.ip_ntop(nh.addr) if not nh.ifName: return ip_str return "{}%{}".format(ip_str, nh.ifName)