Source code for faucet.valve_lldp

"""Manage LLDP."""

# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
# Copyright (C) 2015 Brad Cowie, Christopher Lorier and Joe Stringer.
# Copyright (C) 2015 Research and Education Advanced Network New Zealand Ltd.
# Copyright (C) 2015--2019 The Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from collections import defaultdict

from faucet import valve_util
from faucet import valve_of
from faucet import valve_packet
from faucet.valve_manager_base import ValveManagerBase


[docs] class ValveLLDPManager(ValveManagerBase): """Manage LLDP.""" def __init__( self, vlan_table, highest_priority, logger, notify, inc_var, set_var, set_port_var, stack_manager, ): self.vlan_table = vlan_table self.highest_priority = highest_priority self.logger = logger self.notify = notify self._set_var = set_var self._inc_var = inc_var self._set_port_var = set_port_var self.stack_manager = stack_manager def _lldp_match(self, port): return self.vlan_table.match( in_port=port.number, eth_dst=valve_packet.LLDP_MAC_NEAREST_BRIDGE, eth_dst_mask=valve_packet.BRIDGE_GROUP_MASK, eth_type=valve_of.ether.ETH_TYPE_LLDP, )
[docs] def add_port(self, port): ofmsgs = [] if port.receive_lldp: ofmsgs.append( self.vlan_table.flowcontroller( match=self._lldp_match(port), priority=self.highest_priority, max_len=128, ) ) return ofmsgs
[docs] def del_port(self, port): ofmsgs = [] if port.receive_lldp: ofmsgs.append( self.vlan_table.flowdel( match=self._lldp_match(port), priority=self.highest_priority ) ) return ofmsgs
[docs] def verify_lldp( self, port, now, valve, other_valves, remote_dp_id, remote_dp_name, remote_port_id, remote_port_state, ): """ Verify correct LLDP cabling, then update port to next state Args: port (Port): Port that received the LLDP now (float): Current time other_valves (list): Other valves in the topology remote_dp_id (int): Received LLDP remote DP ID remote_dp_name (str): Received LLDP remote DP name remote_port_id (int): Recevied LLDP port ID remote_port_state (int): Received LLDP port state Returns: dict: Ofmsgs by valve """ if not port.stack: return {} remote_dp = port.stack["dp"] remote_port = port.stack["port"] stack_correct = True self._inc_var("stack_probes_received") if ( remote_dp_id != remote_dp.dp_id or remote_dp_name != remote_dp.name or remote_port_id != remote_port.number ): self.logger.error( "Stack %s cabling incorrect, expected %s:%s:%u, actual %s:%s:%u" % ( port, valve_util.dpid_log(remote_dp.dp_id), remote_dp.name, remote_port.number, valve_util.dpid_log(remote_dp_id), remote_dp_name, remote_port_id, ) ) stack_correct = False self._inc_var("stack_cabling_errors") port.dyn_stack_probe_info = { "last_seen_lldp_time": now, "stack_correct": stack_correct, "remote_dp_id": remote_dp_id, "remote_dp_name": remote_dp_name, "remote_port_id": remote_port_id, "remote_port_state": remote_port_state, } return self.update_stack_link_state([port], now, valve, other_valves)