Ejemplo n.º 1
0
def bgp_speaker_from_neutron_bgp_speaker(speaker):
    return bgp.BGPSpeaker(id=speaker.get('id'),
                          topic=speaker.get('tenant_id'),
                          name=speaker.get('name'),
                          local_as=int(speaker.get('local_as')),
                          peers=speaker.get('peers', []),
                          ip_version=speaker.get('ip_version'))
Ejemplo n.º 2
0
    def _update_bgp_speaker_routes(self, context, bgp_speaker_id, topic):
        """Update the all routes of bgp speaker"""

        prefixes = self._get_tenant_network_routes_by_bgp_speaker(
            context, bgp_speaker_id)
        # Translate to the format of dragonflow db data.
        prefix_routes = [{
            'destination': x['destination'],
            'nexthop': x['next_hop']
        } for x in prefixes]

        host_routes = []
        for _net_id, host, addr in self._get_fip_query(context,
                                                       bgp_speaker_id).all():
            external_ip = self._get_external_ip_by_host(host)
            if not external_ip:
                continue

            host_routes.append({
                'destination': addr + '/32',
                'nexthop': external_ip
            })

        lean_bgp_speaker = bgp.BGPSpeaker(id=bgp_speaker_id,
                                          topic=topic,
                                          prefix_routes=prefix_routes,
                                          host_routes=host_routes)
        self.nb_api.update(lean_bgp_speaker, skip_send_event=True)
Ejemplo n.º 3
0
        def get_all_with_routes_side_effect(model, topic):
            if model == bgp.BGPPeer:
                return [
                    bgp.BGPPeer(id="peer1",
                                topic="topic1",
                                name="peer1",
                                peer_ip="172.24.4.88",
                                remote_as=4321)
                ]

            if model == bgp.BGPSpeaker:
                routes = [{
                    'destination': "10.0.0.0/24",
                    'nexthop': "172.24.4.66"
                }]
                return [
                    bgp.BGPSpeaker(id="speaker1",
                                   topic="topic1",
                                   name="speaker1",
                                   local_as=1234,
                                   peers=["peer1"],
                                   prefix_routes=routes,
                                   host_routes=[],
                                   ip_version=4)
                ]
Ejemplo n.º 4
0
def bgp_speaker_from_neutron_bgp_speaker(speaker):
    topic = df_utils.get_obj_topic(speaker)
    return bgp.BGPSpeaker(id=speaker.get('id'),
                          topic=topic,
                          name=speaker.get('name'),
                          local_as=int(speaker.get('local_as')),
                          peers=speaker.get('peers', []),
                          ip_version=speaker.get('ip_version'))
Ejemplo n.º 5
0
    def test_sync_bgp_data_to_db_store(self):
        self.bgp_service.nb_api.get_all.side_effect = get_all_side_effect
        # Give fixed interval a chance to run.
        self.bgp_service.bgp_pulse.fire()

        self.assertTrue(
            self.bgp_service.db_store.get_one(bgp.BGPPeer(id="peer1")))
        self.assertTrue(
            self.bgp_service.db_store.get_one(bgp.BGPSpeaker(id="speaker1")))
Ejemplo n.º 6
0
 def add_bgp_peer(self, context, bgp_speaker_id, bgp_peer_info):
     ret_value = super(DFBgpPlugin,
                       self).add_bgp_peer(context, bgp_speaker_id,
                                          bgp_peer_info)
     tenant_id = context.tenant_id
     bgp_speaker = self.nb_api.get(
         bgp.BGPSpeaker(id=bgp_speaker_id, topic=tenant_id))
     bgp_speaker.peers.append(ret_value['bgp_peer_id'])
     self.nb_api.update(bgp_speaker, skip_send_event=True)
     return ret_value
Ejemplo n.º 7
0
 def get_advertised_routes(self, context, bgp_speaker_id):
     tenant_id = context.tenant_id
     bgp_speaker = self.nb_api.get(
         bgp.BGPSpeaker(id=bgp_speaker_id, topic=tenant_id))
     bgp_routes = bgp_speaker.host_routes + bgp_speaker.prefix_routes
     # Translate to the format that neutron will acccept.
     return {
         'advertised_routes': [{
             'destination': r.destination,
             'next_hop': r.nexthop
         } for r in bgp_routes]
     }
