summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl')
-rw-r--r--framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java69
-rw-r--r--framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java261
-rw-r--r--framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscoveryFromDevice.java31
-rw-r--r--framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscoveryFromPort.java31
-rw-r--r--framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java760
-rw-r--r--framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/SuppressionConfig.java144
-rw-r--r--framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/SuppressionRules.java123
-rw-r--r--framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/package-info.java20
8 files changed, 0 insertions, 1439 deletions
diff --git a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java
deleted file mode 100644
index a9da92ab..00000000
--- a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * 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.
- */
-package org.onosproject.provider.lldp.impl;
-
-import org.onosproject.mastership.MastershipService;
-import org.onosproject.net.LinkKey;
-import org.onosproject.net.link.LinkProviderService;
-import org.onosproject.net.packet.PacketService;
-
-/**
- * Shared context for use by link discovery.
- */
-interface DiscoveryContext {
-
- /**
- * Returns the shared mastership service reference.
- *
- * @return mastership service
- */
- MastershipService mastershipService();
-
- /**
- * Returns the shared link provider service reference.
- *
- * @return link provider service
- */
- LinkProviderService providerService();
-
- /**
- * Returns the shared packet service reference.
- *
- * @return packet service
- */
- PacketService packetService();
-
- /**
- * Returns the probe rate in millis.
- *
- * @return probe rate
- */
- long probeRate();
-
- /**
- * Indicates whether to emit BDDP.
- *
- * @return true to emit BDDP
- */
- boolean useBddp();
-
- /**
- * Touches the link identified by the given key to indicate that it's active.
- *
- * @param key link key
- */
- void touchLink(LinkKey key);
-}
diff --git a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java
deleted file mode 100644
index 4b962ae5..00000000
--- a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * Copyright 2014-2015 Open Networking Laboratory
- *
- * 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.
- */
-package org.onosproject.provider.lldp.impl;
-
-import com.google.common.collect.Sets;
-import org.jboss.netty.util.Timeout;
-import org.jboss.netty.util.TimerTask;
-import org.onlab.packet.Ethernet;
-import org.onlab.packet.ONOSLLDP;
-import org.onlab.util.Timer;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.Device;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Link.Type;
-import org.onosproject.net.LinkKey;
-import org.onosproject.net.Port;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.link.DefaultLinkDescription;
-import org.onosproject.net.link.LinkDescription;
-import org.onosproject.net.packet.DefaultOutboundPacket;
-import org.onosproject.net.packet.OutboundPacket;
-import org.onosproject.net.packet.PacketContext;
-import org.slf4j.Logger;
-
-import java.nio.ByteBuffer;
-import java.util.Set;
-
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static org.onosproject.net.PortNumber.portNumber;
-import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Run discovery process from a physical switch. Ports are initially labeled as
- * slow ports. When an LLDP is successfully received, label the remote port as
- * fast. Every probeRate milliseconds, loop over all fast ports and send an
- * LLDP, send an LLDP for a single slow port. Based on FlowVisor topology
- * discovery implementation.
- */
-class LinkDiscovery implements TimerTask {
-
- private final Logger log = getLogger(getClass());
-
- private static final String SRC_MAC = "DE:AD:BE:EF:BA:11";
-
- private final Device device;
- private final DiscoveryContext context;
-
- private final ONOSLLDP lldpPacket;
- private final Ethernet ethPacket;
- private final Ethernet bddpEth;
-
- private Timeout timeout;
- private volatile boolean isStopped;
-
- // Set of ports to be probed
- private final Set<Long> ports = Sets.newConcurrentHashSet();
-
- /**
- * Instantiates discovery manager for the given physical switch. Creates a
- * generic LLDP packet that will be customized for the port it is sent out on.
- * Starts the the timer for the discovery process.
- *
- * @param device the physical switch
- * @param context discovery context
- */
- LinkDiscovery(Device device, DiscoveryContext context) {
- this.device = device;
- this.context = context;
-
- lldpPacket = new ONOSLLDP();
- lldpPacket.setChassisId(device.chassisId());
- lldpPacket.setDevice(device.id().toString());
-
- ethPacket = new Ethernet();
- ethPacket.setEtherType(Ethernet.TYPE_LLDP);
- ethPacket.setDestinationMACAddress(ONOSLLDP.LLDP_NICIRA);
- ethPacket.setPayload(this.lldpPacket);
- ethPacket.setPad(true);
-
- bddpEth = new Ethernet();
- bddpEth.setPayload(lldpPacket);
- bddpEth.setEtherType(Ethernet.TYPE_BSN);
- bddpEth.setDestinationMACAddress(ONOSLLDP.BDDP_MULTICAST);
- bddpEth.setPad(true);
-
- isStopped = true;
- start();
- log.debug("Started discovery manager for switch {}", device.id());
-
- }
-
- synchronized void stop() {
- if (!isStopped) {
- isStopped = true;
- timeout.cancel();
- } else {
- log.warn("LinkDiscovery stopped multiple times?");
- }
- }
-
- synchronized void start() {
- if (isStopped) {
- isStopped = false;
- timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS);
- } else {
- log.warn("LinkDiscovery started multiple times?");
- }
- }
-
- synchronized boolean isStopped() {
- return isStopped || timeout.isCancelled();
- }
-
- /**
- * Add physical port to discovery process.
- * Send out initial LLDP and label it as slow port.
- *
- * @param port the port
- */
- void addPort(Port port) {
- boolean newPort = ports.add(port.number().toLong());
- boolean isMaster = context.mastershipService().isLocalMaster(device.id());
- if (newPort && isMaster) {
- log.debug("Sending initial probe to port {}@{}", port.number().toLong(), device.id());
- sendProbes(port.number().toLong());
- }
- }
-
- /**
- * removed physical port from discovery process.
- * @param port the port number
- */
- void removePort(PortNumber port) {
- ports.remove(port.toLong());
- }
-
- /**
- * Handles an incoming LLDP packet. Creates link in topology and adds the
- * link for staleness tracking.
- *
- * @param packetContext packet context
- * @return true if handled
- */
- boolean handleLldp(PacketContext packetContext) {
- Ethernet eth = packetContext.inPacket().parsed();
- if (eth == null) {
- return false;
- }
-
- ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
- if (onoslldp != null) {
- PortNumber srcPort = portNumber(onoslldp.getPort());
- PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
- DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
- DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
-
- ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
- ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
-
- LinkDescription ld = eth.getEtherType() == Ethernet.TYPE_LLDP ?
- new DefaultLinkDescription(src, dst, Type.DIRECT) :
- new DefaultLinkDescription(src, dst, Type.INDIRECT);
-
- try {
- context.providerService().linkDetected(ld);
- context.touchLink(LinkKey.linkKey(src, dst));
- } catch (IllegalStateException e) {
- return true;
- }
- return true;
- }
- return false;
- }
-
-
- /**
- * Execute this method every t milliseconds. Loops over all ports
- * labeled as fast and sends out an LLDP. Send out an LLDP on a single slow
- * port.
- *
- * @param t timeout
- */
- @Override
- public void run(Timeout t) {
- if (isStopped()) {
- return;
- }
-
- if (context.mastershipService().isLocalMaster(device.id())) {
- log.trace("Sending probes from {}", device.id());
- ports.forEach(this::sendProbes);
- }
-
- if (!isStopped()) {
- timeout = Timer.getTimer().newTimeout(this, context.probeRate(), MILLISECONDS);
- }
- }
-
- /**
- * Creates packet_out LLDP for specified output port.
- *
- * @param port the port
- * @return Packet_out message with LLDP data
- */
- private OutboundPacket createOutBoundLldp(Long port) {
- if (port == null) {
- return null;
- }
- lldpPacket.setPortId(port.intValue());
- ethPacket.setSourceMACAddress(SRC_MAC);
- return new DefaultOutboundPacket(device.id(),
- builder().setOutput(portNumber(port)).build(),
- ByteBuffer.wrap(ethPacket.serialize()));
- }
-
- /**
- * Creates packet_out BDDP for specified output port.
- *
- * @param port the port
- * @return Packet_out message with LLDP data
- */
- private OutboundPacket createOutBoundBddp(Long port) {
- if (port == null) {
- return null;
- }
- lldpPacket.setPortId(port.intValue());
- bddpEth.setSourceMACAddress(SRC_MAC);
- return new DefaultOutboundPacket(device.id(),
- builder().setOutput(portNumber(port)).build(),
- ByteBuffer.wrap(bddpEth.serialize()));
- }
-
- private void sendProbes(Long portNumber) {
- log.trace("Sending probes out to {}@{}", portNumber, device.id());
- OutboundPacket pkt = createOutBoundLldp(portNumber);
- context.packetService().emit(pkt);
- if (context.useBddp()) {
- OutboundPacket bpkt = createOutBoundBddp(portNumber);
- context.packetService().emit(bpkt);
- }
- }
-
- boolean containsPort(long portNumber) {
- return ports.contains(portNumber);
- }
-
-}
diff --git a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscoveryFromDevice.java b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscoveryFromDevice.java
deleted file mode 100644
index 32b12d47..00000000
--- a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscoveryFromDevice.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * 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.
- */
-package org.onosproject.provider.lldp.impl;
-
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.config.basics.BasicFeatureConfig;
-
-/**
- * Configuration to see LinkDiscovery should be enabled on Device.
- */
-public class LinkDiscoveryFromDevice extends BasicFeatureConfig<DeviceId> {
-
- public LinkDiscoveryFromDevice() {
- // default: enabled
- super(true);
- }
-
-}
diff --git a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscoveryFromPort.java b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscoveryFromPort.java
deleted file mode 100644
index b9a502f8..00000000
--- a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscoveryFromPort.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * 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.
- */
-package org.onosproject.provider.lldp.impl;
-
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.config.basics.BasicFeatureConfig;
-
-/**
- * Configuration to see LinkDiscovery should be enabled on a Port.
- */
-public class LinkDiscoveryFromPort extends BasicFeatureConfig<ConnectPoint> {
-
- public LinkDiscoveryFromPort() {
- // default: enabled
- super(true);
- }
-
-}
diff --git a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
deleted file mode 100644
index 668d59c0..00000000
--- a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
+++ /dev/null
@@ -1,760 +0,0 @@
-/*
- * Copyright 2014-2015 Open Networking Laboratory
- *
- * 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.
- */
-package org.onosproject.provider.lldp.impl;
-
-import static com.google.common.base.Strings.isNullOrEmpty;
-import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.onlab.packet.Ethernet.TYPE_BSN;
-import static org.onlab.packet.Ethernet.TYPE_LLDP;
-import static org.onlab.util.Tools.get;
-import static org.onlab.util.Tools.groupedThreads;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
-import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY;
-import static org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.util.Dictionary;
-import java.util.EnumSet;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Properties;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledExecutorService;
-
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Modified;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.onlab.packet.Ethernet;
-import org.onosproject.cfg.ComponentConfigService;
-import org.onosproject.cluster.ClusterService;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.mastership.MastershipEvent;
-import org.onosproject.mastership.MastershipListener;
-import org.onosproject.mastership.MastershipService;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.Device;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.LinkKey;
-import org.onosproject.net.Port;
-import org.onosproject.net.config.ConfigFactory;
-import org.onosproject.net.config.NetworkConfigEvent;
-import org.onosproject.net.config.NetworkConfigListener;
-import org.onosproject.net.config.NetworkConfigRegistry;
-import org.onosproject.net.device.DeviceEvent;
-import org.onosproject.net.device.DeviceListener;
-import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.link.DefaultLinkDescription;
-import org.onosproject.net.link.LinkProvider;
-import org.onosproject.net.link.LinkProviderRegistry;
-import org.onosproject.net.link.LinkProviderService;
-import org.onosproject.net.link.LinkService;
-import org.onosproject.net.packet.PacketContext;
-import org.onosproject.net.packet.PacketPriority;
-import org.onosproject.net.packet.PacketProcessor;
-import org.onosproject.net.packet.PacketService;
-import org.onosproject.net.provider.AbstractProvider;
-import org.onosproject.net.provider.ProviderId;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-
-/**
- * Provider which uses LLDP and BDDP packets to detect network infrastructure links.
- */
-@Component(immediate = true)
-public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
-
- private static final String PROVIDER_NAME = "org.onosproject.provider.lldp";
-
- private static final String FORMAT =
- "Settings: enabled={}, useBDDP={}, probeRate={}, " +
- "staleLinkAge={}";
-
- // When a Device/Port has this annotation, do not send out LLDP/BDDP
- public static final String NO_LLDP = "no-lldp";
-
- private final Logger log = getLogger(getClass());
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected LinkProviderRegistry providerRegistry;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected LinkService linkService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected PacketService packetService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected MastershipService masterService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ComponentConfigService cfgService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ClusterService clusterService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected NetworkConfigRegistry cfgRegistry;
-
- private LinkProviderService providerService;
-
- private ScheduledExecutorService executor;
-
- // TODO: Add sanity checking for the configurable params based on the delays
- private static final long DEVICE_SYNC_DELAY = 5;
- private static final long LINK_PRUNER_DELAY = 3;
-
- private static final String PROP_ENABLED = "enabled";
- @Property(name = PROP_ENABLED, boolValue = true,
- label = "If false, link discovery is disabled")
- private boolean enabled = false;
-
- private static final String PROP_USE_BDDP = "useBDDP";
- @Property(name = PROP_USE_BDDP, boolValue = true,
- label = "Use BDDP for link discovery")
- private boolean useBddp = true;
-
- private static final String PROP_PROBE_RATE = "probeRate";
- private static final int DEFAULT_PROBE_RATE = 3_000;
- @Property(name = PROP_PROBE_RATE, intValue = DEFAULT_PROBE_RATE,
- label = "LLDP and BDDP probe rate specified in millis")
- private int probeRate = DEFAULT_PROBE_RATE;
-
- private static final String PROP_STALE_LINK_AGE = "staleLinkAge";
- private static final int DEFAULT_STALE_LINK_AGE = 10_000;
- @Property(name = PROP_STALE_LINK_AGE, intValue = DEFAULT_STALE_LINK_AGE,
- label = "Number of millis beyond which links will be considered stale")
- private int staleLinkAge = DEFAULT_STALE_LINK_AGE;
-
- private final DiscoveryContext context = new InternalDiscoveryContext();
- private final InternalRoleListener roleListener = new InternalRoleListener();
- private final InternalDeviceListener deviceListener = new InternalDeviceListener();
- private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor();
-
- // Device link discovery helpers.
- protected final Map<DeviceId, LinkDiscovery> discoverers = new ConcurrentHashMap<>();
-
- // Most recent time a tracked link was seen; links are tracked if their
- // destination connection point is mastered by this controller instance.
- private final Map<LinkKey, Long> linkTimes = Maps.newConcurrentMap();
-
- private ApplicationId appId;
-
- static final SuppressionRules DEFAULT_RULES
- = new SuppressionRules(EnumSet.of(Device.Type.ROADM),
- ImmutableMap.of(NO_LLDP, SuppressionRules.ANY_VALUE));
-
- private SuppressionRules rules = LldpLinkProvider.DEFAULT_RULES;
-
- public static final String CONFIG_KEY = "suppression";
- public static final String FEATURE_NAME = "linkDiscovery";
-
- private final Set<ConfigFactory<?, ?>> factories = ImmutableSet.of(
- new ConfigFactory<ApplicationId, SuppressionConfig>(APP_SUBJECT_FACTORY,
- SuppressionConfig.class,
- CONFIG_KEY) {
- @Override
- public SuppressionConfig createConfig() {
- return new SuppressionConfig();
- }
- },
- new ConfigFactory<DeviceId, LinkDiscoveryFromDevice>(DEVICE_SUBJECT_FACTORY,
- LinkDiscoveryFromDevice.class, FEATURE_NAME) {
- @Override
- public LinkDiscoveryFromDevice createConfig() {
- return new LinkDiscoveryFromDevice();
- }
- },
- new ConfigFactory<ConnectPoint, LinkDiscoveryFromPort>(CONNECT_POINT_SUBJECT_FACTORY,
- LinkDiscoveryFromPort.class, FEATURE_NAME) {
- @Override
- public LinkDiscoveryFromPort createConfig() {
- return new LinkDiscoveryFromPort();
- }
- }
- );
-
- private final InternalConfigListener cfgListener = new InternalConfigListener();
-
-
- /**
- * Creates an OpenFlow link provider.
- */
- public LldpLinkProvider() {
- super(new ProviderId("lldp", PROVIDER_NAME));
- }
-
- @Activate
- public void activate(ComponentContext context) {
- cfgService.registerProperties(getClass());
- appId = coreService.registerApplication(PROVIDER_NAME);
-
- cfgRegistry.addListener(cfgListener);
- factories.forEach(cfgRegistry::registerConfigFactory);
-
- SuppressionConfig cfg = cfgRegistry.getConfig(appId, SuppressionConfig.class);
- if (cfg == null) {
- // If no configuration is found, register default.
- cfg = cfgRegistry.addConfig(appId, SuppressionConfig.class);
- cfg.deviceTypes(DEFAULT_RULES.getSuppressedDeviceType())
- .annotation(DEFAULT_RULES.getSuppressedAnnotation())
- .apply();
- }
- cfgListener.reconfigureSuppressionRules(cfg);
-
- modified(context);
- log.info("Started");
- }
-
- @Deactivate
- public void deactivate() {
- cfgRegistry.removeListener(cfgListener);
- factories.forEach(cfgRegistry::unregisterConfigFactory);
-
- cfgService.unregisterProperties(getClass(), false);
- disable();
- log.info("Stopped");
- }
-
- @Modified
- public void modified(ComponentContext context) {
- Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
-
- boolean newEnabled, newUseBddp;
- int newProbeRate, newStaleLinkAge;
- try {
- String s = get(properties, PROP_ENABLED);
- newEnabled = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim());
-
- s = get(properties, PROP_USE_BDDP);
- newUseBddp = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim());
-
- s = get(properties, PROP_PROBE_RATE);
- newProbeRate = isNullOrEmpty(s) ? probeRate : Integer.parseInt(s.trim());
-
- s = get(properties, PROP_STALE_LINK_AGE);
- newStaleLinkAge = isNullOrEmpty(s) ? staleLinkAge : Integer.parseInt(s.trim());
-
- } catch (NumberFormatException e) {
- log.warn("Component configuration had invalid values", e);
- newEnabled = enabled;
- newUseBddp = useBddp;
- newProbeRate = probeRate;
- newStaleLinkAge = staleLinkAge;
- }
-
- boolean wasEnabled = enabled;
-
- enabled = newEnabled;
- useBddp = newUseBddp;
- probeRate = newProbeRate;
- staleLinkAge = newStaleLinkAge;
-
- if (!wasEnabled && enabled) {
- enable();
- } else if (wasEnabled && !enabled) {
- disable();
- } else {
- if (enabled) {
- // update all discovery helper state
- loadDevices();
- }
- }
-
- log.info(FORMAT, enabled, useBddp, probeRate, staleLinkAge);
- }
-
- /**
- * Enables link discovery processing.
- */
- private void enable() {
- providerService = providerRegistry.register(this);
- masterService.addListener(roleListener);
- deviceService.addListener(deviceListener);
- packetService.addProcessor(packetProcessor, PacketProcessor.advisor(0));
-
- loadDevices();
-
- executor = newSingleThreadScheduledExecutor(groupedThreads("onos/link", "discovery-%d"));
- executor.scheduleAtFixedRate(new SyncDeviceInfoTask(),
- DEVICE_SYNC_DELAY, DEVICE_SYNC_DELAY, SECONDS);
- executor.scheduleAtFixedRate(new LinkPrunerTask(),
- LINK_PRUNER_DELAY, LINK_PRUNER_DELAY, SECONDS);
-
- requestIntercepts();
- }
-
- /**
- * Disables link discovery processing.
- */
- private void disable() {
- withdrawIntercepts();
-
- providerRegistry.unregister(this);
- masterService.removeListener(roleListener);
- deviceService.removeListener(deviceListener);
- packetService.removeProcessor(packetProcessor);
-
-
- if (executor != null) {
- executor.shutdownNow();
- }
- discoverers.values().forEach(LinkDiscovery::stop);
- discoverers.clear();
-
- providerService = null;
- }
-
- /**
- * Loads available devices and registers their ports to be probed.
- */
- private void loadDevices() {
- if (!enabled) {
- return;
- }
- deviceService.getAvailableDevices()
- .forEach(d -> updateDevice(d)
- .ifPresent(ld -> updatePorts(ld, d.id())));
- }
-
- private boolean isBlacklisted(DeviceId did) {
- LinkDiscoveryFromDevice cfg = cfgRegistry.getConfig(did, LinkDiscoveryFromDevice.class);
- if (cfg == null) {
- return false;
- }
- return !cfg.enabled();
- }
-
- private boolean isBlacklisted(ConnectPoint cp) {
- // if parent device is blacklisted, so is the port
- if (isBlacklisted(cp.deviceId())) {
- return true;
- }
- LinkDiscoveryFromPort cfg = cfgRegistry.getConfig(cp, LinkDiscoveryFromPort.class);
- if (cfg == null) {
- return false;
- }
- return !cfg.enabled();
- }
-
- private boolean isBlacklisted(Port port) {
- return isBlacklisted(new ConnectPoint(port.element().id(), port.number()));
- }
-
- /**
- * Updates discovery helper for specified device.
- *
- * Adds and starts a discovery helper for specified device if enabled,
- * calls {@link #removeDevice(DeviceId)} otherwise.
- *
- * @param device device to add
- * @return discovery helper if discovery is enabled for the device
- */
- private Optional<LinkDiscovery> updateDevice(Device device) {
- if (device == null) {
- return Optional.empty();
- }
- if (rules.isSuppressed(device) || isBlacklisted(device.id())) {
- log.trace("LinkDiscovery from {} disabled by configuration", device.id());
- removeDevice(device.id());
- return Optional.empty();
- }
- LinkDiscovery ld = discoverers.computeIfAbsent(device.id(),
- did -> new LinkDiscovery(device, context));
- if (ld.isStopped()) {
- ld.start();
- }
- return Optional.of(ld);
- }
-
- /**
- * Removes after stopping discovery helper for specified device.
- * @param deviceId device to remove
- */
- private void removeDevice(final DeviceId deviceId) {
- discoverers.computeIfPresent(deviceId, (did, ld) -> {
- ld.stop();
- return null;
- });
-
- }
-
- /**
- * Updates ports of the specified device to the specified discovery helper.
- */
- private void updatePorts(LinkDiscovery discoverer, DeviceId deviceId) {
- deviceService.getPorts(deviceId).forEach(p -> updatePort(discoverer, p));
- }
-
- /**
- * Updates discovery helper state of the specified port.
- *
- * Adds a port to the discovery helper if up and discovery is enabled,
- * or calls {@link #removePort(Port)} otherwise.
- */
- private void updatePort(LinkDiscovery discoverer, Port port) {
- if (port == null) {
- return;
- }
- if (port.number().isLogical()) {
- // silently ignore logical ports
- return;
- }
-
- if (rules.isSuppressed(port) || isBlacklisted(port)) {
- log.trace("LinkDiscovery from {} disabled by configuration", port);
- removePort(port);
- return;
- }
-
- // check if enabled and turn off discovery?
- if (!port.isEnabled()) {
- removePort(port);
- return;
- }
-
- discoverer.addPort(port);
- }
-
- /**
- * Removes a port from the specified discovery helper.
- * @param port the port
- */
- private void removePort(Port port) {
- if (port.element() instanceof Device) {
- Device d = (Device) port.element();
- LinkDiscovery ld = discoverers.get(d.id());
- if (ld != null) {
- ld.removePort(port.number());
- }
- } else {
- log.warn("Attempted to remove non-Device port", port);
- }
- }
-
- /**
- * Requests packet intercepts.
- */
- private void requestIntercepts() {
- TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
- selector.matchEthType(TYPE_LLDP);
- packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId);
-
- selector.matchEthType(TYPE_BSN);
- if (useBddp) {
- packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId);
- } else {
- packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId);
- }
- }
-
- /**
- * Withdraws packet intercepts.
- */
- private void withdrawIntercepts() {
- TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
- selector.matchEthType(TYPE_LLDP);
- packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId);
- selector.matchEthType(TYPE_BSN);
- packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId);
- }
-
- protected SuppressionRules rules() {
- return rules;
- }
-
- protected void updateRules(SuppressionRules newRules) {
- if (!rules.equals(newRules)) {
- rules = newRules;
- loadDevices();
- }
- }
-
- /**
- * Processes device mastership role changes.
- */
- private class InternalRoleListener implements MastershipListener {
- @Override
- public void event(MastershipEvent event) {
- if (MastershipEvent.Type.BACKUPS_CHANGED.equals(event.type())) {
- // only need new master events
- return;
- }
-
- DeviceId deviceId = event.subject();
- Device device = deviceService.getDevice(deviceId);
- if (device == null) {
- log.debug("Device {} doesn't exist, or isn't there yet", deviceId);
- return;
- }
- if (clusterService.getLocalNode().id().equals(event.roleInfo().master())) {
- updateDevice(device).ifPresent(ld -> updatePorts(ld, device.id()));
- }
- }
- }
-
- /**
- * Processes device events.
- */
- private class InternalDeviceListener implements DeviceListener {
- @Override
- public void event(DeviceEvent event) {
- Device device = event.subject();
- Port port = event.port();
- if (device == null) {
- log.error("Device is null.");
- return;
- }
- log.trace("{} {} {}", event.type(), event.subject(), event);
- final DeviceId deviceId = device.id();
- switch (event.type()) {
- case DEVICE_ADDED:
- case DEVICE_UPDATED:
- updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId));
- break;
- case PORT_ADDED:
- case PORT_UPDATED:
- if (port.isEnabled()) {
- updateDevice(device).ifPresent(ld -> updatePort(ld, port));
- } else {
- log.debug("Port down {}", port);
- removePort(port);
- providerService.linksVanished(new ConnectPoint(port.element().id(),
- port.number()));
- }
- break;
- case PORT_REMOVED:
- log.debug("Port removed {}", port);
- removePort(port);
- providerService.linksVanished(new ConnectPoint(port.element().id(),
- port.number()));
- break;
- case DEVICE_REMOVED:
- case DEVICE_SUSPENDED:
- log.debug("Device removed {}", deviceId);
- removeDevice(deviceId);
- providerService.linksVanished(deviceId);
- break;
- case DEVICE_AVAILABILITY_CHANGED:
- if (deviceService.isAvailable(deviceId)) {
- log.debug("Device up {}", deviceId);
- updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId));
- } else {
- log.debug("Device down {}", deviceId);
- removeDevice(deviceId);
- providerService.linksVanished(deviceId);
- }
- break;
- case PORT_STATS_UPDATED:
- break;
- default:
- log.debug("Unknown event {}", event);
- }
- }
- }
-
- /**
- * Processes incoming packets.
- */
- private class InternalPacketProcessor implements PacketProcessor {
- @Override
- public void process(PacketContext context) {
- if (context == null || context.isHandled()) {
- return;
- }
-
- Ethernet eth = context.inPacket().parsed();
- if (eth == null || (eth.getEtherType() != TYPE_LLDP && eth.getEtherType() != TYPE_BSN)) {
- return;
- }
-
- LinkDiscovery ld = discoverers.get(context.inPacket().receivedFrom().deviceId());
- if (ld == null) {
- return;
- }
-
- if (ld.handleLldp(context)) {
- context.block();
- }
- }
- }
-
- /**
- * Auxiliary task to keep device ports up to date.
- */
- private final class SyncDeviceInfoTask implements Runnable {
- @Override
- public void run() {
- if (Thread.currentThread().isInterrupted()) {
- log.info("Interrupted, quitting");
- return;
- }
- // check what deviceService sees, to see if we are missing anything
- try {
- loadDevices();
- } catch (Exception e) {
- // Catch all exceptions to avoid task being suppressed
- log.error("Exception thrown during synchronization process", e);
- }
- }
- }
-
- /**
- * Auxiliary task for pruning stale links.
- */
- private class LinkPrunerTask implements Runnable {
- @Override
- public void run() {
- if (Thread.currentThread().isInterrupted()) {
- log.info("Interrupted, quitting");
- return;
- }
-
- try {
- // TODO: There is still a slight possibility of mastership
- // change occurring right with link going stale. This will
- // result in the stale link not being pruned.
- Maps.filterEntries(linkTimes, e -> {
- if (!masterService.isLocalMaster(e.getKey().dst().deviceId())) {
- return true;
- }
- if (isStale(e.getValue())) {
- providerService.linkVanished(new DefaultLinkDescription(e.getKey().src(),
- e.getKey().dst(),
- DIRECT));
- return true;
- }
- return false;
- }).clear();
-
- } catch (Exception e) {
- // Catch all exceptions to avoid task being suppressed
- log.error("Exception thrown during link pruning process", e);
- }
- }
-
- private boolean isStale(long lastSeen) {
- return lastSeen < System.currentTimeMillis() - staleLinkAge;
- }
- }
-
- /**
- * Provides processing context for the device link discovery helpers.
- */
- private class InternalDiscoveryContext implements DiscoveryContext {
- @Override
- public MastershipService mastershipService() {
- return masterService;
- }
-
- @Override
- public LinkProviderService providerService() {
- return providerService;
- }
-
- @Override
- public PacketService packetService() {
- return packetService;
- }
-
- @Override
- public long probeRate() {
- return probeRate;
- }
-
- @Override
- public boolean useBddp() {
- return useBddp;
- }
-
- @Override
- public void touchLink(LinkKey key) {
- linkTimes.put(key, System.currentTimeMillis());
- }
- }
-
- static final EnumSet<NetworkConfigEvent.Type> CONFIG_CHANGED
- = EnumSet.of(NetworkConfigEvent.Type.CONFIG_ADDED,
- NetworkConfigEvent.Type.CONFIG_UPDATED,
- NetworkConfigEvent.Type.CONFIG_REMOVED);
-
- private class InternalConfigListener implements NetworkConfigListener {
-
- private synchronized void reconfigureSuppressionRules(SuppressionConfig cfg) {
- if (cfg == null) {
- log.error("Suppression Config is null.");
- return;
- }
-
- SuppressionRules newRules = new SuppressionRules(cfg.deviceTypes(),
- cfg.annotation());
-
- updateRules(newRules);
- }
-
- @Override
- public void event(NetworkConfigEvent event) {
- if (event.configClass() == LinkDiscoveryFromDevice.class &&
- CONFIG_CHANGED.contains(event.type())) {
-
- if (event.subject() instanceof DeviceId) {
- final DeviceId did = (DeviceId) event.subject();
- Device device = deviceService.getDevice(did);
- updateDevice(device).ifPresent(ld -> updatePorts(ld, did));
- }
-
- } else if (event.configClass() == LinkDiscoveryFromPort.class &&
- CONFIG_CHANGED.contains(event.type())) {
-
- if (event.subject() instanceof ConnectPoint) {
- ConnectPoint cp = (ConnectPoint) event.subject();
- if (cp.elementId() instanceof DeviceId) {
- final DeviceId did = (DeviceId) cp.elementId();
- Device device = deviceService.getDevice(did);
- Port port = deviceService.getPort(did, cp.port());
- updateDevice(device).ifPresent(ld -> updatePort(ld, port));
- }
- }
-
- } else if (event.configClass().equals(SuppressionConfig.class) &&
- (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
- event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)) {
- SuppressionConfig cfg = cfgRegistry.getConfig(appId, SuppressionConfig.class);
- reconfigureSuppressionRules(cfg);
- log.trace("Network config reconfigured");
- }
- }
- }
-}
diff --git a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/SuppressionConfig.java b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/SuppressionConfig.java
deleted file mode 100644
index 5b10f6d2..00000000
--- a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/SuppressionConfig.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright 2014-2015 Open Networking Laboratory
- *
- * 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.
- */
-package org.onosproject.provider.lldp.impl;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-
-import org.onosproject.core.ApplicationId;
-import org.onosproject.net.Device;
-import org.onosproject.net.config.Config;
-import org.slf4j.Logger;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import static org.onosproject.provider.lldp.impl.LldpLinkProvider.DEFAULT_RULES;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * LinkDiscovery suppression config class.
- */
-public class SuppressionConfig extends Config<ApplicationId> {
-
- private static final String DEVICE_TYPES = "deviceTypes";
- private static final String ANNOTATION = "annotation";
-
- private static final ObjectMapper MAPPER = new ObjectMapper();
-
- private static final List<Device.Type> DEFAULT_DEVICE_TYPES
- = ImmutableList.copyOf(DEFAULT_RULES.getSuppressedDeviceType());
-
- private final Logger log = getLogger(getClass());
-
- /**
- * Returns types of devices on which LinkDiscovery is suppressed.
- *
- * @return set of device types
- */
- public Set<Device.Type> deviceTypes() {
- return ImmutableSet.copyOf(getList(DEVICE_TYPES, Device.Type::valueOf, DEFAULT_DEVICE_TYPES));
- }
-
- /**
- * Sets types of devices on which LinkDiscovery is suppressed.
- *
- * @param deviceTypes new set of device types; null to clear
- * @return self
- */
- public SuppressionConfig deviceTypes(Set<Device.Type> deviceTypes) {
- return (SuppressionConfig) setOrClear(DEVICE_TYPES, deviceTypes);
- }
-
- /**
- * Returns annotation of Ports on which LinkDiscovery is suppressed.
- *
- * @return key-value pairs of annotation
- */
- public Map<String, String> annotation() {
- ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
-
- String jsonAnnotation = get(ANNOTATION, null);
- if (jsonAnnotation == null || jsonAnnotation.isEmpty()) {
- return ImmutableMap.of();
- }
-
- JsonNode annotationNode;
- try {
- annotationNode = MAPPER.readTree(jsonAnnotation);
- } catch (IOException e) {
- log.error("Failed to read JSON tree from: {}", jsonAnnotation);
- return ImmutableMap.of();
- }
-
- if (annotationNode.isObject()) {
- ObjectNode obj = (ObjectNode) annotationNode;
- Iterator<Map.Entry<String, JsonNode>> it = obj.fields();
- while (it.hasNext()) {
- Map.Entry<String, JsonNode> entry = it.next();
- final String key = entry.getKey();
- final JsonNode value = entry.getValue();
-
- if (value.isValueNode()) {
- if (value.isNull()) {
- builder.put(key, SuppressionRules.ANY_VALUE);
- } else {
- builder.put(key, value.asText());
- }
- } else {
- log.warn("Encountered unexpected JSON field {} for annotation", entry);
- }
- }
- } else {
- log.error("Encountered unexpected JSONNode {} for annotation", annotationNode);
- return ImmutableMap.of();
- }
-
- return builder.build();
- }
-
- /**
- * Sets annotation of Ports on which LinkDiscovery is suppressed.
- *
- * @param annotation new key-value pair of annotation; null to clear
- * @return self
- */
- public SuppressionConfig annotation(Map<String, String> annotation) {
-
- // ANY_VALUE should be null in JSON
- Map<String, String> config = Maps.transformValues(annotation,
- v -> (v == SuppressionRules.ANY_VALUE) ? null : v);
-
- String jsonAnnotation = null;
-
- try {
- // TODO Store annotation as a Map instead of a String (which needs NetworkConfigRegistry modification)
- jsonAnnotation = MAPPER.writeValueAsString(config);
- } catch (JsonProcessingException e) {
- log.error("Failed to write JSON from: {}", annotation);
- }
-
- return (SuppressionConfig) setOrClear(ANNOTATION, jsonAnnotation);
- }
-}
diff --git a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/SuppressionRules.java b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/SuppressionRules.java
deleted file mode 100644
index 14bc2200..00000000
--- a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/SuppressionRules.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright 2014-2015 Open Networking Laboratory
- *
- * 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.
- */
-
-package org.onosproject.provider.lldp.impl;
-
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Set;
-
-import org.onosproject.net.Annotations;
-import org.onosproject.net.Device;
-import org.onosproject.net.Element;
-import org.onosproject.net.Port;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.base.MoreObjects;
-
-public class SuppressionRules {
-
- public static final String ANY_VALUE = "(any)";
-
- private final Set<Device.Type> suppressedDeviceType;
- private final Map<String, String> suppressedAnnotation;
-
- public SuppressionRules(Set<Device.Type> suppressedType,
- Map<String, String> suppressedAnnotation) {
-
- this.suppressedDeviceType = ImmutableSet.copyOf(suppressedType);
- this.suppressedAnnotation = ImmutableMap.copyOf(suppressedAnnotation);
- }
-
- public boolean isSuppressed(Device device) {
- if (suppressedDeviceType.contains(device.type())) {
- return true;
- }
- final Annotations annotations = device.annotations();
- if (containsSuppressionAnnotation(annotations)) {
- return true;
- }
- return false;
- }
-
- public boolean isSuppressed(Port port) {
- Element parent = port.element();
- if (parent instanceof Device) {
- if (isSuppressed((Device) parent)) {
- return true;
- }
- }
-
- final Annotations annotations = port.annotations();
- if (containsSuppressionAnnotation(annotations)) {
- return true;
- }
- return false;
- }
-
- private boolean containsSuppressionAnnotation(final Annotations annotations) {
- for (Entry<String, String> entry : suppressedAnnotation.entrySet()) {
- final String suppValue = entry.getValue();
- final String suppKey = entry.getKey();
- if (suppValue == ANY_VALUE) {
- if (annotations.keys().contains(suppKey)) {
- return true;
- }
- } else {
- if (suppValue.equals(annotations.value(suppKey))) {
- return true;
- }
- }
- }
- return false;
- }
-
- Set<Device.Type> getSuppressedDeviceType() {
- return suppressedDeviceType;
- }
-
- Map<String, String> getSuppressedAnnotation() {
- return suppressedAnnotation;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(suppressedDeviceType,
- suppressedAnnotation);
- }
-
- @Override
- public boolean equals(Object object) {
- if (object != null && getClass() == object.getClass()) {
- SuppressionRules that = (SuppressionRules) object;
- return Objects.equals(this.suppressedDeviceType,
- that.suppressedDeviceType)
- && Objects.equals(this.suppressedAnnotation,
- that.suppressedAnnotation);
- }
- return false;
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("suppressedDeviceType", suppressedDeviceType)
- .add("suppressedAnnotation", suppressedAnnotation)
- .toString();
- }
-}
diff --git a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/package-info.java b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/package-info.java
deleted file mode 100644
index 768a6cd2..00000000
--- a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * 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.
- */
-
-/**
- * Provider that uses the core as a means of infrastructure link inference.
- */
-package org.onosproject.provider.lldp.impl;