Exemplo n.º 1
0
def print_switch_dpid(filter_dpid, packet_dpid):
    """
        Confirm if filter_dpid is packet_dpid or any
    """
    packet_dpid = clear_dpid(packet_dpid)
    if filter_dpid in [packet_dpid, 'Any', 'any', 'ANY']:
        return True
    return False
Exemplo n.º 2
0
    def add_dpid_to_proxy_db(self, ip_addr, port, dpid):
        """
            Receives the IP, TCP port and DPID and save them to the
            proxy_db. IP and TCP port are the indexes.

            Args:
                ip_addr: IP address
                port: TCP port
                dpid: switch datapath id
        """
        dpid = clear_dpid(dpid)
        self.proxy_db[ip_addr, port] = self.get_datapath_name(dpid)
Exemplo n.º 3
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