Exemplo n.º 1
0
    def _generate_config_bpdu(self, flags):
        src_mac = self.ofport.hw_addr
        dst_mac = bpdu.BRIDGE_GROUP_ADDRESS
        length = (bpdu.bpdu._PACK_LEN + bpdu.ConfigurationBPDUs.PACK_LEN +
                  llc.llc._PACK_LEN + llc.ControlFormatU._PACK_LEN)

        e = ethernet.ethernet(dst_mac, src_mac, length)
        l = llc.llc(llc.SAP_BPDU, llc.SAP_BPDU, llc.ControlFormatU())
        b = bpdu.ConfigurationBPDUs(
            flags=flags,
            root_priority=self.port_priority.root_id.priority,
            root_mac_address=self.port_priority.root_id.mac_addr,
            root_path_cost=self.port_priority.root_path_cost + self.path_cost,
            bridge_priority=self.bridge_id.priority,
            bridge_mac_address=self.bridge_id.mac_addr,
            port_priority=self.port_id.priority,
            port_number=self.ofport.port_no,
            message_age=self.port_times.message_age + 1,
            max_age=self.port_times.max_age,
            hello_time=self.port_times.hello_time,
            forward_delay=self.port_times.forward_delay)

        pkt = packet.Packet()
        pkt.add_protocol(e)
        pkt.add_protocol(l)
        pkt.add_protocol(b)
        pkt.serialize()

        return pkt.data
Exemplo n.º 2
0
 def __call__(self, policy, rule, port_thread, buf):
     pkt = packet.Packet(buf)
     raise Exception("Packet {} raised exception on port: {}: {}".format(
         str(pkt),
         (port_thread.port.subnet.subnet_id, port_thread.port.port_id),
         self.message,
     ))
Exemplo n.º 3
0
    def lldp_parse(data):
        pkt = packet.Packet(data)
        i = iter(pkt)
        eth_pkt = six.next(i)
        assert type(eth_pkt) == ethernet.ethernet

        lldp_pkt = six.next(i)
        if type(lldp_pkt) != lldp.lldp:
            raise LLDPPacket.LLDPUnknownFormat()

        tlv_chassis_id = lldp_pkt.tlvs[0]
        if tlv_chassis_id.subtype != lldp.ChassisID.SUB_LOCALLY_ASSIGNED:
            raise LLDPPacket.LLDPUnknownFormat(
                msg='unknown chassis id subtype %d' % tlv_chassis_id.subtype)
        chassis_id = tlv_chassis_id.chassis_id.decode('utf-8')
        if not chassis_id.startswith(LLDPPacket.CHASSIS_ID_PREFIX):
            raise LLDPPacket.LLDPUnknownFormat(
                msg='unknown chassis id format %s' % chassis_id)
        src_dpid = str_to_dpid(chassis_id[LLDPPacket.CHASSIS_ID_PREFIX_LEN:])

        tlv_port_id = lldp_pkt.tlvs[1]
        if tlv_port_id.subtype != lldp.PortID.SUB_PORT_COMPONENT:
            raise LLDPPacket.LLDPUnknownFormat(
                msg='unknown port id subtype %d' % tlv_port_id.subtype)
        port_id = tlv_port_id.port_id
        if len(port_id) != LLDPPacket.PORT_ID_SIZE:
            raise LLDPPacket.LLDPUnknownFormat(msg='unknown port id %d' %
                                               port_id)
        (src_port_no, ) = struct.unpack(LLDPPacket.PORT_ID_STR, port_id)

        return src_dpid, src_port_no
Exemplo n.º 4
0
 def __call__(self, buf):
     pkt = packet.Packet(buf)
     pkt_dhcp_protocol = pkt.get_protocol(dhcp.dhcp)
     if not pkt_dhcp_protocol:
         return False
     dhcp_type = _get_dhcp_message_type_opt(pkt_dhcp_protocol)
     return dhcp_type == self.get_dhcp_packet_type()
