Signed-off-by: YAMAMOTO Takashi <[email protected]>
---
 ryu/services/vrrp/event.py         | 30 +++++++++++++++++------------
 ryu/services/vrrp/monitor.py       | 39 +++++++++++++++++++++-----------------
 ryu/services/vrrp/router.py        |  6 ++++--
 ryu/services/vrrp/sample_router.py | 34 ++++++++++++++++-----------------
 4 files changed, 61 insertions(+), 48 deletions(-)

diff --git a/ryu/services/vrrp/event.py b/ryu/services/vrrp/event.py
index 33b9896..49d3692 100644
--- a/ryu/services/vrrp/event.py
+++ b/ryu/services/vrrp/event.py
@@ -18,12 +18,11 @@
 Events for VRRP
 """
 
-import netaddr
-
 from ryu.controller import event
 from ryu.lib import dpid as dpid_lib
 from ryu.lib import mac as mac_lib
 from ryu.lib.packet import vrrp
+from ryu.lib import addrconv
 
 
 # When an instance is created, state transition is None -> Initialize
@@ -55,7 +54,9 @@ class VRRPInterfaceBase(object):
                 self.vlan_id == other.vlan_id)
 
     def __hash__(self):
-        return hash((self.mac_address, self.primary_ip_address, self.vlan_id))
+        return hash((
+            addrconv.mac.text_to_bin(self.mac_address),
+            vrrp.ip_text_to_bin(self.primary_ip_address), self.vlan_id))
 
 
 class VRRPInterfaceNetworkDevice(VRRPInterfaceBase):
@@ -68,8 +69,8 @@ class VRRPInterfaceNetworkDevice(VRRPInterfaceBase):
     def __str__(self):
         return '%s<%s, %s, %s, %s>' % (
             self.__class__.__name__,
-            str(mac_lib.haddr_to_str(self.mac_address)),
-            str(netaddr.IPAddress(self.primary_ip_address)), self.vlan_id,
+            self.mac_address,
+            self.primary_ip_address, self.vlan_id,
             self.device_name)
 
     def __eq__(self, other):
@@ -77,8 +78,10 @@ class VRRPInterfaceNetworkDevice(VRRPInterfaceBase):
                 self.device_name == other.device_name)
 
     def __hash__(self):
-        return hash((self.mac_address, self.primary_ip_address, self.vlan_id,
-                     self.device_name))
+        return hash((
+            addrconv.mac.text_to_bin(self.mac_address),
+            vrrp.ip_text_to_bin(self.primary_ip_address), self.vlan_id,
+            self.device_name))
 
 
 class VRRPInterfaceOpenFlow(VRRPInterfaceBase):
@@ -92,8 +95,8 @@ class VRRPInterfaceOpenFlow(VRRPInterfaceBase):
     def __str__(self):
         return '%s<%s, %s, %s, %s, %d>' % (
             self.__class__.__name__,
-            str(mac_lib.haddr_to_str(self.mac_address)),
-            str(netaddr.IPAddress(self.primary_ip_address)), self.vlan_id,
+            self.mac_address,
+            self.primary_ip_address, self.vlan_id,
             dpid_lib.dpid_to_str(self.dpid), self.port_no)
 
     def __eq__(self, other):
@@ -101,8 +104,10 @@ class VRRPInterfaceOpenFlow(VRRPInterfaceBase):
                 self.dpid == other.dpid and self.port_no == other.port_no)
 
     def __hash__(self):
-        return hash((self.mac_address, self.primary_ip_address, self.vlan_id,
-                     self.dpid, self.port_no))
+        return hash((
+            addrconv.mac.text_to_bin(self.mac_address),
+            vrrp.ip_text_to_bin(self.primary_ip_address), self.vlan_id,
+            self.dpid, self.port_no))
 
 
 class VRRPConfig(object):
@@ -145,7 +150,8 @@ class VRRPConfig(object):
                 self.is_ipv6 == other.is_ipv6)
 
     def __hash__(self):
-        hash((self.version, self.vrid, self.priority, self.ip_addresses,
+        hash((self.version, self.vrid, self.priority,
+              map(vrrp.ip_text_to_bin, self.ip_addresses),
               self.advertisement_interval, self.preempt_mode,
               self.preempt_delay, self.accept_mode, self.is_ipv6))
 
diff --git a/ryu/services/vrrp/monitor.py b/ryu/services/vrrp/monitor.py
index cf6d6f1..b58b64d 100644
--- a/ryu/services/vrrp/monitor.py
+++ b/ryu/services/vrrp/monitor.py
@@ -30,6 +30,7 @@ from ryu.controller import handler
 from ryu.controller import ofp_event
 from ryu.lib import dpid as dpid_lib
 from ryu.lib import hub
+from ryu.lib import addrconv
 from ryu.lib.packet import arp
 from ryu.lib.packet import packet
 from ryu.lib.packet import vlan
@@ -239,7 +240,8 @@ class 
VRRPInterfaceMonitorNetworkDevice(VRRPInterfaceMonitor):
                                            socket.htons(ether_type))
         self.packet_socket.bind((self.interface.device_name, ether_type,
                                  socket.PACKET_MULTICAST,
-                                 arp.ARP_HW_TYPE_ETHERNET, mac_address))
+                                 arp.ARP_HW_TYPE_ETHERNET,
+                                 addrconv.mac.text_to_bin(mac_address)))
 
         self.ifindex = if_nametoindex(self.interface.device_name)
 
@@ -275,7 +277,8 @@ class 
VRRPInterfaceMonitorNetworkDevice(VRRPInterfaceMonitor):
         else:
             add_drop = PACKET_DROP_MEMBERSHIP
         packet_mreq = struct.pack('IHH8s', self.ifindex,
-                                  PACKET_MR_MULTICAST, 6, mac_address)
+                                  PACKET_MR_MULTICAST, 6,
+                                  addrconv.mac.text_to_bin(mac_address))
         self.packet_socket.setsockopt(SOL_PACKET, add_drop, packet_mreq)
 
     def _join_vrrp_group(self, join_leave):
@@ -306,7 +309,7 @@ class 
VRRPInterfaceMonitorNetworkDevice(VRRPInterfaceMonitor):
             sockaddr = struct.pack('H',  socket.AF_INET6)
             sockaddr += struct.pack('!H', 0)
             sockaddr += struct.pack('!I', 0)
-            sockaddr += vrrp.VRRP_IPV6_DST_ADDRESS
+            sockaddr += addrconv.ipv6.text_to_bin(vrrp.VRRP_IPV6_DST_ADDRESS)
             sockaddr += struct.pack('I', 0)
         else:
             # #define __SOCK_SIZE__   16 /* sizeof(struct sockaddr) */
@@ -324,7 +327,7 @@ class 
VRRPInterfaceMonitorNetworkDevice(VRRPInterfaceMonitor):
             family = socket.IPPROTO_IP
             sockaddr = struct.pack('H', socket.AF_INET)
             sockaddr += struct.pack('!H', 0)
-            sockaddr += struct.pack('!I', vrrp.VRRP_IPV4_DST_ADDRESS)
+            sockaddr += addrconv.ipv4.text_to_bin(vrrp.VRRP_IPV4_DST_ADDRESS)
 
         sockaddr += '\x00' * (SS_MAXSIZE - len(sockaddr))
         group_req += sockaddr
@@ -422,27 +425,29 @@ class VRRPInterfaceMonitorOpenFlow(VRRPInterfaceMonitor):
         utils.dp_packet_out(dp, self.interface.port_no, ev.data)
 
     def _ofp_match(self, ofproto_parser):
-        match = ofproto_parser.OFPMatch()
-        match.set_in_port(self.interface.port_no)
         is_ipv6 = vrrp.is_ipv6(self.config.ip_addresses[0])
+        kwargs = {}
+        kwargs['in_port'] = self.interface.port_no
         if is_ipv6:
-            match.set_dl_dst(vrrp.VRRP_IPV6_DST_MAC_ADDRESS)
-            match.set_dl_src(vrrp.vrrp_ipv6_src_mac_address(self.config.vrid))
-            match.set_dl_type(ether.ETH_TYPE_IPV6)
-            match.set_ipv6_dst(vrrp.VRRP_IPV6_DST_ADDRESS)
+            kwargs['eth_dst'] = vrrp.VRRP_IPV6_DST_MAC_ADDRESS
+            kwargs['eth_src'] = \
+                vrrp.vrrp_ipv6_src_mac_address(self.config.vrid)
+            kwargs['eth_type'] = ether.ETH_TYPE_IPV6
+            kwargs['ipv6_dst'] = vrrp.VRRP_IPV6_DST_ADDRESS
         else:
-            match.set_dl_dst(vrrp.VRRP_IPV4_DST_MAC_ADDRESS)
-            match.set_dl_src(vrrp.vrrp_ipv4_src_mac_address(self.config.vrid))
-            match.set_dl_type(ether.ETH_TYPE_IP)
-            match.set_ipv4_dst(vrrp.VRRP_IPV4_DST_ADDRESS)
+            kwargs['eth_dst'] = vrrp.VRRP_IPV4_DST_MAC_ADDRESS
+            kwargs['eth_src'] = \
+                vrrp.vrrp_ipv4_src_mac_address(self.config.vrid)
+            kwargs['eth_type'] = ether.ETH_TYPE_IP
+            kwargs['ipv4_dst'] = vrrp.VRRP_IPV4_DST_ADDRESS
 
         if self.interface.vlan_id is not None:
-            match.set_vlan_vid(self.interface.vlan_id)
-        match.set_ip_proto(inet.IPPROTO_VRRP)
+            kwargs['vlan_vid'] = self.interface.vlan_id
+        kwargs['ip_proto'] = inet.IPPROTO_VRRP
         # OF1.2 doesn't support TTL match.
         # It needs to be checked by packet in handler
 
-        return match
+        return ofproto_parser.OFPMatch(**kwargs)
 
     def _initialize(self):
         dp = self._get_dp()
diff --git a/ryu/services/vrrp/router.py b/ryu/services/vrrp/router.py
index 4a7ae80..cc52f5c 100644
--- a/ryu/services/vrrp/router.py
+++ b/ryu/services/vrrp/router.py
@@ -322,7 +322,8 @@ class VRRPV2StateMaster(VRRPState):
             params = vrrp_router.params
             if (config.priority < vrrp_.priority or
                 (config.priority == vrrp_.priority and
-                 vrrp_router.interface.primary_ip_address < ip.src)):
+                 vrrp.ip_address_lt(vrrp_router.interface.primary_ip_address,
+                                    ip.src))):
                 vrrp_router.adver_timer.cancel()
 
                 vrrp_router.state_change(vrrp_event.VRRP_STATE_BACKUP)
@@ -524,7 +525,8 @@ class VRRPV3StateMaster(VRRPState):
             params = vrrp_router.params
             if (config.priority < vrrp_.priority or
                 (config.priority == vrrp_.priority and
-                 vrrp_router.interface.primary_ip_address < ip.src)):
+                 vrrp.ip_address_lt(vrrp_router.interface.primary_ip_address,
+                                    ip.src))):
                 vrrp_router.adver_timer.cancel()
                 params.master_adver_interval = vrrp_.max_adver_int_in_sec
 
diff --git a/ryu/services/vrrp/sample_router.py 
b/ryu/services/vrrp/sample_router.py
index f562712..9ba73ab 100644
--- a/ryu/services/vrrp/sample_router.py
+++ b/ryu/services/vrrp/sample_router.py
@@ -205,9 +205,10 @@ class RouterIPV4(RouterBase):
     def _garp_packet(self, ip_address):
         # prepare garp packet
         src_mac = vrrp.vrrp_ipv4_src_mac_address(self.config.vrid)
-        e = ethernet.ethernet(mac_lib.BROADCAST, src_mac, ether.ETH_TYPE_ARP)
+        e = ethernet.ethernet(mac_lib.BROADCAST_STR, src_mac,
+                              ether.ETH_TYPE_ARP)
         a = arp.arp_ip(arp.ARP_REQUEST, src_mac, ip_address,
-                       mac_lib.DONTCARE, ip_address)
+                       mac_lib.DONTCARE_STR, ip_address)
 
         p = packet.Packet()
         p.add_protocol(e)
@@ -254,7 +255,7 @@ class RouterIPV4(RouterBase):
         p = packet.Packet(data)
         for proto in p.protocols:
             if isinstance(proto, ethernet.ethernet):
-                if proto.dst not in (mac_lib.BROADCAST, dst_mac):
+                if proto.dst not in (mac_lib.BROADCAST_STR, dst_mac):
                     return None
                 ethertype = proto.ethertype
                 if not ((self.interface.vlan_id is None and
@@ -459,12 +460,12 @@ class RouterIPV4OpenFlow(RouterIPV4):
         self._arp_process(msg.data)
 
     def _drop_match(self, dp):
-        match = dp.ofproto_parser.OFPMatch()
-        match.set_in_port(self.interface.port_no)
-        match.set_dl_dst(vrrp.vrrp_ipv4_src_mac_address(self.config.vrid))
+        kwargs = {}
+        kwargs['in_port'] = self.interface.port_no
+        kwargs['eth_dst'] = vrrp.vrrp_ipv4_src_mac_address(self.config.vrid)
         if self.interface.vlan_id is not None:
-            match.set_vlan_vid(self.interface.vlan_id)
-        return match
+            kwargs['vlan_vid'] = self.interface.vlan_id
+        return dp.ofproto_parser.OFPMatch(**kwargs)
 
     def _install_drop_rule(self, dp):
         match = self._drop_match(dp)
@@ -477,16 +478,15 @@ class RouterIPV4OpenFlow(RouterIPV4):
                           self._DROP_PRIORITY, match, [])
 
     def _arp_match(self, dp):
-        match = dp.ofproto_parser.OFPMatch()
-        match.set_in_port(self.interface.port_no)
-        match.set_dl_dst(mac_lib.BROADCAST)
-        match.set_dl_type(ether.ETH_TYPE_ARP)
+        kwargs = {}
+        kwargs['in_port'] = self.interface.port_no
+        kwargs['eth_dst'] = mac_lib.BROADCAST_STR
+        kwargs['eth_type'] = ether.ETH_TYPE_ARP
         if self.interface.vlan_id is not None:
-            match.set_vlan_vid(self.interface.vlan_id)
-        match.set_arp_opcode(arp.ARP_REQUEST)
-        match.set_arp_tpa(self,
-                          vrrp.vrrp_ipv4_src_mac_address(self.config.vrid))
-        return match
+            kwargs['vlan_vid'] = self.interface.vlan_id
+        kwargs['arp_op'] = arp.ARP_REQUEST
+        kwargs['arp_tpa'] = vrrp.vrrp_ipv4_src_mac_address(self.config.vrid)
+        return dp.ofproto_parser.OFPMatch(**kwargs)
 
     def _install_arp_rule(self, dp):
         ofproto = dp.ofproto
-- 
1.8.1.5


------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to