backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / services / protocols / vrrp / dumper.py
1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2013 Isaku Yamahata <yamahata at private email ne jp>
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 """
18 VRRP event dumper
19 This is also a template for router implementation that support VRRP
20 """
21
22 from ryu.base import app_manager
23 from ryu.controller import handler
24 from ryu.services.protocols.vrrp import event as vrrp_event
25
26
27 class VRRPDumper(app_manager.RyuApp):
28     def __init__(self, *args, **kwargs):
29         super(VRRPDumper, self).__init__(*args, **kwargs)
30
31     @handler.set_ev_cls(vrrp_event.EventVRRPStateChanged)
32     def vrrp_state_changed_handler(self, ev):
33         old_state = ev.old_state
34         new_state = ev.new_state
35         self.logger.info('state change %s: %s -> %s', ev.instance_name,
36                          old_state, new_state)
37         if new_state == vrrp_event.VRRP_STATE_MASTER:
38             self.logger.info('becomes master')
39             if old_state is None:
40                 # RFC3768 6.4.1
41                 # o  Broadcast a gratuitous ARP request containing the virtual
42                 # router MAC address for each IP address associated with the
43                 # virtual router.
44                 #
45                 # or
46                 #
47                 # RFC 5795 6.4.1
48                 # (115)+ If the protected IPvX address is an IPv4 address,
49                 # then:
50                 #   (120) * Broadcast a gratuitous ARP request containing the
51                 #   virtual router MAC address for each IP address associated
52                 #   with the virtual router.
53                 # (125) + else // IPv6
54                 #   (130) * For each IPv6 address associated with the virtual
55                 #   router, send an unsolicited ND Neighbor Advertisement with
56                 #   the Router Flag (R) set, the Solicited Flag (S) unset, the
57                 #   Override flag (O) set, the target address set to the IPv6
58                 #   address of the virtual router, and the target link-layer
59                 #   address set to the virtual router MAC address.
60                 #
61                 pass
62             elif old_state == vrrp_event.VRRP_STATE_BACKUP:
63                 # RFC3768 6.4.2
64                 # o  Broadcast a gratuitous ARP request containing the virtual
65                 #    router MAC address for each IP address associated with the
66                 #    virtual router
67                 #
68                 # or
69                 #
70                 # RFC 5795 6.4.2
71                 # (375)+ If the protected IPvX address is an IPv4 address,
72                 # then:
73                 #   (380)* Broadcast a gratuitous ARP request on that interface
74                 #   containing the virtual router MAC address for each IPv4
75                 #   address associated with the virtual router.
76                 # (385) + else // ipv6
77                 #   (390) * Compute and join the Solicited-Node multicast
78                 #   address [RFC4291] for the IPv6 address(es) associated with
79                 #   the virtual router.
80                 #   (395) * For each IPv6 address associated with the virtual
81                 #   router, send an unsolicited ND Neighbor Advertisement with
82                 #   the Router Flag (R) set, the Solicited Flag (S) unset, the
83                 #   Override flag (O) set, the target address set to the IPv6
84                 #   address of the virtual router, and the target link-layer
85                 #   address set to the virtual router MAC address.
86                 pass
87
88             # RFC 3768 6.4.3
89             # -  MUST respond to ARP requests for the IP address(es) associated
90             #    with the virtual router.
91             # -  MUST forward packets with a destination link layer MAC address
92             #    equal to the virtual router MAC address.
93             # -  MUST NOT accept packets addressed to the IP address(es)
94             #    associated with the virtual router if it is not the IP address
95             #    owner.
96             # -  MUST accept packets addressed to the IP address(es) associated
97             #    with the virtual router if it is the IP address owner.
98             #
99             # or
100             #
101             # RFC5798 6.4.3
102             # (605) - If the protected IPvX address is an IPv4 address, then:
103             #   (610) + MUST respond to ARP requests for the IPv4 address(es)
104             #   associated with the virtual router.
105             # (615) - else // ipv6
106             #   (620) + MUST be a member of the Solicited-Node multicast
107             #   address for the IPv6 address(es) associated with the virtual
108             #   router.
109             #   (625) + MUST respond to ND Neighbor Solicitation message for
110             #   the IPv6 address(es) associated with the virtual router.
111             #   (630) ++ MUST send ND Router Advertisements for the virtual
112             #   router.
113             #   (635) ++ If Accept_Mode is False:  MUST NOT drop IPv6 Neighbor
114             #   Solicitations and Neighbor Advertisements.
115             # (640) +-endif // ipv4?
116             # (645) - MUST forward packets with a destination link-layer MAC
117             # address equal to the virtual router MAC address.
118             # (650) - MUST accept packets addressed to the IPvX address(es)
119             # associated with the virtual router if it is the IPvX address
120             # owner or if Accept_Mode is True.  Otherwise, MUST NOT accept
121             # these packets.
122
123         elif new_state == vrrp_event.VRRP_STATE_BACKUP:
124             self.logger.info('becomes backup')
125
126             # RFC 3768 6.4.2 Backup
127             # -  MUST NOT respond to ARP requests for the IP address(s)
128             #    associated with the virtual router.
129             # -  MUST discard packets with a destination link layer MAC address
130             #    equal to the virtual router MAC address.
131             # -  MUST NOT accept packets addressed to the IP address(es)
132             #    associated with the virtual router.
133             #
134             # or
135             #
136             # RFC 5798 6.4.2 Backup
137             # (305) - If the protected IPvX address is an IPv4 address, then:
138             #   (310) + MUST NOT respond to ARP requests for the IPv4
139             #   address(es) associated with the virtual router.
140             # (315) - else // protected addr is IPv6
141             #   (320) + MUST NOT respond to ND Neighbor Solicitation messages
142             #   for the IPv6 address(es) associated with the virtual router.
143             #   (325) + MUST NOT send ND Router Advertisement messages for the
144             #   virtual router.
145             # (330) -endif // was protected addr IPv4?
146             # (335) - MUST discard packets with a destination link-layer MAC
147             # address equal to the virtual router MAC address.
148             # (340) - MUST NOT accept packets addressed to the IPvX address(es)
149             # associated with the virtual router.
150         elif new_state == vrrp_event.VRRP_STATE_INITIALIZE:
151             if old_state is None:
152                 self.logger.info('initialized')
153             else:
154                 self.logger.info('shutdowned')
155         else:
156             raise ValueError('invalid vrrp state %s' % new_state)