Exemplo n.º 5
0
    def test_serialize(self):
        pkt = packet.Packet()

        eth_pkt = ethernet.ethernet('b0:a8:6e:18:b8:08', '64:87:88:e9:cb:c8')
        pkt.add_protocol(eth_pkt)

        ip_pkt = ipv4.ipv4(src='172.28.3.1',
                           dst='172.28.3.2',
                           tos=192,
                           identification=26697,
                           proto=inet.IPPROTO_UDP)
        pkt.add_protocol(ip_pkt)

        udp_pkt = udp.udp(49152, 3784)
        pkt.add_protocol(udp_pkt)

        bfd_pkt = bfd.bfd(ver=1,
                          diag=bfd.BFD_DIAG_CTRL_DETECT_TIME_EXPIRED,
                          state=bfd.BFD_STATE_UP,
                          detect_mult=3,
                          my_discr=6,
                          your_discr=7,
                          desired_min_tx_interval=60000,
                          required_min_rx_interval=60000,
                          required_min_echo_rx_interval=0)
        pkt.add_protocol(bfd_pkt)

        eq_(len(pkt.protocols), 4)

        pkt.serialize()
        eq_(pkt.data, self.data)
Exemplo n.º 6
0
    def test_serialize(self):
        pkt = packet.Packet()

        dst = lldp.LLDP_MAC_NEAREST_BRIDGE
        src = '00:04:96:1f:a7:26'
        ethertype = ether.ETH_TYPE_LLDP
        eth_pkt = ethernet.ethernet(dst, src, ethertype)
        pkt.add_protocol(eth_pkt)

        tlv_chassis_id = lldp.ChassisID(
            subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
            chassis_id=addrconv.mac.text_to_bin(src))
        tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_INTERFACE_NAME,
                                  port_id=b'1/3')
        tlv_ttl = lldp.TTL(ttl=120)
        tlv_end = lldp.End()
        tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
        lldp_pkt = lldp.lldp(tlvs)
        pkt.add_protocol(lldp_pkt)

        eq_(len(pkt.protocols), 2)

        pkt.serialize()

        # Note: If ethernet frame is less than 60 bytes length,
        # ethernet.ethernet() appends padding to the payload.
        # So, we splits the serialized data to compare.
        data_len = len(self.data)
        pkt_data_lldp = pkt.data[:data_len]
        pkt_data_pad = pkt.data[data_len:]
        eq_(b'\x00' * (60 - data_len), pkt_data_pad)

        eq_(self.data, pkt_data_lldp)
Exemplo n.º 7
0
 def __packet_in_filter(self, ev):
     pkt = packet.Packet(ev.msg.data)
     if not packet_in_handler.pkt_in_filter.filter(pkt):
         if logging:
             LOG.debug('The packet is discarded by %s: %s', cls, pkt)
         return
     return packet_in_handler(self, ev)
Exemplo n.º 8
0
 def test_create_packet(self):
     primary_ip = '192.168.0.2'
     p0 = self.vrrpv3.create_packet(primary_ip)
     p0.serialize()
     p1 = packet.Packet(six.binary_type(p0.data))
     p1.serialize()
     eq_(p0.data, p1.data)
Exemplo n.º 9
0
    def _handle_invalid_dest(self, msg):
        """
        Handle a packet sent to the router interface (by IP). Since only ping
        and ARP are supported, everything else is responded to with a
        Destination Unreachable message.

        :param msg: Packet in message
        :type msg:  os_ken.ofproto.ofproto_v<version>_parser.OFPPacketIn
        """
        # If the destination is router interface, the unique key of router
        # interface will be set to reg7 before sending to local controller.
        # Code will hit here only when the router interface is not
        # concrete.
        if self.port_icmp_unreach_respond_rate_limit():
            LOG.warning(
                "Get more than %(rate)s packets to router port "
                "per second at table %(table)s",
                {'rate': self.conf.router_port_unreach_max_rate,
                 'table': const.L3_LOOKUP_TABLE})
            return

        # Response icmp unreachable to udp or tcp.
        pkt = packet.Packet(msg.data)
        tcp_pkt = pkt.get_protocol(tcp.tcp)
        udp_pkt = pkt.get_protocol(udp.udp)
        if tcp_pkt or udp_pkt:
            icmp_dst_unreach = icmp_error_generator.generate(
                icmp.ICMP_DEST_UNREACH, icmp.ICMP_PORT_UNREACH_CODE,
                msg.data, pkt=pkt)
            unique_key = msg.match.get('reg6')
            self.dispatch_packet(icmp_dst_unreach, unique_key)
