Beispiel #1
0
    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')
Beispiel #2
0
    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]