def get_cool_rib(self): # from ryu.services.protocols.bgp.api.base import call # show = { # 'params': ['rib', 'ipv4'], # 'format': format # } # # call('operator.show', **show) from ryu.services.protocols.bgp.operator.internal_api import InternalApi INTERNAL_API = InternalApi() #_init_log_handler()) # table_manager = self.get_core_service().table_manager # gtable = table_manager.get_global_table_by_route_family(rf) return INTERNAL_API.get_single_rib_routes('ipv4')
def __init__(self, sock, addr): super(SshServer, self).__init__() self.sock = sock self.addr = addr # tweak InternalApi and RootCmd for non-bgp related commands self.api = InternalApi(log_handler=logging.StreamHandler(sys.stderr)) setattr(self.api, 'sshserver', self) self.root = RootCmd(self.api) self.root.subcommands['help'] = self.HelpCmd self.root.subcommands['quit'] = self.QuitCmd self.transport = paramiko.Transport(self.sock) self.transport.load_server_moduli() host_key = find_ssh_server_key() self.transport.add_server_key(host_key) self.transport.start_server(server=self) self.is_connected = True # For pylint self.buf = None self.chan = None self.curpos = None self.histindex = None self.history = None self.prompted = None self.promptlen = None
def __init__(self, sock, addr): super(SshServer, self).__init__() # tweak InternalApi and RootCmd for non-bgp related commands self.api = InternalApi(log_handler=logging.StreamHandler(sys.stderr)) setattr(self.api, 'sshserver', self) self.root = RootCmd(self.api) self.root.subcommands['help'] = self.HelpCmd self.root.subcommands['quit'] = self.QuitCmd transport = paramiko.Transport(sock) transport.load_server_moduli() host_key = self._find_ssh_server_key() transport.add_server_key(host_key) self.transport = transport transport.start_server(server=self)
from ryu.services.protocols.bgp.operator.commands.show import ShowCmd from ryu.services.protocols.bgp.operator.internal_api import InternalApi LOG = logging.getLogger('bgpspeaker.api.rtconf') DEFAULT_LOG_FORMAT = '%(asctime)s %(levelname)s %(message)s' def _init_log_handler(): log_handler = RpcLogHandler() log_handler.setLevel(logging.ERROR) log_handler.formatter = logging.Formatter(DEFAULT_LOG_FORMAT) return log_handler INTERNAL_API = InternalApi(_init_log_handler()) class RootCmd(Command): subcommands = {'show': ShowCmd, 'set': SetCmd, 'clear': ClearCmd} def operator_run(cmd, **kwargs): params = kwargs.get('params', []) fmt = kwargs.get('format', 'json') root = RootCmd(api=INTERNAL_API, resp_formatter_name=fmt) ret, _ = root([cmd] + params) if ret.status == STATUS_ERROR: raise ApiException(str(ret.value)) return ret.value
def update_networks_from_rib(self): from ryu.services.protocols.bgp.operator.internal_api import InternalApi INTERNAL_API = InternalApi() rib_bgp = INTERNAL_API.get_single_rib_routes('ipv4') print rib_bgp to_delete = {} for route in rib_bgp: prefix = route['prefix'] paths = route['paths'] best_hop = None list_of_next_hops = [] for index, path in enumerate(paths): aspath = path['aspath'] if aspath == []: continue nexthop = path['nexthop'] list_of_next_hops.append(nexthop) is_best_route = path['best'] if is_best_route: best_hop = nexthop ip = IPNetwork(prefix) # ("172.16.0.0/24") ip_network = str(ip.network) # mask_value = ip.prefixlen # netmask = ip.netmask #print prefix,'\n\n\n' if ip_network not in self.networks: switch = self.neighbor[nexthop]['switch'] port = self.neighbor[nexthop]['port'] controller_ip = None if aspath == []: # aspath = [] means that this prefix is local controller_ip = self.local_networks[prefix][ 'controller_ip'] else: controller_ip = self.hosts['neighbors'][nexthop][ 'controller_ip'] self.networks[ip_network] = { 'mask': str(ip.netmask), 'controller_ip': controller_ip, 'next_hop': { nexthop: { 'switch': switch, 'port': port, 'bandwidth': 0, 'congested': 0 } }, 'as_path': aspath, 'best_hop': nexthop } else: best_next_hop = self.networks[ip_network]['best_hop'] if best_hop != best_next_hop: self.networks[ip_network]['next_hop'][ 'best_hop'] = best_hop if nexthop not in self.networks[ip_network]['next_hop']: switch = self.neighbor[nexthop]['switch'] port = self.neighbor[nexthop]['port'] controller_ip = None if aspath == []: # aspath = [] means that this prefix is local controller_ip = self.local_networks[prefix][ 'controller_ip'] else: controller_ip = self.hosts['neighbors'][nexthop][ 'controller_ip'] self.networks[ip_network]['next_hop'][nexthop] = { 'switch': switch, 'port': port, 'bandwidth': 0, 'congested': 0 } else: #I dont know if it is necessary to change pass self.networks[ip_network]['as_path'] = aspath ip = IPNetwork(prefix) # ("172.16.0.0/24") ip_network = str(ip.network) if ip_network in self.networks: for nexthop in self.networks[ip_network]['next_hop']: if nexthop not in list_of_next_hops: del self.networks[ip_network]['next_hop'][nexthop]
def __init__(self): self._init_log_handler() self.internal_api = InternalApi(self.log_handler)