Exemplo n.º 10
0
    def _create_test_dhcp6_packet(self, zero_time=False):
        ret_pkt = packet.Packet()
        ret_pkt.add_protocol(
            ethernet.ethernet(
                ethertype=ether_types.ETH_TYPE_IPV6,
                dst='33:33:00:01:00:02',
                src=self.port_info['mac_address']))
        ret_pkt.add_protocol(
            ipv6.ipv6(
                src='fe80::f816:3eff:fe60:714b',
                dst='ff02::1:2',
                nxt=inet.IPPROTO_UDP))
        ret_pkt.add_protocol(
            udp.udp(
                src_port=constants.DHCPV6_RESPONSE_PORT,
                dst_port=constants.DHCPV6_CLIENT_PORT))

        options = [dhcp6.option(
            code=1,
            data=b"\x00\x01\x00\x01",
            length=4)]
        if zero_time:
            options.append(dhcp6.option(
                code=3,
                data=b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
                length=12))
        else:
            options.append(dhcp6.option(
                code=3,
                data=b"\x01\x02\x03\x04\x05\x06\x07\x08\x0a\x0b\x0c\x0d",
                length=12))
        ret_pkt.add_protocol(dhcp6.dhcp6(
            dhcp6.DHCPV6_REQUEST, dhcp6.options(option_list=options)))
        return ret_pkt
Exemplo n.º 11
0
 def _create_test_dhcp_request_packet(self):
     option_list = []
     bin_server = addrconv.ipv4.text_to_bin('192.168.1.1')
     option_list.append(
         dhcp.option(tag=dhcp.DHCP_SERVER_IDENTIFIER_OPT, value=bin_server))
     option_list.append(
         dhcp.option(tag=dhcp.DHCP_MESSAGE_TYPE_OPT, value=b'\x03'))
     options = dhcp.options(option_list=option_list)
     ret_pkt = packet.Packet()
     ret_pkt.add_protocol(
         ethernet.ethernet(dst="ff:ff:ff:ff:ff:ff",
                           src=self.port_info['mac_address']))
     ret_pkt.add_protocol(
         ipv4.ipv4(dst="255.255.255.255",
                   src="0.0.0.0",
                   proto=inet.IPPROTO_UDP))
     ret_pkt.add_protocol(
         udp.udp(src_port=constants.DHCP_CLIENT_PORT,
                 dst_port=constants.DHCP_RESPONSE_PORT))
     ret_pkt.add_protocol(
         dhcp.dhcp(op=dhcp.DHCP_BOOT_REQUEST,
                   chaddr=self.port_info['mac_address'],
                   siaddr='0.0.0.0',
                   xid=3454038351,
                   options=options))
     return ret_pkt
Exemplo n.º 12
0
    def test_parse(self):
        buf = self.data
        pkt = packet.Packet(buf)
        i = iter(pkt)

        eq_(type(next(i)), ethernet.ethernet)
        eq_(type(next(i)), lldp.lldp)
Exemplo n.º 13
0
    def lldp_packet(dpid, port_no, dl_addr, ttl):
        pkt = packet.Packet()

        dst = lldp.LLDP_MAC_NEAREST_BRIDGE
        src = dl_addr
        ethertype = ETH_TYPE_LLDP
        eth_pkt = ethernet.ethernet(dst, src, ethertype)
        pkt.add_protocol(eth_pkt)

        tlv_chassis_id = lldp.ChassisID(
            subtype=lldp.ChassisID.SUB_LOCALLY_ASSIGNED,
            chassis_id=(LLDPPacket.CHASSIS_ID_FMT %
                        dpid_to_str(dpid)).encode('ascii'))

        tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_PORT_COMPONENT,
                                  port_id=struct.pack(LLDPPacket.PORT_ID_STR,
                                                      port_no))

        tlv_ttl = lldp.TTL(ttl=ttl)
        tlv_end = lldp.End()

        tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
        lldp_pkt = lldp.lldp(tlvs)
        pkt.add_protocol(lldp_pkt)

        pkt.serialize()
        return pkt.data
Exemplo n.º 14
0
 def __call__(self, buf):
     pkt = packet.Packet(buf)
     vlan_pkt = pkt.get_protocol(vlan.vlan)
     if not vlan_pkt:
         return False
     if self.tag and self.tag != vlan_pkt.vid:
         return False
     return True