Ejemplo n.º 8
0
    def _update_bgp_speaker_tenant_network_routes(self, context,
                                                  bgp_speaker_id, topic):
        """Update the prefix routes while keep the host(fip) routes"""

        prefixes = self._get_tenant_network_routes_by_bgp_speaker(
            context, bgp_speaker_id)
        # Translate to the format of dragonflow db data.
        routes = [{
            'destination': x['destination'],
            'nexthop': x['next_hop']
        } for x in prefixes]
        bgp_speaker = self.nb_api.get(
            bgp.BGPSpeaker(id=bgp_speaker_id, topic=topic))

        bgp_speaker.prefix_routes = routes
        self.nb_api.update(bgp_speaker, skip_send_event=True)
Ejemplo n.º 9
0
    def _del_bgp_speaker_fip_route(self, context, bgp_speaker_id, topic, cidr):
        """Delete host route from bgp speaker in nd db"""

        bgp_speaker = self.nb_api.get(
            bgp.BGPSpeaker(id=bgp_speaker_id, topic=topic))
        current_routes = {
            str(r.destination): r
            for r in bgp_speaker.host_routes
        }
        if cidr not in current_routes:
            # Route has not been added, skip.
            return

        del current_routes[cidr]
        bgp_speaker.host_routes = current_routes.values()
        self.nb_api.update(bgp_speaker, skip_send_event=True)
Ejemplo n.º 10
0
    def _add_bgp_speaker_fip_route(self, context, bgp_speaker_id, topic,
                                   route):
        """Add host route to bgp speaker in nb db"""

        bgp_speaker = self.nb_api.get(
            bgp.BGPSpeaker(id=bgp_speaker_id, topic=topic))
        # Since all routable cidrs are in one address scope, they should be
        # unique in such context.
        current_routes = {
            str(r.destination): r
            for r in bgp_speaker.host_routes
        }
        cidr = route['destination']
        if (cidr in current_routes
                and route == current_routes[cidr].to_struct()):
            # Nothing changes, skip.
            return

        current_routes[cidr] = route
        bgp_speaker.host_routes = current_routes.values()
        self.nb_api.update(bgp_speaker, skip_send_event=True)
Ejemplo n.º 11
0
def get_all_side_effect(model, topic):
    if model == bgp.BGPPeer:
        return [
            bgp.BGPPeer(id="peer1",
                        topic="topic1",
                        name="peer1",
                        peer_ip="172.24.4.88",
                        remote_as=4321)
        ]

    if model == bgp.BGPSpeaker:
        return [
            bgp.BGPSpeaker(id="speaker1",
                           topic="topic1",
                           name="speaker1",
                           local_as=1234,
                           peers=["peer1"],
                           host_routes=[],
                           prefix_routes=[],
                           ip_version=4)
        ]
Ejemplo n.º 12
0
 def _remove_bgp_peer_from_bgp_speaker(self, context, bgp_speaker_id,
                                       peer_id, topic):
     bgp_speaker = self.nb_api.get(
         bgp.BGPSpeaker(id=bgp_speaker_id, topic=topic))
     bgp_speaker.remove_peer(peer_id)
     self.nb_api.update(bgp_speaker, skip_send_event=True)
Ejemplo n.º 13
0
 def delete_bgp_speaker(self, context, bgp_speaker_id):
     super(DFBgpPlugin, self).delete_bgp_speaker(context, bgp_speaker_id)
     self.nb_api.delete(bgp.BGPSpeaker(id=bgp_speaker_id),
                        skip_send_event=True)
Ejemplo n.º 14
0
 def exists(self):
     bgp_speaker = self.nb_api.get(bgp.BGPSpeaker(id=self.speaker_id))
     return bool(bgp_speaker)
Ejemplo n.º 15
0
 def get_nb_bgp_speaker(self):
     return self.nb_api.get(bgp.BGPSpeaker(id=self.speaker_id))