Ejemplo n.º 1
0
def ethertype_filters(msg):
    """
        Filter PacketIn and PacketOut messages based on Ethertype
        Sanitizer filter (-F), entry "filters", "ethertype"
        Args:
            msg: class OFMessage
        Returns:
            False: Don't filter packet
            True: Filter it (don't print)
    """
    if msg.ofp.header.message_type in [10, 13]:
        try:
            filters = Sanitizer().filters['ethertypes']
        except KeyError:
            return False

        if not len(filters):
            # No filters
            return False

        # Go to payload
        try:
            if is_protocol(msg.ofp.data, lldp=True) and filters['lldp']:
                return True
            if is_protocol(msg.ofp.data, oess=True) and filters['fvd']:
                return True
            if is_protocol(msg.ofp.data, arp=True) and filters['arp']:
                return True
        except KeyError:
            pass

        # Other Ethertypes listed as hex
        for protocol in filters['others']:
            try:
                if is_protocol(msg.ofp.data) == int(protocol, 16):
                    return True
            except ValueError:
                pass

    return False
Ejemplo n.º 2
0
    def process_packet(self, pkt):
        """
            Method called by ofp_sniffer to process the IP+OF packet
            We are only interested in Packet_Ins because these are
            messages coming from the switch, which means, the end of
            the OESS FV cycle:
                (OESS -> packetOut -> dpid -> packetIn -> OESS)

            Args:
                pkt: Packet class
        """
        for msg in pkt.ofmsgs:
            if msg.ofp.header.message_type in [OFP_PACKET_IN]:
                fvd = is_protocol(msg.ofp.data, oess=True)
                if fvd is not False:
                    self.add_link(fvd, pkt.l1.time)
Ejemplo n.º 3
0
    def process_packet(self, pkt):
        """
            Go through all OFMessages in Pkt.
            IF FeaturesReply or PacketOut, get the DPID

            pkt: packet class
        """

        if not self.active:
            return

        for msg in pkt.ofmsgs:
            if msg.ofp.header.message_type.value == 6:
                ip_addr = pkt.l3.s_addr
                port = pkt.l4.source_port
                self.add_dpid_to_proxy_db(ip_addr, port,
                                          msg.ofp.datapath_id.value)

            elif msg.ofp.header.message_type.value == 13:
                ip_addr = pkt.l3.d_addr
                port = pkt.l4.dest_port
                lldp = is_protocol(msg.ofp.data, lldp=True)
                if isinstance(lldp, LLDP):
                    self.add_dpid_to_proxy_db(ip_addr, port, lldp.c_id)
Ejemplo n.º 4
0
def dpid_filters(msg):
    """
        Filter PacketIn and PacketOut messages based on DPID and ports
        Sanitizer filter (-F), entry "filters", "packetIn_filter" or
          "packetOut_filter"
          If switch_dpid AND in_port are Any, don't filter (print it)
          If switch_dpid OR in_port are NOT Any, print only what matches the
            most specific (filter everything else)
        Args:
            msg: class OFMessage
        Returns:
            False: Don' filter packet (print it)
            True: Filter it (don't print)
    """

    # It has to be a PacketOut or PacketIn
    if msg.ofp.header.message_type not in [10, 13]:
        return False

    # It has to be a LLDP packet
    if not is_protocol(msg.ofp.data, lldp=True):
        return False

    try:
        # If it is a PacketIn ...
        if msg.ofp.header.message_type in [10]:
            # It has to have a packetIn_filter filter
            filters = Sanitizer().filters['packetIn_filter']
            filter_port = filters['in_port']

        # If it a PacketOut...
        else:
            # It has to have a packetOut_filter filter
            filters = Sanitizer().filters['packetOut_filter']
            filter_port = filters['out_port']

        filter_dpid = filters['switch_dpid']

    except KeyError:
        return False
    if not len(filters):
        return False

    # Was switch_dpid or in_port specified by user?
    if filter_dpid in ['any', 'Any', 'ANY']:
        if filter_port in ['any', 'Any', 'ANY']:
            return False

    # If we got here, it means we have content to avoid printing
    print_it = False
    lldp_msg = get_protocol(msg.ofp.data, lldp=True)
    switch_dpid = clear_dpid(filter_dpid)

    if print_switch_dpid(switch_dpid, lldp_msg.c_id):
        if msg.ofp.header.message_type in [10]:
            if print_port(filter_port, str(msg.ofp.in_port)):
                print_it = True
        else:
            if print_port(filter_port, str(lldp_msg.p_id)):
                print_it = True

    if print_it:
        return False

    return True