Exemplo n.º 15
0
    def _build_itag(self):
        b_src_mac = '00:07:0d:af:f4:54'
        b_dst_mac = '00:00:00:00:00:00'
        b_ethertype = ether.ETH_TYPE_8021AD
        e1 = ethernet.ethernet(b_dst_mac, b_src_mac, b_ethertype)

        b_pcp = 0
        b_cfi = 0
        b_vid = 32
        b_ethertype = ether.ETH_TYPE_8021Q
        bt = vlan.svlan(b_pcp, b_cfi, b_vid, b_ethertype)

        c_src_mac = '11:11:11:11:11:11'
        c_dst_mac = 'aa:aa:aa:aa:aa:aa'
        c_ethertype = ether.ETH_TYPE_8021AD
        e2 = ethernet.ethernet(c_dst_mac, c_src_mac, c_ethertype)

        s_pcp = 0
        s_cfi = 0
        s_vid = 32
        s_ethertype = ether.ETH_TYPE_8021Q
        st = vlan.svlan(s_pcp, s_cfi, s_vid, s_ethertype)

        c_pcp = 0
        c_cfi = 0
        c_vid = 32
        c_ethertype = ether.ETH_TYPE_IP
        ct = vlan.vlan(c_pcp, c_cfi, c_vid, c_ethertype)

        version = 4
        header_length = 20
        tos = 0
        total_length = 24
        identification = 0x8a5d
        flags = 0
        offset = 1480
        ttl = 64
        proto = inet.IPPROTO_ICMP
        csum = 0xa7f2
        src = '131.151.32.21'
        dst = '131.151.32.129'
        option = b'TEST'
        ip = ipv4.ipv4(version, header_length, tos, total_length,
                       identification, flags, offset, ttl, proto, csum, src,
                       dst, option)

        p = packet.Packet()

        p.add_protocol(e1)
        p.add_protocol(bt)
        p.add_protocol(self.it)
        p.add_protocol(e2)
        p.add_protocol(st)
        p.add_protocol(ct)
        p.add_protocol(ip)
        p.serialize()

        return p
Exemplo n.º 16
0
    def send_arp_request(self, src_mac, src_ip, dst_ip, port_key):
        arp_request_pkt = packet.Packet()
        arp_request_pkt.add_protocol(
            ethernet.ethernet(ethertype=ether.ETH_TYPE_ARP, src=src_mac))

        arp_request_pkt.add_protocol(
            arp.arp(src_mac=src_mac, src_ip=src_ip, dst_ip=dst_ip))

        self.dispatch_packet(arp_request_pkt, port_key)
Exemplo n.º 17
0
    def test_parse(self):
        buf = self.data
        pkt = packet.Packet(buf)
        i = iter(pkt)

        eq_(type(next(i)), ethernet.ethernet)
        eq_(type(next(i)), ipv4.ipv4)
        eq_(type(next(i)), udp.udp)
        eq_(type(bfd.bfd.parser(next(i))[0]), bfd.bfd)
Exemplo n.º 18
0
 def __call__(self, buf):
     pkt = packet.Packet(buf)
     if self.ethertype == n_const.IPv4:
         pkt_icmp_protocol = pkt.get_protocol(icmp.icmp)
     else:
         pkt_icmp_protocol = pkt.get_protocol(icmpv6.icmpv6)
     if not pkt_icmp_protocol:
         return False
     return self.filter_icmp(pkt, pkt_icmp_protocol)
