backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / services / protocols / bgp / info_base / rtc.py
1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 """
17  Defines data types and models required specifically for RTC support.
18 """
19
20 import logging
21
22 from ryu.lib.packet.bgp import RF_RTC_UC
23
24 from ryu.services.protocols.bgp.info_base.base import Destination
25 from ryu.services.protocols.bgp.info_base.base import NonVrfPathProcessingMixin
26 from ryu.services.protocols.bgp.info_base.base import Path
27 from ryu.services.protocols.bgp.info_base.base import Table
28
29 LOG = logging.getLogger('bgpspeaker.info_base.rtc')
30
31
32 class RtcTable(Table):
33     """Global table to store RT membership information.
34
35     Uses `RtDest` to store destination information for each known RT NLRI path.
36     """
37     ROUTE_FAMILY = RF_RTC_UC
38
39     def __init__(self, core_service, signal_bus):
40         Table.__init__(self, None, core_service, signal_bus)
41
42     def _table_key(self, rtc_nlri):
43         """Return a key that will uniquely identify this RT NLRI inside
44         this table.
45         """
46         return str(rtc_nlri.origin_as) + ':' + rtc_nlri.route_target
47
48     def _create_dest(self, nlri):
49         return RtcDest(self, nlri)
50
51     def __str__(self):
52         return 'RtcTable(scope_id: %s, rf: %s)' % (self.scope_id,
53                                                    self.route_family)
54
55
56 class RtcDest(Destination, NonVrfPathProcessingMixin):
57     ROUTE_FAMILY = RF_RTC_UC
58
59     def _new_best_path(self, new_best_path):
60         NonVrfPathProcessingMixin._new_best_path(self, new_best_path)
61
62     def _best_path_lost(self):
63         NonVrfPathProcessingMixin._best_path_lost(self)
64
65
66 class RtcPath(Path):
67     ROUTE_FAMILY = RF_RTC_UC
68
69     def __init__(self, source, nlri, src_ver_num, pattrs=None,
70                  nexthop='0.0.0.0', is_withdraw=False,
71                  med_set_by_target_neighbor=False):
72         Path.__init__(self, source, nlri, src_ver_num, pattrs, nexthop,
73                       is_withdraw, med_set_by_target_neighbor)