From 6a07d2d622eaa06953f3353e39c080984076e8de Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Fri, 9 Oct 2015 18:32:44 -0700 Subject: Updated master to commit id 6ee8aa3e67ce89908a8c93aa9445c6f71a18f986 Change-Id: I94b055ee2f298daf71e2ec794fd0f2495bd8081f --- .../incubator/net/intf/impl/InterfaceManager.java | 52 ++++- .../incubator/net/mcast/impl/MulticastData.java | 85 ++++++++ .../net/mcast/impl/MulticastRouteManager.java | 174 ++++++++++++++++ .../incubator/net/mcast/impl/package-info.java | 20 ++ .../incubator/net/meter/impl/MeterManager.java | 37 +++- .../net/virtual/impl/VirtualNetworkManager.java | 223 +++++++++++++++++++++ .../incubator/net/virtual/impl/package-info.java | 20 ++ .../net/mcast/impl/MulticastRouteManagerTest.java | 200 ++++++++++++++++++ .../incubator/net/meter/impl/MeterManagerTest.java | 15 +- 9 files changed, 811 insertions(+), 15 deletions(-) create mode 100644 framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/MulticastData.java create mode 100644 framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManager.java create mode 100644 framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/package-info.java create mode 100644 framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java create mode 100644 framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/package-info.java create mode 100644 framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManagerTest.java (limited to 'framework/src/onos/incubator/net') diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/InterfaceManager.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/InterfaceManager.java index f82cdbf2..0439d038 100644 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/InterfaceManager.java +++ b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/InterfaceManager.java @@ -29,6 +29,7 @@ import org.onlab.packet.VlanId; import org.onosproject.incubator.net.config.basics.ConfigException; import org.onosproject.incubator.net.config.basics.InterfaceConfig; import org.onosproject.incubator.net.intf.Interface; +import org.onosproject.incubator.net.intf.InterfaceAdminService; import org.onosproject.incubator.net.intf.InterfaceService; import org.onosproject.net.ConnectPoint; import org.onosproject.net.config.NetworkConfigEvent; @@ -50,7 +51,8 @@ import static java.util.stream.Collectors.toSet; */ @Service @Component(immediate = true) -public class InterfaceManager implements InterfaceService { +public class InterfaceManager implements InterfaceService, + InterfaceAdminService { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -153,6 +155,54 @@ public class InterfaceManager implements InterfaceService { interfaces.remove(port); } + @Override + public void add(Interface intf) { + if (interfaces.containsKey(intf.connectPoint())) { + boolean conflict = interfaces.get(intf.connectPoint()).stream() + .filter(i -> i.connectPoint().equals(intf.connectPoint())) + .filter(i -> i.mac().equals(intf.mac())) + .filter(i -> i.vlan().equals(intf.vlan())) + .findAny().isPresent(); + + if (conflict) { + log.error("Can't add interface because it conflicts with existing config"); + return; + } + } + + InterfaceConfig config = + configService.addConfig(intf.connectPoint(), CONFIG_CLASS); + + config.addInterface(intf); + + configService.applyConfig(intf.connectPoint(), CONFIG_CLASS, config.node()); + } + + @Override + public void remove(ConnectPoint connectPoint, VlanId vlanId) { + Optional intf = interfaces.get(connectPoint).stream() + .filter(i -> i.vlan().equals(vlanId)) + .findAny(); + + if (!intf.isPresent()) { + log.error("Can't find interface {}/{} to remove", connectPoint, vlanId); + return; + } + + InterfaceConfig config = configService.addConfig(intf.get().connectPoint(), CONFIG_CLASS); + config.removeInterface(intf.get()); + + try { + if (config.getInterfaces().isEmpty()) { + configService.removeConfig(connectPoint, CONFIG_CLASS); + } else { + configService.applyConfig(intf.get().connectPoint(), CONFIG_CLASS, config.node()); + } + } catch (ConfigException e) { + log.error("Error reading interfaces JSON", e); + } + } + /** * Listener for network config events. */ diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/MulticastData.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/MulticastData.java new file mode 100644 index 00000000..946d8c6e --- /dev/null +++ b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/MulticastData.java @@ -0,0 +1,85 @@ +/* + * 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.incubator.net.mcast.impl; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import org.onosproject.net.ConnectPoint; + +import java.util.Collections; +import java.util.List; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Simple entity maintaining a mapping between a source and a collection of sink + * connect points. + */ +public final class MulticastData { + + private final ConnectPoint source; + private final List sinks; + private final boolean isEmpty; + + private MulticastData() { + this.source = null; + this.sinks = Collections.EMPTY_LIST; + isEmpty = true; + } + + public MulticastData(ConnectPoint source, List sinks) { + this.source = checkNotNull(source, "Multicast source cannot be null."); + this.sinks = checkNotNull(sinks, "List of sinks cannot be null."); + isEmpty = false; + } + + public MulticastData(ConnectPoint source, ConnectPoint sink) { + this.source = checkNotNull(source, "Multicast source cannot be null."); + this.sinks = Lists.newArrayList(checkNotNull(sink, "Sink cannot be null.")); + isEmpty = false; + } + + public MulticastData(ConnectPoint source) { + this.source = checkNotNull(source, "Multicast source cannot be null."); + this.sinks = Lists.newArrayList(); + isEmpty = false; + } + + public ConnectPoint source() { + return source; + } + + public List sinks() { + return ImmutableList.copyOf(sinks); + } + + public void appendSink(ConnectPoint sink) { + sinks.add(sink); + } + + public boolean removeSink(ConnectPoint sink) { + return sinks.remove(sink); + } + + public boolean isEmpty() { + return isEmpty; + } + + public static MulticastData empty() { + return new MulticastData(); + } + +} diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManager.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManager.java new file mode 100644 index 00000000..f73dfe44 --- /dev/null +++ b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManager.java @@ -0,0 +1,174 @@ +/* + * 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.incubator.net.mcast.impl; + +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.Reference; +import org.apache.felix.scr.annotations.ReferenceCardinality; +import org.apache.felix.scr.annotations.Service; +import org.onlab.packet.IpPrefix; +import org.onlab.util.KryoNamespace; +import org.onosproject.core.ApplicationId; +import org.onosproject.core.CoreService; +import org.onosproject.event.AbstractListenerManager; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.mcast.McastEvent; +import org.onosproject.net.mcast.McastListener; +import org.onosproject.net.mcast.McastRoute; +import org.onosproject.net.mcast.MulticastRouteService; +import org.onosproject.store.service.ConsistentMap; +import org.onosproject.store.service.Serializer; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.Versioned; +import org.slf4j.Logger; + +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; + +import static org.slf4j.LoggerFactory.getLogger; + +/** + * An implementation of a multicast route table. + */ +@Component(immediate = true) +@Service +public class MulticastRouteManager + extends AbstractListenerManager + implements MulticastRouteService { + //TODO: add MulticastRouteAdminService + + private static final String MCASTRIB = "mcast-rib-table"; + + private Logger log = getLogger(getClass()); + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + private StorageService storageService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + private CoreService coreService; + + + protected ApplicationId appId; + protected ConsistentMap mcastRoutes; + + @Activate + public void activate() { + + eventDispatcher.addSink(McastEvent.class, listenerRegistry); + + appId = coreService.registerApplication("org.onosproject.mcastrib"); + + mcastRoutes = storageService.consistentMapBuilder() + .withApplicationId(appId) + .withName(MCASTRIB) + .withSerializer(Serializer.using(KryoNamespace.newBuilder().register( + MulticastData.class, + McastRoute.class, + McastRoute.Type.class, + IpPrefix.class, + List.class, + ConnectPoint.class + ).build())).build(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + log.info("Stopped"); + } + + @Override + public void add(McastRoute route) { + mcastRoutes.put(route, MulticastData.empty()); + post(new McastEvent(McastEvent.Type.ROUTE_ADDED, route, null, null)); + } + + @Override + public void remove(McastRoute route) { + mcastRoutes.remove(route); + post(new McastEvent(McastEvent.Type.ROUTE_REMOVED, route, null, null)); + } + + @Override + public void addSource(McastRoute route, ConnectPoint connectPoint) { + Versioned d = mcastRoutes.compute(route, (k, v) -> { + if (v.isEmpty()) { + return new MulticastData(connectPoint); + } else { + log.warn("Route {} is already in use.", route); + return v; + } + }); + + if (d != null) { + post(new McastEvent(McastEvent.Type.SOURCE_ADDED, + route, null, connectPoint)); + } + } + + @Override + public void addSink(McastRoute route, ConnectPoint connectPoint) { + AtomicReference source = new AtomicReference<>(); + mcastRoutes.compute(route, (k, v) -> { + if (!v.isEmpty()) { + v.appendSink(connectPoint); + source.set(v.source()); + } else { + log.warn("Route {} does not exist"); + } + return v; + }); + + if (source.get() != null) { + post(new McastEvent(McastEvent.Type.SINK_ADDED, route, + connectPoint, source.get())); + } + } + + + @Override + public void removeSink(McastRoute route, ConnectPoint connectPoint) { + AtomicReference source = new AtomicReference<>(); + mcastRoutes.compute(route, (k, v) -> { + if (v.removeSink(connectPoint)) { + source.set(v.source()); + } + return v; + }); + + if (source.get() != null) { + post(new McastEvent(McastEvent.Type.SINK_REMOVED, route, + connectPoint, source.get())); + } + } + + @Override + public ConnectPoint fetchSource(McastRoute route) { + MulticastData d = mcastRoutes.asJavaMap().getOrDefault(route, + MulticastData.empty()); + return d.source(); + } + + @Override + public List fetchSinks(McastRoute route) { + MulticastData d = mcastRoutes.asJavaMap().getOrDefault(route, + MulticastData.empty()); + return d.sinks(); + } +} diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/package-info.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/package-info.java new file mode 100644 index 00000000..464cf701 --- /dev/null +++ b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ + +/** + * An implementation of a multicast RIB. + */ +package org.onosproject.incubator.net.mcast.impl; \ No newline at end of file diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/MeterManager.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/MeterManager.java index 575a7153..5c5c11cd 100644 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/MeterManager.java +++ b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/MeterManager.java @@ -15,6 +15,7 @@ */ package org.onosproject.incubator.net.meter.impl; +import com.google.common.collect.Maps; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; @@ -27,6 +28,7 @@ import org.onosproject.net.meter.Meter; import org.onosproject.net.meter.MeterEvent; import org.onosproject.net.meter.MeterFailReason; import org.onosproject.net.meter.MeterId; +import org.onosproject.net.meter.MeterKey; import org.onosproject.net.meter.MeterListener; import org.onosproject.net.meter.MeterOperation; import org.onosproject.net.meter.MeterProvider; @@ -61,7 +63,7 @@ public class MeterManager extends AbstractListenerProviderRegistry implements MeterService, MeterProviderRegistry { - private final String meterIdentifier = "meter-id-counter"; + private static final String METERCOUNTERIDENTIFIER = "meter-id-counter-%s"; private final Logger log = getLogger(getClass()); private final MeterStoreDelegate delegate = new InternalMeterStoreDelegate(); @@ -71,15 +73,13 @@ public class MeterManager extends AbstractListenerProviderRegistry meterIdCounters + = Maps.newConcurrentMap(); private TriConsumer onComplete; @Activate public void activate() { - meterIdCounter = storageService.atomicCounterBuilder() - .withName(meterIdentifier) - .build(); store.setDelegate(delegate); @@ -115,11 +115,13 @@ public class MeterManager extends AbstractListenerProviderRegistry { + if (v == null) { + return allocateCounter(k); + } + return v; + }).incrementAndGet(); + + return MeterId.meterId((int) id); + } + + private AtomicCounter allocateCounter(DeviceId deviceId) { + return storageService.atomicCounterBuilder() + .withName(String.format(METERCOUNTERIDENTIFIER, deviceId)) + .build(); } private class InternalMeterProviderService diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java new file mode 100644 index 00000000..fe9f8841 --- /dev/null +++ b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java @@ -0,0 +1,223 @@ +/* + * 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.incubator.net.virtual.impl; + +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.Reference; +import org.apache.felix.scr.annotations.ReferenceCardinality; +import org.apache.felix.scr.annotations.Service; +import org.onosproject.incubator.net.tunnel.TunnelId; +import org.onosproject.incubator.net.virtual.NetworkId; +import org.onosproject.incubator.net.virtual.TenantId; +import org.onosproject.incubator.net.virtual.VirtualDevice; +import org.onosproject.incubator.net.virtual.VirtualLink; +import org.onosproject.incubator.net.virtual.VirtualNetwork; +import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService; +import org.onosproject.incubator.net.virtual.VirtualNetworkEvent; +import org.onosproject.incubator.net.virtual.VirtualNetworkListener; +import org.onosproject.incubator.net.virtual.VirtualNetworkProvider; +import org.onosproject.incubator.net.virtual.VirtualNetworkProviderRegistry; +import org.onosproject.incubator.net.virtual.VirtualNetworkProviderService; +import org.onosproject.incubator.net.virtual.VirtualNetworkService; +import org.onosproject.incubator.net.virtual.VirtualNetworkStore; +import org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate; +import org.onosproject.incubator.net.virtual.VirtualPort; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.DeviceId; +import org.onosproject.net.Port; +import org.onosproject.net.PortNumber; +import org.onosproject.net.provider.AbstractListenerProviderRegistry; +import org.onosproject.net.provider.AbstractProviderService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Implementation of the virtual network service. + */ +@Component(immediate = true) +@Service +public class VirtualNetworkManager + extends AbstractListenerProviderRegistry + implements VirtualNetworkService, VirtualNetworkAdminService, VirtualNetworkProviderRegistry { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + private static final String TENANT_NULL = "Tenant ID cannot be null"; + private static final String NETWORK_NULL = "Network ID cannot be null"; + private static final String DEVICE_NULL = "Device ID cannot be null"; + private static final String LINK_POINT_NULL = "Link end-point cannot be null"; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected VirtualNetworkStore store; + + private VirtualNetworkStoreDelegate delegate = new InternalStoreDelegate(); + + // TODO: figure out how to coordinate "implementation" of a virtual network in a cluster + + @Activate + protected void activate() { + store.setDelegate(delegate); + log.info("Started"); + } + + @Deactivate + protected void deactivate() { + store.unsetDelegate(delegate); + log.info("Stopped"); + } + + @Override + public void registerTenantId(TenantId tenantId) { + checkNotNull(tenantId, TENANT_NULL); + store.addTenantId(tenantId); + } + + @Override + public void unregisterTenantId(TenantId tenantId) { + checkNotNull(tenantId, TENANT_NULL); + store.removeTenantId(tenantId); + } + + @Override + public Set getTenantIds() { + return store.getTenantIds(); + } + + @Override + public VirtualNetwork createVirtualNetwork(TenantId tenantId) { + checkNotNull(tenantId, TENANT_NULL); + return store.addNetwork(tenantId); + } + + @Override + public void removeVirtualNetwork(NetworkId networkId) { + checkNotNull(networkId, NETWORK_NULL); + store.removeNetwork(networkId); + } + + @Override + public VirtualDevice createVirtualDevice(NetworkId networkId, DeviceId deviceId) { + checkNotNull(networkId, NETWORK_NULL); + checkNotNull(deviceId, DEVICE_NULL); + return store.addDevice(networkId, deviceId); + } + + @Override + public void removeVirtualDevice(NetworkId networkId, DeviceId deviceId) { + checkNotNull(networkId, NETWORK_NULL); + checkNotNull(deviceId, DEVICE_NULL); + store.removeDevice(networkId, deviceId); + } + + @Override + public VirtualLink createVirtualLink(NetworkId networkId, + ConnectPoint src, ConnectPoint dst, + TunnelId realizedBy) { + checkNotNull(networkId, NETWORK_NULL); + checkNotNull(src, LINK_POINT_NULL); + checkNotNull(dst, LINK_POINT_NULL); + checkNotNull(realizedBy, "Tunnel ID cannot be null"); + return store.addLink(networkId, src, dst, realizedBy); + } + + @Override + public void removeVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { + checkNotNull(networkId, NETWORK_NULL); + checkNotNull(src, LINK_POINT_NULL); + checkNotNull(dst, LINK_POINT_NULL); + store.removeLink(networkId, src, dst); + } + + @Override + public VirtualPort createVirtualPort(NetworkId networkId, DeviceId deviceId, + PortNumber portNumber, Port realizedBy) { + checkNotNull(networkId, NETWORK_NULL); + checkNotNull(deviceId, DEVICE_NULL); + checkNotNull(portNumber, "Port description cannot be null"); + return store.addPort(networkId, deviceId, portNumber, realizedBy); + } + + @Override + public void removeVirtualPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) { + checkNotNull(networkId, NETWORK_NULL); + checkNotNull(deviceId, DEVICE_NULL); + checkNotNull(portNumber, "Port number cannot be null"); + store.removePort(networkId, deviceId, portNumber); + } + + @Override + public Set getVirtualNetworks(TenantId tenantId) { + checkNotNull(tenantId, TENANT_NULL); + return store.getNetworks(tenantId); + } + + @Override + public Set getVirtualDevices(NetworkId networkId) { + checkNotNull(networkId, NETWORK_NULL); + return store.getDevices(networkId); + } + + @Override + public Set getVirtualLinks(NetworkId networkId) { + checkNotNull(networkId, NETWORK_NULL); + return store.getLinks(networkId); + } + + @Override + public Set getVirtualPorts(NetworkId networkId, DeviceId deviceId) { + checkNotNull(networkId, NETWORK_NULL); + checkNotNull(deviceId, DEVICE_NULL); + return store.getPorts(networkId, deviceId); + } + + @Override + public T get(NetworkId networkId, Class serviceClass) { + checkNotNull(networkId, NETWORK_NULL); + return null; + } + + @Override + protected VirtualNetworkProviderService createProviderService(VirtualNetworkProvider provider) { + return new InternalVirtualNetworkProviderService(provider); + } + + // Service issued to registered virtual network providers so that they + // can interact with the core. + private class InternalVirtualNetworkProviderService + extends AbstractProviderService + implements VirtualNetworkProviderService { + InternalVirtualNetworkProviderService(VirtualNetworkProvider provider) { + super(provider); + } + } + + // Auxiliary store delegate to receive notification about changes in + // the virtual network configuration store state - by the store itself. + private class InternalStoreDelegate implements VirtualNetworkStoreDelegate { + @Override + public void notify(VirtualNetworkEvent event) { + post(event); + } + } + +} diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/package-info.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/package-info.java new file mode 100644 index 00000000..da4be5aa --- /dev/null +++ b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ + +/** + * Implementation of the virtual network subsystem. + */ +package org.onosproject.incubator.net.virtual.impl; \ No newline at end of file diff --git a/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManagerTest.java b/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManagerTest.java new file mode 100644 index 00000000..545e21d0 --- /dev/null +++ b/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManagerTest.java @@ -0,0 +1,200 @@ +/* + * 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.incubator.net.mcast.impl; + +import com.google.common.collect.Lists; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onlab.junit.TestUtils; +import org.onlab.packet.IpPrefix; +import org.onosproject.common.event.impl.TestEventDispatcher; +import org.onosproject.core.ApplicationId; +import org.onosproject.core.CoreService; +import org.onosproject.core.DefaultApplicationId; +import org.onosproject.core.IdGenerator; +import org.onosproject.core.Version; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.PortNumber; +import org.onosproject.net.mcast.McastEvent; +import org.onosproject.net.mcast.McastListener; +import org.onosproject.net.mcast.McastRoute; +import org.onosproject.store.service.TestStorageService; + +import java.util.List; +import java.util.Set; + +import static junit.framework.Assert.fail; +import static junit.framework.TestCase.assertEquals; +import static org.onosproject.net.NetTestTools.did; +import static org.onosproject.net.NetTestTools.injectEventDispatcher; + +/** + * Tests for the multicast RIB. + */ +public class MulticastRouteManagerTest { + + McastRoute r1 = new McastRoute(IpPrefix.valueOf("1.1.1.1/8"), + IpPrefix.valueOf("1.1.1.2/8"), + McastRoute.Type.IGMP); + + McastRoute r11 = new McastRoute(IpPrefix.valueOf("1.1.1.1/8"), + IpPrefix.valueOf("1.1.1.2/8"), + McastRoute.Type.STATIC); + + McastRoute r2 = new McastRoute(IpPrefix.valueOf("2.2.2.1/8"), + IpPrefix.valueOf("2.2.2.2/8"), + McastRoute.Type.PIM); + + ConnectPoint cp1 = new ConnectPoint(did("1"), PortNumber.portNumber(1)); + + ConnectPoint cp2 = new ConnectPoint(did("2"), PortNumber.portNumber(2)); + + private TestMulticastListener listener = new TestMulticastListener(); + + private MulticastRouteManager manager; + + private List events; + + @Before + public void setUp() throws Exception { + manager = new MulticastRouteManager(); + injectEventDispatcher(manager, new TestEventDispatcher()); + TestUtils.setField(manager, "storageService", new TestStorageService()); + TestUtils.setField(manager, "coreService", new TestCoreService()); + events = Lists.newArrayList(); + manager.activate(); + manager.addListener(listener); + } + + @After + public void tearDown() { + manager.removeListener(listener); + manager.deactivate(); + } + + @Test + public void testAdd() { + manager.add(r1); + + assertEquals("Add failed", manager.mcastRoutes.size(), 1); + validateEvents(McastEvent.Type.ROUTE_ADDED); + } + + @Test + public void testRemove() { + manager.add(r1); + + manager.remove(r1); + + assertEquals("Remove failed", manager.mcastRoutes.size(), 0); + validateEvents(McastEvent.Type.ROUTE_ADDED, McastEvent.Type.ROUTE_REMOVED); + } + + @Test + public void testAddSource() { + manager.add(r1); + + manager.addSource(r1, cp1); + + validateEvents(McastEvent.Type.ROUTE_ADDED, McastEvent.Type.SOURCE_ADDED); + assertEquals("Route is not equal", cp1, manager.fetchSource(r1)); + } + + @Test + public void testAddSink() { + manager.add(r1); + + manager.addSource(r1, cp1); + manager.addSink(r1, cp1); + + validateEvents(McastEvent.Type.ROUTE_ADDED, + McastEvent.Type.SOURCE_ADDED, + McastEvent.Type.SINK_ADDED); + assertEquals("Route is not equal", Lists.newArrayList(cp1), manager.fetchSinks(r1)); + } + + @Test + public void testRemoveSink() { + manager.add(r1); + + manager.addSource(r1, cp1); + manager.addSink(r1, cp1); + manager.addSink(r1, cp2); + manager.removeSink(r1, cp2); + + validateEvents(McastEvent.Type.ROUTE_ADDED, + McastEvent.Type.SOURCE_ADDED, + McastEvent.Type.SINK_ADDED, + McastEvent.Type.SINK_ADDED, + McastEvent.Type.SINK_REMOVED); + assertEquals("Route is not equal", Lists.newArrayList(cp1), manager.fetchSinks(r1)); + } + + private void validateEvents(McastEvent.Type... evs) { + if (events.size() != evs.length) { + fail(String.format("Mismatch number of events# obtained -> %s : expected %s", + events, evs)); + } + + for (int i = 0; i < evs.length; i++) { + if (evs[i] != events.get(i).type()) { + fail(String.format("Mismtached events# obtained -> %s : expected %s", + events, evs)); + } + } + } + + class TestMulticastListener implements McastListener { + + @Override + public void event(McastEvent event) { + events.add(event); + } + } + + private class TestCoreService implements CoreService { + @Override + public Version version() { + return null; + } + + @Override + public Set getAppIds() { + return null; + } + + @Override + public ApplicationId getAppId(Short id) { + return null; + } + + @Override + public ApplicationId getAppId(String name) { + return null; + } + + @Override + public ApplicationId registerApplication(String identifier) { + return new DefaultApplicationId(0, identifier); + } + + @Override + public IdGenerator getIdGenerator(String topic) { + return null; + } + } +} diff --git a/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/meter/impl/MeterManagerTest.java b/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/meter/impl/MeterManagerTest.java index e0c0c868..76caebcb 100644 --- a/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/meter/impl/MeterManagerTest.java +++ b/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/meter/impl/MeterManagerTest.java @@ -130,7 +130,7 @@ public class MeterManagerTest { m2 = DefaultMeter.builder() .forDevice(did("2")) .fromApp(APP_ID) - .withId(MeterId.meterId(2)) + .withId(MeterId.meterId(1)) .withUnit(Meter.Unit.KB_PER_SEC) .withBands(Collections.singletonList(band)) .build(); @@ -167,7 +167,7 @@ public class MeterManagerTest { assertTrue("The meter was not added", manager.getAllMeters().size() == 1); - assertThat(manager.getMeter(MeterId.meterId(1)), is(m1)); + assertThat(manager.getMeter(did("1"), MeterId.meterId(1)), is(m1)); } @Test @@ -175,7 +175,7 @@ public class MeterManagerTest { manager.submit(m1Request.add()); manager.withdraw(m1Request.remove(), m1.id()); - assertThat(manager.getMeter(MeterId.meterId(1)).state(), + assertThat(manager.getMeter(did("1"), MeterId.meterId(1)).state(), is(MeterState.PENDING_REMOVE)); providerService.pushMeterMetrics(m1.deviceId(), Collections.emptyList()); @@ -184,7 +184,16 @@ public class MeterManagerTest { } + @Test + public void testMultipleDevice() { + manager.submit(m1Request.add()); + manager.submit(m2Request.add()); + assertTrue("The meters were not added", manager.getAllMeters().size() == 2); + + assertThat(manager.getMeter(did("1"), MeterId.meterId(1)), is(m1)); + assertThat(manager.getMeter(did("2"), MeterId.meterId(1)), is(m2)); + } public class TestApplicationId extends DefaultApplicationId { public TestApplicationId(int id, String name) { -- cgit 1.2.3-korg