aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/net/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core/net/src/main/java/org')
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java2
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/edgeservice/impl/package-info.java16
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java38
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java48
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java15
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java48
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java42
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java81
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java14
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/proxyarp/impl/ProxyArpManager.java359
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/statistic/impl/StatisticManager.java22
11 files changed, 420 insertions, 265 deletions
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
index 07612292..8a441f61 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
@@ -59,7 +59,7 @@ public class CoreManager implements CoreService {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final File VERSION_FILE = new File("../VERSION");
- private static Version version = Version.version("1.3.0-SNAPSHOT");
+ private static Version version = Version.version("1.4.0-SNAPSHOT");
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ApplicationIdStore applicationIdStore;
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/edgeservice/impl/package-info.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/edgeservice/impl/package-info.java
index fd867326..fa5f2480 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/edgeservice/impl/package-info.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/edgeservice/impl/package-info.java
@@ -1,3 +1,19 @@
+/*
+ * 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.
+ */
+
/**
* Core subsystem for interacting with network edges.
*/
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
index 99263381..43f346b7 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
@@ -25,6 +25,7 @@ import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.incubator.net.intf.InterfaceService;
+import org.onosproject.net.edge.EdgePortService;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.config.NetworkConfigListener;
@@ -45,7 +46,6 @@ import org.onosproject.net.host.HostProviderService;
import org.onosproject.net.host.HostService;
import org.onosproject.net.host.HostStore;
import org.onosproject.net.host.HostStoreDelegate;
-import org.onosproject.net.host.PortAddresses;
import org.onosproject.net.packet.PacketService;
import org.onosproject.net.provider.AbstractProviderService;
import org.slf4j.Logger;
@@ -90,6 +90,9 @@ public class HostManager
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected InterfaceService interfaceService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected EdgePortService edgePortService;
+
private HostMonitor monitor;
@Activate
@@ -97,7 +100,7 @@ public class HostManager
store.setDelegate(delegate);
eventDispatcher.addSink(HostEvent.class, listenerRegistry);
networkConfigService.addListener(networkConfigListener);
- monitor = new HostMonitor(packetService, this, interfaceService);
+ monitor = new HostMonitor(packetService, this, interfaceService, edgePortService);
monitor.start();
log.info("Started");
}
@@ -195,33 +198,6 @@ public class HostManager
}
}
- @Override
- public void bindAddressesToPort(PortAddresses addresses) {
- store.updateAddressBindings(addresses);
- }
-
- @Override
- public void unbindAddressesFromPort(PortAddresses portAddresses) {
- store.removeAddressBindings(portAddresses);
- }
-
- @Override
- public void clearAddresses(ConnectPoint connectPoint) {
- store.clearAddressBindings(connectPoint);
- }
-
- @Override
- public Set<PortAddresses> getAddressBindings() {
- checkPermission(HOST_READ);
- return store.getAddressBindings();
- }
-
- @Override
- public Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint) {
- checkPermission(HOST_READ);
- return store.getAddressBindingsForPort(connectPoint);
- }
-
// Personalized host provider service issued to the supplied provider.
private class InternalHostProviderService
extends AbstractProviderService<HostProvider>
@@ -231,12 +207,12 @@ public class HostManager
}
@Override
- public void hostDetected(HostId hostId, HostDescription hostDescription) {
+ public void hostDetected(HostId hostId, HostDescription hostDescription, boolean replaceIps) {
checkNotNull(hostId, HOST_ID_NULL);
checkValidity();
hostDescription = validateHost(hostDescription, hostId);
HostEvent event = store.createOrUpdateHost(provider().id(), hostId,
- hostDescription);
+ hostDescription, replaceIps);
if (event != null) {
post(event);
}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
index fe252368..44f8cbf0 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
@@ -31,21 +31,20 @@ import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Host;
+import org.onosproject.net.edge.EdgePortService;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.flow.instructions.Instruction;
-import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.host.HostProvider;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.packet.DefaultOutboundPacket;
import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.packet.PacketService;
import org.onosproject.net.provider.ProviderId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -60,9 +59,13 @@ import java.util.concurrent.TimeUnit;
* </p>
*/
public class HostMonitor implements TimerTask {
+
+ private Logger log = LoggerFactory.getLogger(getClass());
+
private PacketService packetService;
private HostManager hostManager;
private InterfaceService interfaceService;
+ private EdgePortService edgePortService;
private final Set<IpAddress> monitoredAddresses;
@@ -83,11 +86,13 @@ public class HostMonitor implements TimerTask {
* @param interfaceService interface service for interface information
*/
public HostMonitor(PacketService packetService, HostManager hostManager,
- InterfaceService interfaceService) {
+ InterfaceService interfaceService,
+ EdgePortService edgePortService) {
this.packetService = packetService;
this.hostManager = hostManager;
this.interfaceService = interfaceService;
+ this.edgePortService = edgePortService;
monitoredAddresses = Collections.newSetFromMap(new ConcurrentHashMap<>());
hostProviders = new ConcurrentHashMap<>();
@@ -149,7 +154,7 @@ public class HostMonitor implements TimerTask {
Set<Host> hosts = hostManager.getHostsByIp(ip);
if (hosts.isEmpty()) {
- sendArpNdpRequest(ip);
+ sendRequest(ip);
} else {
for (Host host : hosts) {
HostProvider provider = hostProviders.get(host.providerId());
@@ -166,45 +171,44 @@ public class HostMonitor implements TimerTask {
}
/**
- * Sends an ARP or Neighbor Discovery Protocol request for the given IP
- * address.
+ * Sends an ARP or NDP request for the given IP address.
*
* @param targetIp IP address to send the request for
*/
- private void sendArpNdpRequest(IpAddress targetIp) {
+ private void sendRequest(IpAddress targetIp) {
Interface intf = interfaceService.getMatchingInterface(targetIp);
if (intf == null) {
return;
}
+ if (!edgePortService.isEdgePoint(intf.connectPoint())) {
+ log.warn("Attempt to send probe out non-edge port: {}", intf);
+ return;
+ }
+
for (InterfaceIpAddress ia : intf.ipAddresses()) {
if (ia.subnetAddress().contains(targetIp)) {
- sendArpNdpProbe(intf.connectPoint(), targetIp, ia.ipAddress(),
+ sendProbe(intf.connectPoint(), targetIp, ia.ipAddress(),
intf.mac(), intf.vlan());
}
}
}
- private void sendArpNdpProbe(ConnectPoint connectPoint,
- IpAddress targetIp,
- IpAddress sourceIp, MacAddress sourceMac,
- VlanId vlan) {
+ private void sendProbe(ConnectPoint connectPoint,
+ IpAddress targetIp,
+ IpAddress sourceIp, MacAddress sourceMac,
+ VlanId vlan) {
Ethernet probePacket = null;
if (targetIp.isIp4()) {
// IPv4: Use ARP
- probePacket = buildArpRequest(targetIp, sourceIp, sourceMac,
- vlan);
+ probePacket = buildArpRequest(targetIp, sourceIp, sourceMac, vlan);
} else {
// IPv6: Use Neighbor Discovery
- probePacket = buildNdpRequest(targetIp, sourceIp, sourceMac,
- vlan);
+ probePacket = buildNdpRequest(targetIp, sourceIp, sourceMac, vlan);
}
- List<Instruction> instructions = new ArrayList<>();
- instructions.add(Instructions.createOutput(connectPoint.port()));
-
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.setOutput(connectPoint.port())
.build();
@@ -273,7 +277,7 @@ public class HostMonitor implements TimerTask {
icmp6.setIcmpType(ICMP6.NEIGHBOR_SOLICITATION);
icmp6.setIcmpCode((byte) 0);
- // Create the Neighbor Solication packet
+ // Create the Neighbor Solicitation packet
NeighborSolicitation ns = new NeighborSolicitation();
ns.setTargetAddress(targetIp.toOctets());
ns.addOption(NeighborDiscoveryOptions.TYPE_SOURCE_LL_ADDRESS,
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java
index 609f9a34..52621e2f 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java
@@ -1,3 +1,18 @@
+/*
+ * 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.net.intent.impl.compiler;
import static java.util.Arrays.asList;
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
index c60325a7..05a20f96 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
@@ -51,7 +51,6 @@ import org.onosproject.net.resource.link.LinkResourceRequest;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.Topology;
-import org.onosproject.net.topology.TopologyEdge;
import org.onosproject.net.topology.TopologyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -265,34 +264,31 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
private Set<Path> getOpticalPaths(OpticalConnectivityIntent intent) {
// Route in WDM topology
Topology topology = topologyService.currentTopology();
- LinkWeight weight = new LinkWeight() {
- @Override
- public double weight(TopologyEdge edge) {
- // Disregard inactive or non-optical links
- if (edge.link().state() == Link.State.INACTIVE) {
- return -1;
- }
- if (edge.link().type() != Link.Type.OPTICAL) {
- return -1;
- }
- // Adhere to static port mappings
- DeviceId srcDeviceId = edge.link().src().deviceId();
- if (srcDeviceId.equals(intent.getSrc().deviceId())) {
- ConnectPoint srcStaticPort = staticPort(intent.getSrc());
- if (srcStaticPort != null) {
- return srcStaticPort.equals(edge.link().src()) ? 1 : -1;
- }
+ LinkWeight weight = edge -> {
+ // Disregard inactive or non-optical links
+ if (edge.link().state() == Link.State.INACTIVE) {
+ return -1;
+ }
+ if (edge.link().type() != Link.Type.OPTICAL) {
+ return -1;
+ }
+ // Adhere to static port mappings
+ DeviceId srcDeviceId = edge.link().src().deviceId();
+ if (srcDeviceId.equals(intent.getSrc().deviceId())) {
+ ConnectPoint srcStaticPort = staticPort(intent.getSrc());
+ if (srcStaticPort != null) {
+ return srcStaticPort.equals(edge.link().src()) ? 1 : -1;
}
- DeviceId dstDeviceId = edge.link().dst().deviceId();
- if (dstDeviceId.equals(intent.getDst().deviceId())) {
- ConnectPoint dstStaticPort = staticPort(intent.getDst());
- if (dstStaticPort != null) {
- return dstStaticPort.equals(edge.link().dst()) ? 1 : -1;
- }
+ }
+ DeviceId dstDeviceId = edge.link().dst().deviceId();
+ if (dstDeviceId.equals(intent.getDst().deviceId())) {
+ ConnectPoint dstStaticPort = staticPort(intent.getDst());
+ if (dstStaticPort != null) {
+ return dstStaticPort.equals(edge.link().dst()) ? 1 : -1;
}
-
- return 1;
}
+
+ return 1;
};
ConnectPoint start = intent.getSrc();
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java
index a6b08f62..801092f4 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java
@@ -16,12 +16,14 @@
package org.onosproject.net.link.impl;
import static org.slf4j.LoggerFactory.getLogger;
+import static com.google.common.base.Preconditions.checkNotNull;
import java.time.Duration;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.config.ConfigOperator;
import org.onosproject.net.config.basics.BasicLinkConfig;
+import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.Link;
import org.onosproject.net.SparseAnnotations;
@@ -81,6 +83,46 @@ public final class BasicLinkOperator implements ConfigOperator {
if (cfg.bandwidth() != DEF_BANDWIDTH) {
b.set(AnnotationKeys.BANDWIDTH, String.valueOf(cfg.bandwidth()));
}
+ if (cfg.isDurable() != null) {
+ b.set(AnnotationKeys.DURABLE, String.valueOf(cfg.isDurable()));
+ }
return DefaultAnnotations.union(an, b.build());
}
+
+ /**
+ * Generates a link description from a link description entity. The endpoints
+ * must be specified to indicate directionality.
+ *
+ * @param src the source ConnectPoint
+ * @param dst the destination ConnectPoint
+ * @param link the link config entity
+ * @return a linkDescription based on the config
+ */
+ public static LinkDescription descriptionOf(
+ ConnectPoint src, ConnectPoint dst, Link link) {
+ checkNotNull(src, "Must supply a source endpoint");
+ checkNotNull(dst, "Must supply a destination endpoint");
+ checkNotNull(link, "Must supply a link");
+ return new DefaultLinkDescription(
+ src, dst, link.type(), (SparseAnnotations) link.annotations());
+ }
+
+ /**
+ * Generates a link description from a link config entity. This is for
+ * links that cannot be discovered and has to be injected. The endpoints
+ * must be specified to indicate directionality.
+ *
+ * @param src the source ConnectPoint
+ * @param dst the destination ConnectPoint
+ * @param link the link config entity
+ * @return a linkDescription based on the config
+ */
+ public static LinkDescription descriptionOf(
+ ConnectPoint src, ConnectPoint dst, BasicLinkConfig link) {
+ checkNotNull(src, "Must supply a source endpoint");
+ checkNotNull(dst, "Must supply a destination endpoint");
+ checkNotNull(link, "Must supply a link config");
+ return new DefaultLinkDescription(
+ src, dst, link.type(), combine(link, DefaultAnnotations.EMPTY));
+ }
}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java
index 157288a4..d6f72fd9 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java
@@ -15,9 +15,9 @@
*/
package org.onosproject.net.link.impl;
-import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Sets;
+
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
+import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigService;
@@ -54,7 +55,6 @@ import org.slf4j.Logger;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
import static org.onosproject.net.LinkKey.linkKey;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.slf4j.LoggerFactory.getLogger;
@@ -125,13 +125,7 @@ public class LinkManager
public Iterable<Link> getActiveLinks() {
checkPermission(LINK_READ);
return FluentIterable.from(getLinks())
- .filter(new Predicate<Link>() {
-
- @Override
- public boolean apply(Link input) {
- return input.state() == State.ACTIVE;
- }
- });
+ .filter(input -> input.state() == State.ACTIVE);
}
@Override
@@ -207,6 +201,10 @@ public class LinkManager
post(store.removeLink(src, dst));
}
+ private boolean isAllowed(BasicLinkConfig cfg) {
+ return (cfg == null || cfg.isAllowed());
+ }
+
// Auxiliary interceptor for device remove events to prune links that
// are associated with the removed device or its port.
private class InternalDeviceListener implements DeviceListener {
@@ -240,11 +238,12 @@ public class LinkManager
checkNotNull(linkDescription, LINK_DESC_NULL);
checkValidity();
linkDescription = validateLink(linkDescription);
- LinkEvent event = store.createOrUpdateLink(provider().id(),
- linkDescription);
- if (event != null) {
- log.info("Link {} detected", linkDescription);
- post(event);
+ if (linkDescription != null) {
+ LinkEvent event = store.createOrUpdateLink(provider().id(), linkDescription);
+ if (event != null) {
+ log.info("Link {} detected", linkDescription);
+ post(event);
+ }
}
}
@@ -258,11 +257,12 @@ public class LinkManager
BasicLinkConfig cfgTwo = networkConfigService.getConfig(linkKey(linkDescription.dst(),
linkDescription.src()),
BasicLinkConfig.class);
-
- checkState(cfg == null || cfg.isAllowed(), "Link " + linkDescription.toString() + " is not allowed");
- checkState(cfgTwo == null || cfgTwo.isAllowed(), "Link " + linkDescription.toString() + " is not allowed");
-
- return BasicLinkOperator.combine(cfg, linkDescription);
+ if (isAllowed(cfg) && isAllowed(cfgTwo)) {
+ return BasicLinkOperator.combine(cfg, linkDescription);
+ } else {
+ log.trace("Link " + linkDescription.toString() + " is not allowed");
+ return null;
+ }
}
@Override
@@ -324,20 +324,41 @@ public class LinkManager
// listens for NetworkConfigEvents of type BasicLinkConfig and removes
// links that the config does not allow
private class InternalNetworkConfigListener implements NetworkConfigListener {
+
+ @Override
+ public boolean isRelevant(NetworkConfigEvent event) {
+ return event.configClass().equals(BasicLinkConfig.class)
+ && (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
+ || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED);
+ }
+
@Override
public void event(NetworkConfigEvent event) {
- if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
- event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) &&
- event.configClass().equals(BasicLinkConfig.class)) {
- log.info("Detected Link network config event {}", event.type());
- LinkKey lk = (LinkKey) event.subject();
- BasicLinkConfig cfg = networkConfigService.getConfig(lk, BasicLinkConfig.class);
- if (cfg != null && !cfg.isAllowed()) {
- log.info("Kicking out links between {} and {}", lk.src(), lk.dst());
- removeLink(lk.src(), lk.dst());
- removeLink(lk.dst(), lk.src());
- }
+ LinkKey lk = (LinkKey) event.subject();
+ BasicLinkConfig cfg = networkConfigService.getConfig(lk, BasicLinkConfig.class);
+
+ if (!isAllowed(cfg)) {
+ log.info("Kicking out links between {} and {}", lk.src(), lk.dst());
+ removeLink(lk.src(), lk.dst());
+ removeLink(lk.dst(), lk.src());
+ return;
}
+ Link link = getLink(lk.src(), lk.dst());
+ LinkDescription fldesc;
+ LinkDescription rldesc;
+ if (link == null) {
+ fldesc = BasicLinkOperator.descriptionOf(lk.src(), lk.dst(), cfg);
+ rldesc = BasicLinkOperator.descriptionOf(lk.dst(), lk.src(), cfg);
+ } else {
+ fldesc = BasicLinkOperator.combine(cfg,
+ BasicLinkOperator.descriptionOf(lk.src(), lk.dst(), link));
+ rldesc = BasicLinkOperator.combine(cfg,
+ BasicLinkOperator.descriptionOf(lk.dst(), lk.src(), link));
+ }
+ // XXX think of sane way to fetch the LinkProvider
+ store.createOrUpdateLink(ProviderId.NONE, fldesc);
+ store.createOrUpdateLink(ProviderId.NONE, rldesc);
}
+
}
}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java
index 75239fdd..a0bc693c 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.packet.impl;
+import com.google.common.collect.ImmutableMap;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -53,6 +54,7 @@ import org.onosproject.net.provider.AbstractProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.slf4j.Logger;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
@@ -61,8 +63,8 @@ import java.util.concurrent.Executors;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.security.AppGuard.checkPermission;
-import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.security.AppPermission.Type.*;
+import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides a basic implementation of the packet SB &amp; NB APIs.
@@ -138,6 +140,11 @@ public class PacketManager
}
@Override
+ public Map<Integer, PacketProcessor> getProcessors() {
+ return ImmutableMap.copyOf(processors);
+ }
+
+ @Override
public void requestPackets(TrafficSelector selector, PacketPriority priority,
ApplicationId appId) {
checkPermission(PACKET_READ);
@@ -163,6 +170,11 @@ public class PacketManager
}
}
+ @Override
+ public List<PacketRequest> getRequests() {
+ return store.existingRequests();
+ }
+
/**
* Pushes a packet request flow rule to all devices.
*
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/proxyarp/impl/ProxyArpManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/proxyarp/impl/ProxyArpManager.java
index 398260ff..25a2640d 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/proxyarp/impl/ProxyArpManager.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/proxyarp/impl/ProxyArpManager.java
@@ -69,11 +69,9 @@ public class ProxyArpManager implements ProxyArpService {
private final Logger log = getLogger(getClass());
- private static final String MAC_ADDR_NULL = "Mac address cannot be null.";
+ private static final String MAC_ADDR_NULL = "MAC address cannot be null.";
private static final String REQUEST_NULL = "ARP or NDP request cannot be null.";
- private static final String REQUEST_NOT_ARP = "Ethernet frame does not contain ARP request.";
- private static final String NOT_ARP_REQUEST = "ARP is not a request.";
- private static final String NOT_ARP_REPLY = "ARP is not a reply.";
+ private static final String MSG_NOT_REQUEST = "Message is not an ARP or NDP request";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EdgePortService edgeService;
@@ -96,6 +94,14 @@ public class ProxyArpManager implements ProxyArpService {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected InterfaceService interfaceService;
+ private enum Protocol {
+ ARP, NDP
+ }
+
+ private enum MessageType {
+ REQUEST, REPLY
+ }
+
@Activate
public void activate() {
store.setDelegate(this::sendTo);
@@ -123,46 +129,48 @@ public class ProxyArpManager implements ProxyArpService {
checkNotNull(eth, REQUEST_NULL);
- if (eth.getEtherType() == Ethernet.TYPE_ARP) {
- replyArp(eth, inPort);
- } else if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
- replyNdp(eth, inPort);
+ MessageContext context = createContext(eth, inPort);
+ if (context != null) {
+ replyInternal(context);
}
}
- private void replyArp(Ethernet eth, ConnectPoint inPort) {
- ARP arp = (ARP) eth.getPayload();
- checkArgument(arp.getOpCode() == ARP.OP_REQUEST, NOT_ARP_REQUEST);
- checkNotNull(inPort);
- Ip4Address targetAddress = Ip4Address.valueOf(arp.getTargetProtocolAddress());
-
- VlanId vlan = vlanId(eth.getVlanID());
+ /**
+ * Handles a request message.
+ *
+ * If the MAC address of the target is known, we can reply directly to the
+ * requestor. Otherwise, we forward the request out other ports in an
+ * attempt to find the correct host.
+ *
+ * @param context request message context to process
+ */
+ private void replyInternal(MessageContext context) {
+ checkNotNull(context);
+ checkArgument(context.type() == MessageType.REQUEST, MSG_NOT_REQUEST);
- if (hasIpAddress(inPort)) {
+ if (hasIpAddress(context.inPort())) {
// If the request came from outside the network, only reply if it was
// for one of our external addresses.
- interfaceService.getInterfacesByPort(inPort)
+ interfaceService.getInterfacesByPort(context.inPort())
.stream()
.filter(intf -> intf.ipAddresses()
.stream()
- .anyMatch(ia -> ia.ipAddress().equals(targetAddress)))
- .forEach(intf -> buildAndSendArp(targetAddress, intf.mac(), eth, inPort));
+ .anyMatch(ia -> ia.ipAddress().equals(context.target())))
+ .forEach(intf -> buildAndSendReply(context, intf.mac()));
// Stop here and don't proxy ARPs if the port has an IP address
return;
}
// See if we have the target host in the host store
-
- Set<Host> hosts = hostService.getHostsByIp(targetAddress);
+ Set<Host> hosts = hostService.getHostsByIp(context.target());
Host dst = null;
- Host src = hostService.getHost(hostId(eth.getSourceMAC(),
- vlanId(eth.getVlanID())));
+ Host src = hostService.getHost(hostId(context.srcMac(), context.vlan()));
for (Host host : hosts) {
- if (host.vlan().equals(vlan)) {
+ if (host.vlan().equals(context.vlan())) {
dst = host;
break;
}
@@ -170,22 +178,19 @@ public class ProxyArpManager implements ProxyArpService {
if (src != null && dst != null) {
// We know the target host so we can respond
- buildAndSendArp(targetAddress, dst.mac(), eth, inPort);
+ buildAndSendReply(context, dst.mac());
return;
}
// If the source address matches one of our external addresses
// it could be a request from an internal host to an external
// address. Forward it over to the correct port.
- Ip4Address source =
- Ip4Address.valueOf(arp.getSenderProtocolAddress());
-
boolean matched = false;
- Set<Interface> interfaces = interfaceService.getInterfacesByIp(source);
+ Set<Interface> interfaces = interfaceService.getInterfacesByIp(context.sender());
for (Interface intf : interfaces) {
- if (intf.vlan().equals(vlan)) {
+ if (intf.vlan().equals(context.vlan())) {
matched = true;
- sendTo(eth, intf.connectPoint());
+ sendTo(context.packet(), intf.connectPoint());
break;
}
}
@@ -196,89 +201,33 @@ public class ProxyArpManager implements ProxyArpService {
// The request couldn't be resolved.
// Flood the request on all ports except the incoming port.
- flood(eth, inPort);
+ flood(context.packet(), context.inPort());
}
- private void replyNdp(Ethernet eth, ConnectPoint inPort) {
- IPv6 ipv6 = (IPv6) eth.getPayload();
- ICMP6 icmpv6 = (ICMP6) ipv6.getPayload();
- NeighborSolicitation nsol = (NeighborSolicitation) icmpv6.getPayload();
- Ip6Address targetAddress = Ip6Address.valueOf(nsol.getTargetAddress());
-
- VlanId vlan = vlanId(eth.getVlanID());
-
- // If the request came from outside the network, only reply if it was
- // for one of our external addresses.
- if (hasIpAddress(inPort)) {
- interfaceService.getInterfacesByPort(inPort)
- .stream()
- .filter(intf -> intf.ipAddresses()
- .stream()
- .anyMatch(ia -> ia.ipAddress().equals(targetAddress)))
- .forEach(intf -> buildAndSendNdp(targetAddress, intf.mac(), eth, inPort));
- return;
- }
-
- // Continue with normal proxy ARP case
-
- Set<Host> hosts = hostService.getHostsByIp(targetAddress);
-
- Host dst = null;
- Host src = hostService.getHost(hostId(eth.getSourceMAC(),
- vlanId(eth.getVlanID())));
-
- for (Host host : hosts) {
- if (host.vlan().equals(vlan)) {
- dst = host;
- break;
- }
- }
-
- if (src != null && dst != null) {
- // We know the target host so we can respond
- buildAndSendNdp(targetAddress, dst.mac(), eth, inPort);
- return;
- }
-
- // If the source address matches one of our external addresses
- // it could be a request from an internal host to an external
- // address. Forward it over to the correct port.
- Ip6Address source =
- Ip6Address.valueOf(ipv6.getSourceAddress());
-
- boolean matched = false;
-
- Set<Interface> interfaces = interfaceService.getInterfacesByIp(source);
- for (Interface intf : interfaces) {
- if (intf.vlan().equals(vlan)) {
- matched = true;
- sendTo(eth, intf.connectPoint());
- break;
- }
- }
-
- if (matched) {
- return;
+ /**
+ * Builds and sends a reply message given a request context and the resolved
+ * MAC address to answer with.
+ *
+ * @param context message context of request
+ * @param targetMac MAC address to be given in the response
+ */
+ private void buildAndSendReply(MessageContext context, MacAddress targetMac) {
+ switch (context.protocol()) {
+ case ARP:
+ sendTo(ARP.buildArpReply((Ip4Address) context.target(),
+ targetMac, context.packet()), context.inPort());
+ break;
+ case NDP:
+ sendTo(buildNdpReply((Ip6Address) context.target(), targetMac,
+ context.packet()), context.inPort());
+ break;
+ default:
+ break;
}
-
- // The request couldn't be resolved.
- // Flood the request on all ports except the incoming ports.
- flood(eth, inPort);
- }
- //TODO checkpoint
-
- private void buildAndSendArp(Ip4Address srcIp, MacAddress srcMac,
- Ethernet request, ConnectPoint port) {
- sendTo(ARP.buildArpReply(srcIp, srcMac, request), port);
- }
-
- private void buildAndSendNdp(Ip6Address srcIp, MacAddress srcMac,
- Ethernet request, ConnectPoint port) {
- sendTo(buildNdpReply(srcIp, srcMac, request), port);
}
/**
- * Outputs the given packet out the given port.
+ * Outputs a packet out a specific port.
*
* @param packet the packet to send
* @param outPort the port to send it out
@@ -287,6 +236,12 @@ public class ProxyArpManager implements ProxyArpService {
sendTo(outPort, ByteBuffer.wrap(packet.serialize()));
}
+ /**
+ * Outputs a packet out a specific port.
+ *
+ * @param outPort port to send it out
+ * @param packet packet to send
+ */
private void sendTo(ConnectPoint outPort, ByteBuffer packet) {
if (!edgeService.isEdgePoint(outPort)) {
// Sanity check to make sure we don't send the packet out an
@@ -298,7 +253,7 @@ public class ProxyArpManager implements ProxyArpService {
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
builder.setOutput(outPort.port());
packetService.emit(new DefaultOutboundPacket(outPort.deviceId(),
- builder.build(), packet));
+ builder.build(), packet));
}
/**
@@ -323,7 +278,7 @@ public class ProxyArpManager implements ProxyArpService {
checkNotNull(eth, REQUEST_NULL);
Host h = hostService.getHost(hostId(eth.getDestinationMAC(),
- vlanId(eth.getVlanID())));
+ vlanId(eth.getVlanID())));
if (h == null) {
flood(eth, inPort);
@@ -344,42 +299,24 @@ public class ProxyArpManager implements ProxyArpService {
if (ethPkt == null) {
return false;
}
- if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
- return handleArp(context, ethPkt);
- } else if (ethPkt.getEtherType() == Ethernet.TYPE_IPV6) {
- return handleNdp(context, ethPkt);
- }
- return false;
- }
- private boolean handleArp(PacketContext context, Ethernet ethPkt) {
- ARP arp = (ARP) ethPkt.getPayload();
+ MessageContext msgContext = createContext(ethPkt, pkt.receivedFrom());
- if (arp.getOpCode() == ARP.OP_REPLY) {
- forward(ethPkt, context.inPacket().receivedFrom());
- } else if (arp.getOpCode() == ARP.OP_REQUEST) {
- reply(ethPkt, context.inPacket().receivedFrom());
- } else {
+ if (msgContext == null) {
return false;
}
- context.block();
- return true;
- }
- private boolean handleNdp(PacketContext context, Ethernet ethPkt) {
- IPv6 ipv6 = (IPv6) ethPkt.getPayload();
-
- if (ipv6.getNextHeader() != IPv6.PROTOCOL_ICMP6) {
- return false;
- }
- ICMP6 icmpv6 = (ICMP6) ipv6.getPayload();
- if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_ADVERTISEMENT) {
- forward(ethPkt, context.inPacket().receivedFrom());
- } else if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_SOLICITATION) {
- reply(ethPkt, context.inPacket().receivedFrom());
- } else {
+ switch (msgContext.type()) {
+ case REPLY:
+ forward(msgContext.packet(), msgContext.inPort());
+ break;
+ case REQUEST:
+ replyInternal(msgContext);
+ break;
+ default:
return false;
}
+
context.block();
return true;
}
@@ -444,4 +381,148 @@ public class ProxyArpManager implements ProxyArpService {
eth.setPayload(ipv6);
return eth;
}
+
+ /**
+ * Attempts to create a MessageContext for the given Ethernet frame. If the
+ * frame is a valid ARP or NDP request or response, a context will be
+ * created.
+ *
+ * @param eth input Ethernet frame
+ * @param inPort in port
+ * @return MessageContext if the packet was ARP or NDP, otherwise null
+ */
+ private MessageContext createContext(Ethernet eth, ConnectPoint inPort) {
+ if (eth.getEtherType() == Ethernet.TYPE_ARP) {
+ return createArpContext(eth, inPort);
+ } else if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
+ return createNdpContext(eth, inPort);
+ }
+
+ return null;
+ }
+
+ /**
+ * Extracts context information from ARP packets.
+ *
+ * @param eth input Ethernet frame that is thought to be ARP
+ * @param inPort in port
+ * @return MessageContext object if the packet was a valid ARP packet,
+ * otherwise null
+ */
+ private MessageContext createArpContext(Ethernet eth, ConnectPoint inPort) {
+ if (eth.getEtherType() != Ethernet.TYPE_ARP) {
+ return null;
+ }
+
+ ARP arp = (ARP) eth.getPayload();
+
+ IpAddress target = Ip4Address.valueOf(arp.getTargetProtocolAddress());
+ IpAddress sender = Ip4Address.valueOf(arp.getSenderProtocolAddress());
+
+ MessageType type;
+ if (arp.getOpCode() == ARP.OP_REQUEST) {
+ type = MessageType.REQUEST;
+ } else if (arp.getOpCode() == ARP.OP_REPLY) {
+ type = MessageType.REPLY;
+ } else {
+ return null;
+ }
+
+ return new MessageContext(eth, inPort, Protocol.ARP, type, target, sender);
+ }
+
+ /**
+ * Extracts context information from NDP packets.
+ *
+ * @param eth input Ethernet frame that is thought to be NDP
+ * @param inPort in port
+ * @return MessageContext object if the packet was a valid NDP packet,
+ * otherwise null
+ */
+ private MessageContext createNdpContext(Ethernet eth, ConnectPoint inPort) {
+ if (eth.getEtherType() != Ethernet.TYPE_IPV6) {
+ return null;
+ }
+ IPv6 ipv6 = (IPv6) eth.getPayload();
+
+ if (ipv6.getNextHeader() != IPv6.PROTOCOL_ICMP6) {
+ return null;
+ }
+ ICMP6 icmpv6 = (ICMP6) ipv6.getPayload();
+
+ IpAddress sender = Ip6Address.valueOf(ipv6.getSourceAddress());
+ IpAddress target = null;
+
+ MessageType type;
+ if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_SOLICITATION) {
+ type = MessageType.REQUEST;
+ NeighborSolicitation nsol = (NeighborSolicitation) icmpv6.getPayload();
+ target = Ip6Address.valueOf(nsol.getTargetAddress());
+ } else if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_ADVERTISEMENT) {
+ type = MessageType.REPLY;
+ } else {
+ return null;
+ }
+
+ return new MessageContext(eth, inPort, Protocol.NDP, type, target, sender);
+ }
+
+ /**
+ * Provides context information for a particular ARP or NDP message, with
+ * a unified interface to access data regardless of protocol.
+ */
+ private class MessageContext {
+ private Protocol protocol;
+ private MessageType type;
+
+ private IpAddress target;
+ private IpAddress sender;
+
+ private Ethernet eth;
+ private ConnectPoint inPort;
+
+
+ public MessageContext(Ethernet eth, ConnectPoint inPort,
+ Protocol protocol, MessageType type,
+ IpAddress target, IpAddress sender) {
+ this.eth = eth;
+ this.inPort = inPort;
+ this.protocol = protocol;
+ this.type = type;
+ this.target = target;
+ this.sender = sender;
+ }
+
+ public ConnectPoint inPort() {
+ return inPort;
+ }
+
+ public Ethernet packet() {
+ return eth;
+ }
+
+ public Protocol protocol() {
+ return protocol;
+ }
+
+ public MessageType type() {
+ return type;
+ }
+
+ public VlanId vlan() {
+ return VlanId.vlanId(eth.getVlanID());
+ }
+
+ public MacAddress srcMac() {
+ return MacAddress.valueOf(eth.getSourceMACAddress());
+ }
+
+ public IpAddress target() {
+ return target;
+ }
+
+ public IpAddress sender() {
+ return sender;
+ }
+ }
}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/statistic/impl/StatisticManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/statistic/impl/StatisticManager.java
index 996ad14e..57964d69 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/statistic/impl/StatisticManager.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/statistic/impl/StatisticManager.java
@@ -348,12 +348,7 @@ public class StatisticManager implements StatisticService {
* @return predicate
*/
private static Predicate<FlowEntry> hasApplicationId(ApplicationId appId) {
- return new Predicate<FlowEntry>() {
- @Override
- public boolean apply(FlowEntry flowEntry) {
- return flowEntry.appId() == appId.id();
- }
- };
+ return flowEntry -> flowEntry.appId() == appId.id();
}
/**
@@ -364,16 +359,13 @@ public class StatisticManager implements StatisticService {
* @return predicate
*/
private static Predicate<FlowEntry> hasGroupId(Optional<GroupId> groupId) {
- return new Predicate<FlowEntry>() {
- @Override
- public boolean apply(FlowEntry flowEntry) {
- if (!groupId.isPresent()) {
- return false;
- }
- // FIXME: The left hand type and right hand type don't match
- // FlowEntry.groupId() still returns a short value, not int.
- return flowEntry.groupId().equals(groupId.get());
+ return flowEntry -> {
+ if (!groupId.isPresent()) {
+ return false;
}
+ // FIXME: The left hand type and right hand type don't match
+ // FlowEntry.groupId() still returns a short value, not int.
+ return flowEntry.groupId().equals(groupId.get());
};
}
}