Exemplo n.º 19
0
    def bfd_packet(src_mac,
                   dst_mac,
                   src_ip,
                   dst_ip,
                   ipv4_id,
                   src_port,
                   dst_port,
                   diag=0,
                   state=0,
                   flags=0,
                   detect_mult=0,
                   my_discr=0,
                   your_discr=0,
                   desired_min_tx_interval=0,
                   required_min_rx_interval=0,
                   required_min_echo_rx_interval=0,
                   auth_cls=None):
        """
        Generate BFD packet with Ethernet/IPv4/UDP encapsulated.
        """
        # Generate ethernet header first.
        pkt = packet.Packet()
        eth_pkt = ethernet.ethernet(dst_mac, src_mac, ETH_TYPE_IP)
        pkt.add_protocol(eth_pkt)

        # IPv4 encapsulation
        # set ToS to 192 (Network control/CS6)
        # set TTL to 255 (RFC5881 Section 5.)
        ipv4_pkt = ipv4.ipv4(proto=inet.IPPROTO_UDP,
                             src=src_ip,
                             dst=dst_ip,
                             tos=192,
                             identification=ipv4_id,
                             ttl=255)
        pkt.add_protocol(ipv4_pkt)

        # UDP encapsulation
        udp_pkt = udp.udp(src_port=src_port, dst_port=dst_port)
        pkt.add_protocol(udp_pkt)

        # BFD payload
        bfd_pkt = bfd.bfd(
            ver=1,
            diag=diag,
            state=state,
            flags=flags,
            detect_mult=detect_mult,
            my_discr=my_discr,
            your_discr=your_discr,
            desired_min_tx_interval=desired_min_tx_interval,
            required_min_rx_interval=required_min_rx_interval,
            required_min_echo_rx_interval=required_min_echo_rx_interval,
            auth_cls=auth_cls)
        pkt.add_protocol(bfd_pkt)

        pkt.serialize()
        return pkt.data
Exemplo n.º 20
0
 def packet_in_handler(self, event):
     if event.msg.match['in_port'] != FAKEPORT:
         return
     pkt = packet.Packet(event.msg.data)
     eth_protocol = pkt.get_protocol(ethernet.ethernet)
     vlan_protocol = pkt.get_protocol(vlan.vlan)
     ipv6_protocol = pkt.get_protocol(ipv6.ipv6)
     icmpv6_protocol = pkt.get_protocol(icmpv6.icmpv6)
     if not (eth_protocol and vlan_protocol and ipv6_protocol
             and icmpv6_protocol):
         return
     if icmpv6_protocol.type_ != icmpv6.ND_NEIGHBOR_SOLICIT:
         return
     if int(ipaddress.ip_address(ipv6_protocol.src)) == 0:
         return
     src_ip = ipaddress.ip_address(icmpv6_protocol.data.dst)
     if src_ip.is_reserved:
         return
     eth_dst = eth_protocol.src
     dst_ip = ipv6_protocol.src
     eth_src = FAKECLIENTMAC
     vid = vlan_protocol.vid
     reply = packet.Packet()
     for protocol in (ethernet.ethernet(eth_dst, eth_src,
                                        ether.ETH_TYPE_8021Q),
                      vlan.vlan(vid=vid, ethertype=ether.ETH_TYPE_IPV6),
                      ipv6.ipv6(src=src_ip,
                                dst=dst_ip,
                                nxt=socket.IPPROTO_ICMPV6,
                                hop_limit=255),
                      icmpv6.icmpv6(
                          type_=icmpv6.ND_NEIGHBOR_ADVERT,
                          data=icmpv6.nd_neighbor(
                              dst=src_ip,
                              option=icmpv6.nd_option_tla(hw_src=eth_src),
                              res=7))):
         reply.add_protocol(protocol)
     reply.serialize()
     out = parser.OFPPacketOut(datapath=event.msg.datapath,
                               buffer_id=ofp.OFP_NO_BUFFER,
                               in_port=ofp.OFPP_CONTROLLER,
                               actions=[parser.OFPActionOutput(FAKEPORT)],
                               data=reply.data)
     self.send_mods(event.msg.datapath, [out])
