Example #1
0
    def __init__(self, *args, **kwargs):
        super(VRRPInterfaceMonitorNetworkDevice, self).__init__(*args,
                                                                **kwargs)
        self.__is_active = True
        config = self.config
        if config.is_ipv6:
            family = socket.AF_INET6
            ether_type = ether.ETH_TYPE_IPV6
            mac_address = vrrp.vrrp_ipv6_src_mac_address(config.vrid)
        else:
            family = socket.AF_INET
            ether_type = ether.ETH_TYPE_IP
            mac_address = vrrp.vrrp_ipv4_src_mac_address(config.vrid)
        # socket module doesn't define IPPROTO_VRRP
        self.ip_socket = socket.socket(family, socket.SOCK_RAW,
                                       inet.IPPROTO_VRRP)

        self.packet_socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
                                           socket.htons(ether_type))
        self.packet_socket.bind((self.interface.device_name, ether_type,
                                 socket.PACKET_MULTICAST,
                                 arp.ARP_HW_TYPE_ETHERNET,
                                 addrconv.mac.text_to_bin(mac_address)))

        self.ifindex = if_nametoindex(self.interface.device_name)
Example #2
0
    def __init__(self, *args, **kwargs):
        super(VRRPInterfaceMonitorNetworkDevice, self).__init__(*args,
                                                                **kwargs)
        self.__is_active = True
        config = self.config
        if config.is_ipv6:
            family = socket.AF_INET6
            ether_type = ether.ETH_TYPE_IPV6
            mac_address = vrrp.vrrp_ipv6_src_mac_address(config.vrid)
        else:
            family = socket.AF_INET
            ether_type = ether.ETH_TYPE_IP
            mac_address = vrrp.vrrp_ipv4_src_mac_address(config.vrid)
        # socket module doesn't define IPPROTO_VRRP
        self.ip_socket = socket.socket(family, socket.SOCK_RAW,
                                       inet.IPPROTO_VRRP)

        self.packet_socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
                                           socket.htons(ether_type))
        self.packet_socket.bind((self.interface.device_name, ether_type,
                                 socket.PACKET_MULTICAST,
                                 arp.ARP_HW_TYPE_ETHERNET,
                                 addrconv.mac.text_to_bin(mac_address)))

        self.ifindex = if_nametoindex(self.interface.device_name)
Example #3
0
 def _join_multicast_membership(self, join_leave):
     config = self.config
     if config.is_ipv6:
         mac_address = vrrp.vrrp_ipv6_src_mac_address(config.vrid)
     else:
         mac_address = vrrp.vrrp_ipv4_src_mac_address(config.vrid)
     if join_leave:
         add_drop = PACKET_ADD_MEMBERSHIP
     else:
         add_drop = PACKET_DROP_MEMBERSHIP
     packet_mreq = struct.pack('IHH8s', self.ifindex,
                               PACKET_MR_MULTICAST, 6,
                               addrconv.mac.text_to_bin(mac_address))
     self.packet_socket.setsockopt(SOL_PACKET, add_drop, packet_mreq)
Example #4
0
 def _join_multicast_membership(self, join_leave):
     config = self.config
     if config.is_ipv6:
         mac_address = vrrp.vrrp_ipv6_src_mac_address(config.vrid)
     else:
         mac_address = vrrp.vrrp_ipv4_src_mac_address(config.vrid)
     if join_leave:
         add_drop = PACKET_ADD_MEMBERSHIP
     else:
         add_drop = PACKET_DROP_MEMBERSHIP
     # struct packet_mreq {
     #     int mr_ifindex;
     #     unsigned short mr_type;
     #     unsigned short mr_alen;
     #     unsigned char  mr_mr_address[8];
     # };
     packet_mreq = struct.pack('IHH8s', self.ifindex, PACKET_MR_MULTICAST,
                               6, addrconv.mac.text_to_bin(mac_address))
     self.packet_socket.setsockopt(SOL_PACKET, add_drop, packet_mreq)
Example #5
0
    def _ofp_match(self, ofproto_parser):
        is_ipv6 = vrrp.is_ipv6(self.config.ip_addresses[0])
        kwargs = {}
        kwargs['in_port'] = self.interface.port_no
        if is_ipv6:
            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:
            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:
            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 ofproto_parser.OFPMatch(**kwargs)
    def _ofp_match(self, ofproto_parser):
        is_ipv6 = vrrp.is_ipv6(self.config.ip_addresses[0])
        kwargs = {}
        kwargs['in_port'] = self.interface.port_no
        if is_ipv6:
            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:
            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:
            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 ofproto_parser.OFPMatch(**kwargs)