Exemplo n.º 21
0
    def _packet_in_handler(self, ev):
        # If you hit this you might want to increase
        # the "miss_send_length" of your switch
        if ev.msg.msg_len < ev.msg.total_len:
            self.logger.debug("packet truncated: only %s of %s bytes",
                              ev.msg.msg_len, ev.msg.total_len)
        msg = ev.msg
        datapath = msg.datapath
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser
        in_port = msg.match['in_port']

        pkt = packet.Packet(msg.data)
        eth = pkt.get_protocols(ethernet.ethernet)[0]

        if eth.ethertype == ether_types.ETH_TYPE_LLDP:
            # ignore lldp packet
            return
        dst = eth.dst
        src = eth.src

        dpid = datapath.id
        self.mac_to_port.setdefault(dpid, {})

        self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port)

        # learn a mac address to avoid FLOOD next time.
        self.mac_to_port[dpid][src] = in_port

        if dst in self.mac_to_port[dpid]:
            out_port = self.mac_to_port[dpid][dst]
        else:
            out_port = ofproto.OFPP_FLOOD

        actions = [parser.OFPActionOutput(out_port)]

        # install a flow to avoid packet_in next time
        if out_port != ofproto.OFPP_FLOOD:
            match = parser.OFPMatch(in_port=in_port, eth_dst=dst, eth_src=src)
            # verify if we have a valid buffer_id, if yes avoid to send both
            # flow_mod & packet_out
            if msg.buffer_id != ofproto.OFP_NO_BUFFER:
                self.add_flow(datapath, 1, match, actions, msg.buffer_id)
                return
            else:
                self.add_flow(datapath, 1, match, actions)
        data = None
        if msg.buffer_id == ofproto.OFP_NO_BUFFER:
            data = msg.data

        out = parser.OFPPacketOut(datapath=datapath,
                                  buffer_id=msg.buffer_id,
                                  in_port=in_port,
                                  actions=actions,
                                  data=data)
        datapath.send_msg(out)
Exemplo n.º 22
0
    def __call__(self, buf):
        pkt = packet.Packet(buf)
        pkt_arp_protocol = pkt.get_protocol(arp.arp)
        if (not pkt_arp_protocol) or (pkt_arp_protocol.opcode !=
                                      arp.ARP_REQUEST):
            return False
        if self.arp_tpa is not None:
            return pkt_arp_protocol.dst_ip == self.arp_tpa

        return True
Exemplo n.º 23
0
 def packet_in_handler(self, evt):
     """PacketIn event handler. when the received packet was LACP,
     proceed it. otherwise, send a event."""
     req_pkt = packet.Packet(evt.msg.data)
     if slow.lacp in req_pkt:
         (req_lacp, ) = req_pkt.get_protocols(slow.lacp)
         (req_eth, ) = req_pkt.get_protocols(ethernet.ethernet)
         self._do_lacp(req_lacp, req_eth.src, evt.msg)
     else:
         self.send_event_to_observers(EventPacketIn(evt.msg))
Exemplo n.º 24
0
 def test_create_packet(self):
     primary_ip = '2001:db8:2000::3'
     p0 = self.vrrpv3.create_packet(primary_ip)
     p0.serialize()
     print(len(p0.data), p0.data)
     p1 = packet.Packet(six.binary_type(p0.data))
     p1.serialize()
     print(len(p0.data), p0.data)
     print(len(p1.data), p1.data)
     eq_(p0.data, p1.data)
Exemplo n.º 25
0
    def _packet_in_handler(self, event):
        msg = event.msg
        datapath = msg.datapath
        ofproto = datapath.ofproto

        if msg.reason != ofproto.OFPR_ACTION:
            LOG.debug("DHCP Controller only handle the packet which "
                      "match the rules and the action is send to the "
                      "controller.")
            return

        of_in_port = msg.match['in_port']
        LOG.info("DHCP Controller packet in OF port: %s", of_in_port)
        pkt = packet.Packet(data=msg.data)

        LOG.debug(
            'DHCP Controller packet received: '
            'buffer_id=%x total_len=%d reason=ACTION '
            'table_id=%d cookie=%d match=%s pkt=%s', msg.buffer_id,
            msg.total_len, msg.table_id, msg.cookie, msg.match, pkt)

        if self.version == IPV4_STR:
            ip_protocol = ipv4.ipv4
            dhcp_protocol = dhcp.dhcp
        else:
            ip_protocol = ipv6.ipv6
            dhcp_protocol = dhcp6.dhcp6
        ip_header = pkt.get_protocol(ip_protocol)
        if not ip_header:
            LOG.warning(
                "DHCP Controller received packet "
                "is not an IP%s packet", self.version)
            return

        dhcp_pkt = pkt.get_protocol(dhcp_protocol)
        if not dhcp_pkt:
            LOG.warning(
                "DHCP Controller received packet "
                "is not a DHCP%s packet", self.version)
            return

        eth_pkt = pkt.get_protocol(ethernet.ethernet)
        port_id = self.get_port_id_from_br(of_in_port, eth_pkt.src)
        LOG.debug(
            "DHCP Controller received DHCP%s packet's neutron port "
            "id: %s", self.version, port_id)

        port_info = self.ext_api.get_port_info(port_id)
        LOG.debug(
            "DHCP Controller received DHCP%s packet's neutron port "
            "info: %s", self.version, port_info)
        if not port_info:
            return

        self.handle_dhcp(datapath, of_in_port, pkt, port_info)
Exemplo n.º 26
0
 def _create_response(self, datapath, port, req):
     """create a packet including LACP."""
     src = datapath.ports[port].hw_addr
     res_ether = ethernet.ethernet(slow.SLOW_PROTOCOL_MULTICAST, src,
                                   ether.ETH_TYPE_SLOW)
     res_lacp = self._create_lacp(datapath, port, req)
     res_pkt = packet.Packet()
     res_pkt.add_protocol(res_ether)
     res_pkt.add_protocol(res_lacp)
     res_pkt.serialize()
     return res_pkt
Exemplo n.º 27
0
    def __call__(self, buf):
        pkt = packet.Packet(buf)
        pkt_udp = pkt.get_protocol(udp.udp)

        if pkt_udp is None:
            return False

        if self._dst_port is not None and pkt_udp.dst_port != self._dst_port:
            return False

        return True
Exemplo n.º 28
0
    def __call__(self, buf):
        pkt = packet.Packet(buf)
        pkt_mpls = pkt.get_protocol(mpls.mpls)

        if pkt_mpls is None:
            return False

        if self._label is not None and pkt_mpls.label != self._label:
            return False

        return True
Exemplo n.º 29
0
    def _do_leave(self, leave, in_port, msg):
        """the process when the snooper received a LEAVE message."""
        datapath = msg.datapath
        dpid = datapath.id
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        # check whether the querier port has been specified.
        if not self._to_querier.get(dpid):
            self.logger.info("no querier exists.")
            return

        # save this LEAVE message and reset the condition of the port
        # that received this message.
        self._to_hosts.setdefault(dpid, {})
        self._to_hosts[dpid].setdefault(leave.address, {
            'replied': False,
            'leave': None,
            'ports': {}
        })
        self._to_hosts[dpid][leave.address]['leave'] = msg
        self._to_hosts[dpid][leave.address]['ports'][in_port] = {
            'out': False,
            'in': False
        }

        # create a specific query.
        timeout = igmp.LAST_MEMBER_QUERY_INTERVAL
        res_igmp = igmp.igmp(msgtype=igmp.IGMP_TYPE_QUERY,
                             maxresp=timeout * 10,
                             csum=0,
                             address=leave.address)
        res_ipv4 = ipv4.ipv4(total_length=len(ipv4.ipv4()) + len(res_igmp),
                             proto=inet.IPPROTO_IGMP,
                             ttl=1,
                             src=self._to_querier[dpid]['ip'],
                             dst=igmp.MULTICAST_IP_ALL_HOST)
        res_ether = ethernet.ethernet(dst=igmp.MULTICAST_MAC_ALL_HOST,
                                      src=self._to_querier[dpid]['mac'],
                                      ethertype=ether.ETH_TYPE_IP)
        res_pkt = packet.Packet()
        res_pkt.add_protocol(res_ether)
        res_pkt.add_protocol(res_ipv4)
        res_pkt.add_protocol(res_igmp)
        res_pkt.serialize()

        # send a specific query to the host that sent this message.
        actions = [parser.OFPActionOutput(ofproto.OFPP_IN_PORT)]
        self._do_packet_out(datapath, res_pkt.data, in_port, actions)

        # wait for REPORT messages.
        hub.spawn(self._do_timeout_for_leave, timeout, datapath, leave.address,
                  in_port)
Exemplo n.º 30
0
 def packet_in_handler(self, ev):
     msg = ev.msg
     cookie_id = msg.cookie
     pkt = packet.Packet(msg.data)
     try:
         cookie_entry = self._get_cookie_by_id(cookie_id)
         LOG.info(
             "action=%s project_id=%s log_resource_ids=%s vm_port=%s "
             "pkt=%s", cookie_entry.action, cookie_entry.project,
             list(cookie_entry.log_object_refs), cookie_entry.port, pkt)
     except log_exc.CookieNotFound:
         LOG.warning("Unknown cookie=%s packet_in pkt=%s", cookie_id, pkt)