diff options
Diffstat (limited to 'framework/src/onos/incubator/net/src')
24 files changed, 0 insertions, 2987 deletions
diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/config/impl/ExtraNetworkConfigs.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/config/impl/ExtraNetworkConfigs.java deleted file mode 100644 index e77e1da0..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/config/impl/ExtraNetworkConfigs.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.incubator.net.config.impl; - -import com.google.common.collect.ImmutableSet; -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.onosproject.incubator.net.domain.IntentDomainConfig; -import org.onosproject.incubator.net.domain.IntentDomainId; -import org.onosproject.net.config.ConfigFactory; -import org.onosproject.net.config.NetworkConfigRegistry; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Set; - -import static org.onosproject.incubator.net.config.basics.ExtraSubjectFactories.INTENT_DOMAIN_SUBJECT_FACTORY; - -/** - * Component for registration of builtin basic network configurations. - */ -@Component(immediate = true) -public class ExtraNetworkConfigs { - - private final Logger log = LoggerFactory.getLogger(getClass()); - - private final Set<ConfigFactory> factories = ImmutableSet.of( - new ConfigFactory<IntentDomainId, IntentDomainConfig>(INTENT_DOMAIN_SUBJECT_FACTORY, - IntentDomainConfig.class, - "basic") { - @Override - public IntentDomainConfig createConfig() { - return new IntentDomainConfig(); - } - } - ); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected NetworkConfigRegistry registry; - - @Activate - public void activate() { - factories.forEach(registry::registerConfigFactory); - log.info("Started"); - } - - @Deactivate - public void deactivate() { - factories.forEach(registry::unregisterConfigFactory); - log.info("Stopped"); - } - -} diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/config/impl/package-info.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/config/impl/package-info.java deleted file mode 100644 index a2375429..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/config/impl/package-info.java +++ /dev/null @@ -1,20 +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. - */ - -/** - * Implementation of the network configuration subsystem. - */ -package org.onosproject.incubator.net.config.impl;
\ No newline at end of file diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/domain/impl/IntentDomainManager.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/domain/impl/IntentDomainManager.java deleted file mode 100644 index 33c8a3c5..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/domain/impl/IntentDomainManager.java +++ /dev/null @@ -1,210 +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.incubator.net.domain.impl; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; -import com.google.common.collect.Multimaps; -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; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.Service; -import org.onlab.graph.AdjacencyListsGraph; -import org.onlab.graph.Graph; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.config.NetworkConfigEvent; -import org.onosproject.net.config.NetworkConfigListener; -import org.onosproject.net.config.NetworkConfigService; -import org.onosproject.incubator.net.domain.DomainEdge; -import org.onosproject.incubator.net.domain.DomainVertex; -import org.onosproject.incubator.net.domain.IntentDomain; -import org.onosproject.incubator.net.domain.IntentDomainAdminService; -import org.onosproject.incubator.net.domain.IntentDomainConfig; -import org.onosproject.incubator.net.domain.IntentDomainId; -import org.onosproject.incubator.net.domain.IntentDomainListener; -import org.onosproject.incubator.net.domain.IntentDomainProvider; -import org.onosproject.incubator.net.domain.IntentDomainService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentMap; -import java.util.stream.Collectors; - -/** - * Implementation of the intent domain service. - */ -@Component(immediate = true) -@Service -public class IntentDomainManager - implements IntentDomainService, IntentDomainAdminService { - - private final Logger log = LoggerFactory.getLogger(getClass()); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected NetworkConfigService configService; - - private NetworkConfigListener cfgListener = new InternalConfigListener(); - - private final ConcurrentMap<IntentDomainId, IntentDomain> domains = Maps.newConcurrentMap(); - - private final Multimap<String, IntentDomainId> appToDomain = - Multimaps.synchronizedSetMultimap(HashMultimap.<String, IntentDomainId>create()); - - private Graph<DomainVertex, DomainEdge> graph; - - @Activate - protected void activate() { - configService.addListener(cfgListener); - configService.getSubjects(IntentDomainId.class, IntentDomainConfig.class) - .forEach(this::processConfig); - graph = buildGraph(); - log.debug("Graph: {}", graph); - log.info("Started"); - } - - private void processConfig(IntentDomainId intentDomainId) { - IntentDomainConfig cfg = configService.getConfig(intentDomainId, - IntentDomainConfig.class); - - domains.put(intentDomainId, createDomain(intentDomainId, cfg)); - appToDomain.put(cfg.applicationName(), intentDomainId); - } - - private IntentDomain createDomain(IntentDomainId id, IntentDomainConfig cfg) { - return new IntentDomain(id, cfg.domainName(), cfg.internalDevices(), cfg.edgePorts()); - } - - private Graph<DomainVertex, DomainEdge> buildGraph() { - Set<DomainVertex> vertices = Sets.newHashSet(); - Set<DomainEdge> edges = Sets.newHashSet(); - - Map<DeviceId, DomainVertex> deviceVertices = Maps.newHashMap(); - domains.forEach((id, domain) -> { - DomainVertex domainVertex = new DomainVertex(id); - - // Add vertex for domain - vertices.add(domainVertex); - - // Add vertices for connection devices - domain.edgePorts().stream() - .map(ConnectPoint::deviceId) - .collect(Collectors.toSet()) - .forEach(did -> deviceVertices.putIfAbsent(did, new DomainVertex(did))); - - // Add bi-directional edges between each domain and connection device - domain.edgePorts().forEach(cp -> { - DomainVertex deviceVertex = deviceVertices.get(cp.deviceId()); - edges.add(new DomainEdge(domainVertex, deviceVertex, cp)); - edges.add(new DomainEdge(deviceVertex, domainVertex, cp)); - }); - }); - - vertices.addAll(deviceVertices.values()); - //FIXME verify graph integrity... - return new AdjacencyListsGraph<>(vertices, edges); - } - - @Deactivate - protected void deactivate() { - configService.removeListener(cfgListener); - log.info("Stopped"); - } - - @Override - public IntentDomain getDomain(IntentDomainId id) { - return domains.get(id); - } - - @Override - public Set<IntentDomain> getDomains() { - return ImmutableSet.copyOf(domains.values()); - } - - @Override - public Set<IntentDomain> getDomains(DeviceId deviceId) { - return domains.values().stream() - .filter(domain -> - domain.internalDevices().contains(deviceId) || - domain.edgePorts().stream() - .map(ConnectPoint::deviceId) - .anyMatch(d -> d.equals(deviceId))) - .collect(Collectors.toSet()); - } - - @Override - public Graph<DomainVertex, DomainEdge> getDomainGraph() { - return graph; - } - - @Override - public void addListener(IntentDomainListener listener) { - //TODO slide in AbstractListenerManager - } - - @Override - public void removeListener(IntentDomainListener listener) { - //TODO slide in AbstractListenerManager - } - - @Override - public void registerApplication(ApplicationId applicationId, IntentDomainProvider provider) { - appToDomain.get(applicationId.name()).forEach(d -> domains.get(d).setProvider(provider)); - } - - @Override - public void unregisterApplication(ApplicationId applicationId) { - appToDomain.get(applicationId.name()).forEach(d -> domains.get(d).unsetProvider()); - } - - private class InternalConfigListener implements NetworkConfigListener { - @Override - public void event(NetworkConfigEvent event) { - switch (event.type()) { - case CONFIG_ADDED: - case CONFIG_UPDATED: - processConfig((IntentDomainId) event.subject()); - graph = buildGraph(); - log.debug("Graph: {}", graph); - break; - - case CONFIG_REGISTERED: - case CONFIG_UNREGISTERED: - case CONFIG_REMOVED: - default: - //TODO - break; - } - } - - @Override - public boolean isRelevant(NetworkConfigEvent event) { - return event.configClass().equals(IntentDomainConfig.class); - } - } -} diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/domain/impl/package-info.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/domain/impl/package-info.java deleted file mode 100644 index 8fe3a3c6..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/domain/impl/package-info.java +++ /dev/null @@ -1,20 +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. - */ - -/** - * Implementation of the intent domain subsystem. - */ -package org.onosproject.incubator.net.domain.impl;
\ No newline at end of file diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/impl/PortStatisticsManager.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/impl/PortStatisticsManager.java deleted file mode 100644 index 1a615481..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/impl/PortStatisticsManager.java +++ /dev/null @@ -1,162 +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.incubator.net.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; -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.PortStatisticsService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.device.DeviceEvent; -import org.onosproject.net.device.DeviceListener; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.device.PortStatistics; -import org.onosproject.net.statistic.DefaultLoad; -import org.onosproject.net.statistic.Load; -import org.slf4j.Logger; - -import java.util.Map; -import java.util.stream.Collectors; - -import static org.onosproject.net.PortNumber.portNumber; -import static org.onosproject.net.device.DeviceEvent.Type.*; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Implementation of the port statistics service. - */ -@Component(immediate = true) -@Service -public class PortStatisticsManager implements PortStatisticsService { - - private final Logger log = getLogger(getClass()); - - private static final long POLL_FREQUENCY = 10_000; // milliseconds - private static final long STALE_LIMIT = (long) (1.5 * POLL_FREQUENCY); - private static final int SECOND = 1_000; // milliseconds - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - - private final DeviceListener deviceListener = new InternalDeviceListener(); - - private Map<ConnectPoint, DataPoint> current = Maps.newConcurrentMap(); - private Map<ConnectPoint, DataPoint> previous = Maps.newConcurrentMap(); - - @Activate - public void activate() { - deviceService.addListener(deviceListener); - log.info("Started"); - } - - @Deactivate - public void deactivate() { - deviceService.removeListener(deviceListener); - log.info("Stopped"); - } - - @Override - public Load load(ConnectPoint connectPoint) { - DataPoint c = current.get(connectPoint); - DataPoint p = previous.get(connectPoint); - long now = System.currentTimeMillis(); - - if (c != null && p != null && (now - c.time < STALE_LIMIT)) { - if (c.time > p.time + SECOND) { - //Use max of either Tx or Rx load as the total load of a port - Load load = null; - if (c.stats.bytesSent() >= p.stats.bytesSent()) { - load = new DefaultLoad(c.stats.bytesSent(), p.stats.bytesSent(), - (int) (c.time - p.time) / SECOND); - } - if (c.stats.bytesReceived() >= p.stats.bytesReceived()) { - Load rcvLoad = new DefaultLoad(c.stats.bytesReceived(), p.stats.bytesReceived(), - (int) (c.time - p.time) / SECOND); - load = ((load == null) || (rcvLoad.rate() > load.rate())) ? rcvLoad : load; - } - return load; - } - } - return null; - } - - // Monitors port stats update messages. - private class InternalDeviceListener implements DeviceListener { - @Override - public void event(DeviceEvent event) { - DeviceEvent.Type type = event.type(); - DeviceId deviceId = event.subject().id(); - if (type == PORT_STATS_UPDATED) { - // Update port load - updateDeviceData(deviceId); - - } else if (type == DEVICE_REMOVED || - (type == DEVICE_AVAILABILITY_CHANGED && - !deviceService.isAvailable(deviceId))) { - // Clean-up all port loads - pruneDeviceData(deviceId); - } - } - } - - // Updates the port stats for the specified device - private void updateDeviceData(DeviceId deviceId) { - deviceService.getPortStatistics(deviceId) - .forEach(stats -> updatePortData(deviceId, stats)); - } - - // Updates the port stats for the specified port - private void updatePortData(DeviceId deviceId, PortStatistics stats) { - ConnectPoint cp = new ConnectPoint(deviceId, portNumber(stats.port())); - DataPoint c = current.get(cp); - - // Create a new data point and make it the current one - current.put(cp, new DataPoint(stats)); - - // If we have a current data point, demote it to previous - if (c != null) { - previous.put(cp, c); - } - } - - // Cleans all port loads for the specified device - private void pruneDeviceData(DeviceId deviceId) { - pruneMap(current, deviceId); - pruneMap(previous, deviceId); - } - - private void pruneMap(Map<ConnectPoint, DataPoint> map, DeviceId deviceId) { - map.keySet().stream().filter(cp -> deviceId.equals(cp.deviceId())) - .collect(Collectors.toSet()).forEach(map::remove); - } - - // Auxiliary data point to track when we receive different samples. - private class DataPoint { - long time; - PortStatistics stats; - - DataPoint(PortStatistics stats) { - time = System.currentTimeMillis(); - this.stats = stats; - } - } - -} diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/impl/package-info.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/impl/package-info.java deleted file mode 100644 index 842a58fb..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/impl/package-info.java +++ /dev/null @@ -1,20 +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. - */ - -/** - * Implementations of incubating core subsystems. - */ -package org.onosproject.incubator.net.impl;
\ No newline at end of file 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 deleted file mode 100644 index bbd96de0..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/InterfaceManager.java +++ /dev/null @@ -1,269 +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.incubator.net.intf.impl; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -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; -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.IpAddress; -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; -import org.onosproject.net.config.NetworkConfigListener; -import org.onosproject.net.config.NetworkConfigService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collections; -import java.util.Iterator; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; - -import static java.util.stream.Collectors.collectingAndThen; -import static java.util.stream.Collectors.toSet; - -/** - * Manages the inventory of interfaces in the system. - */ -@Service -@Component(immediate = true) -public class InterfaceManager implements InterfaceService, - InterfaceAdminService { - - private final Logger log = LoggerFactory.getLogger(getClass()); - - private static final Class<ConnectPoint> SUBJECT_CLASS = ConnectPoint.class; - private static final Class<InterfaceConfig> CONFIG_CLASS = InterfaceConfig.class; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected NetworkConfigService configService; - - private final InternalConfigListener listener = new InternalConfigListener(); - - private final Map<ConnectPoint, Set<Interface>> interfaces = Maps.newConcurrentMap(); - - @Activate - public void activate() { - configService.addListener(listener); - - // TODO address concurrency issues here - for (ConnectPoint subject : configService.getSubjects(SUBJECT_CLASS, CONFIG_CLASS)) { - InterfaceConfig config = configService.getConfig(subject, CONFIG_CLASS); - - if (config != null) { - updateInterfaces(config); - } - } - - log.info("Started"); - } - - @Deactivate - public void deactivate() { - configService.removeListener(listener); - - log.info("Stopped"); - } - - @Override - public Set<Interface> getInterfaces() { - return interfaces.values() - .stream() - .flatMap(set -> set.stream()) - .collect(collectingAndThen(toSet(), ImmutableSet::copyOf)); - } - - @Override - public Set<Interface> getInterfacesByPort(ConnectPoint port) { - Set<Interface> intfs = interfaces.get(port); - if (intfs == null) { - return Collections.emptySet(); - } - return ImmutableSet.copyOf(intfs); - } - - @Override - public Set<Interface> getInterfacesByIp(IpAddress ip) { - return interfaces.values() - .stream() - .flatMap(set -> set.stream()) - .filter(intf -> intf.ipAddresses() - .stream() - .anyMatch(ia -> ia.ipAddress().equals(ip))) - .collect(collectingAndThen(toSet(), ImmutableSet::copyOf)); - } - - @Override - public Interface getMatchingInterface(IpAddress ip) { - Optional<Interface> match = interfaces.values() - .stream() - .flatMap(set -> set.stream()) - .filter(intf -> intf.ipAddresses() - .stream() - .anyMatch(intfIp -> intfIp.subnetAddress().contains(ip))) - .findFirst(); - - if (match.isPresent()) { - return match.get(); - } - - return null; - } - - @Override - public Set<Interface> getInterfacesByVlan(VlanId vlan) { - return interfaces.values() - .stream() - .flatMap(set -> set.stream()) - .filter(intf -> intf.vlan().equals(vlan)) - .collect(collectingAndThen(toSet(), ImmutableSet::copyOf)); - } - - private void updateInterfaces(InterfaceConfig intfConfig) { - try { - interfaces.put(intfConfig.subject(), Sets.newHashSet(intfConfig.getInterfaces())); - } catch (ConfigException e) { - log.error("Error in interface config", e); - } - } - - private void removeInterfaces(ConnectPoint port) { - interfaces.remove(port); - } - - @Override - public void add(Interface intf) { - addInternal(intf); - - InterfaceConfig config = - configService.addConfig(intf.connectPoint(), CONFIG_CLASS); - - config.addInterface(intf); - - configService.applyConfig(intf.connectPoint(), CONFIG_CLASS, config.node()); - } - - private void addInternal(Interface intf) { - interfaces.compute(intf.connectPoint(), (cp, current) -> { - if (current == null) { - return Sets.newHashSet(intf); - } - - Iterator<Interface> it = current.iterator(); - while (it.hasNext()) { - Interface i = it.next(); - if (i.name().equals(intf.name())) { - it.remove(); - break; - } - } - - current.add(intf); - return current; - }); - } - - @Override - public boolean remove(ConnectPoint connectPoint, String name) { - boolean success = removeInternal(name, connectPoint); - - InterfaceConfig config = configService.addConfig(connectPoint, CONFIG_CLASS); - config.removeInterface(name); - - try { - if (config.getInterfaces().isEmpty()) { - configService.removeConfig(connectPoint, CONFIG_CLASS); - } else { - configService.applyConfig(connectPoint, CONFIG_CLASS, config.node()); - } - } catch (ConfigException e) { - log.error("Error reading interfaces JSON", e); - } - - return success; - } - - public boolean removeInternal(String name, ConnectPoint connectPoint) { - AtomicBoolean removed = new AtomicBoolean(false); - - interfaces.compute(connectPoint, (cp, current) -> { - if (current == null) { - return null; - } - - Iterator<Interface> it = current.iterator(); - while (it.hasNext()) { - Interface i = it.next(); - if (i.name().equals(name)) { - it.remove(); - removed.set(true); - break; - } - } - - if (current.isEmpty()) { - return null; - } else { - return current; - } - }); - - return removed.get(); - } - - /** - * Listener for network config events. - */ - private class InternalConfigListener implements NetworkConfigListener { - - @Override - public void event(NetworkConfigEvent event) { - switch (event.type()) { - case CONFIG_ADDED: - case CONFIG_UPDATED: - if (event.configClass() == InterfaceConfig.class) { - InterfaceConfig config = - configService.getConfig((ConnectPoint) event.subject(), InterfaceConfig.class); - updateInterfaces(config); - } - break; - case CONFIG_REMOVED: - if (event.configClass() == InterfaceConfig.class) { - removeInterfaces((ConnectPoint) event.subject()); - } - break; - case CONFIG_REGISTERED: - case CONFIG_UNREGISTERED: - default: - break; - } - } - } -} diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/package-info.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/package-info.java deleted file mode 100644 index abdce5a4..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/package-info.java +++ /dev/null @@ -1,20 +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. - */ - -/** - * Implementation of service for interacting with interfaces. - */ -package org.onosproject.incubator.net.intf.impl; 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 deleted file mode 100644 index 946d8c6e..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/MulticastData.java +++ /dev/null @@ -1,85 +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.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<ConnectPoint> sinks; - private final boolean isEmpty; - - private MulticastData() { - this.source = null; - this.sinks = Collections.EMPTY_LIST; - isEmpty = true; - } - - public MulticastData(ConnectPoint source, List<ConnectPoint> 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<ConnectPoint> 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 deleted file mode 100644 index f73dfe44..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManager.java +++ /dev/null @@ -1,174 +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.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<McastEvent, McastListener> - 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<McastRoute, MulticastData> mcastRoutes; - - @Activate - public void activate() { - - eventDispatcher.addSink(McastEvent.class, listenerRegistry); - - appId = coreService.registerApplication("org.onosproject.mcastrib"); - - mcastRoutes = storageService.<McastRoute, MulticastData>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<MulticastData> 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<ConnectPoint> 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<ConnectPoint> 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<ConnectPoint> 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 deleted file mode 100644 index 464cf701..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/mcast/impl/package-info.java +++ /dev/null @@ -1,20 +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. - */ - -/** - * 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 deleted file mode 100644 index 5c5c11cd..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/MeterManager.java +++ /dev/null @@ -1,248 +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.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; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.Service; -import org.onlab.util.TriConsumer; -import org.onosproject.net.meter.DefaultMeter; -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; -import org.onosproject.net.meter.MeterProviderRegistry; -import org.onosproject.net.meter.MeterProviderService; -import org.onosproject.net.meter.MeterRequest; -import org.onosproject.net.meter.MeterService; -import org.onosproject.net.meter.MeterState; -import org.onosproject.net.meter.MeterStore; -import org.onosproject.net.meter.MeterStoreDelegate; -import org.onosproject.net.meter.MeterStoreResult; -import org.onosproject.net.DeviceId; -import org.onosproject.net.provider.AbstractListenerProviderRegistry; -import org.onosproject.net.provider.AbstractProviderService; -import org.onosproject.store.service.AtomicCounter; -import org.onosproject.store.service.StorageService; -import org.slf4j.Logger; - -import java.util.Collection; -import java.util.Map; -import java.util.stream.Collectors; - -import static org.slf4j.LoggerFactory.getLogger; - - -/** - * Provides implementation of the meter service APIs. - */ -@Component(immediate = true, enabled = true) -@Service -public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, MeterListener, - MeterProvider, MeterProviderService> - implements MeterService, MeterProviderRegistry { - - private static final String METERCOUNTERIDENTIFIER = "meter-id-counter-%s"; - private final Logger log = getLogger(getClass()); - private final MeterStoreDelegate delegate = new InternalMeterStoreDelegate(); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected StorageService storageService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected MeterStore store; - - private Map<DeviceId, AtomicCounter> meterIdCounters - = Maps.newConcurrentMap(); - - private TriConsumer<MeterRequest, MeterStoreResult, Throwable> onComplete; - - @Activate - public void activate() { - - store.setDelegate(delegate); - - onComplete = (request, result, error) -> - { - request.context().ifPresent(c -> { - if (error != null) { - c.onError(request, MeterFailReason.UNKNOWN); - } else { - if (result.reason().isPresent()) { - c.onError(request, result.reason().get()); - } else { - c.onSuccess(request); - } - } - }); - - }; - log.info("Started"); - } - - @Deactivate - public void deactivate() { - store.unsetDelegate(delegate); - log.info("Stopped"); - } - - @Override - protected MeterProviderService createProviderService(MeterProvider provider) { - return new InternalMeterProviderService(provider); - } - - @Override - public Meter submit(MeterRequest request) { - - MeterId id = allocateMeterId(request.deviceId()); - - Meter.Builder mBuilder = DefaultMeter.builder() - .forDevice(request.deviceId()) - .fromApp(request.appId()) - .withBands(request.bands()) - .withId(id) - .withUnit(request.unit()); - - if (request.isBurst()) { - mBuilder.burst(); - } - DefaultMeter m = (DefaultMeter) mBuilder.build(); - m.setState(MeterState.PENDING_ADD); - store.storeMeter(m).whenComplete((result, error) -> - onComplete.accept(request, result, error)); - return m; - } - - @Override - public void withdraw(MeterRequest request, MeterId meterId) { - Meter.Builder mBuilder = DefaultMeter.builder() - .forDevice(request.deviceId()) - .fromApp(request.appId()) - .withBands(request.bands()) - .withId(meterId) - .withUnit(request.unit()); - - if (request.isBurst()) { - mBuilder.burst(); - } - - DefaultMeter m = (DefaultMeter) mBuilder.build(); - m.setState(MeterState.PENDING_REMOVE); - store.deleteMeter(m).whenComplete((result, error) -> - onComplete.accept(request, result, error)); - } - - @Override - public Meter getMeter(DeviceId deviceId, MeterId id) { - MeterKey key = MeterKey.key(deviceId, id); - return store.getMeter(key); - } - - @Override - public Collection<Meter> getAllMeters() { - return store.getAllMeters(); - } - - private MeterId allocateMeterId(DeviceId deviceId) { - long id = meterIdCounters.compute(deviceId, (k, v) -> { - 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 - extends AbstractProviderService<MeterProvider> - implements MeterProviderService { - - /** - * Creates a provider service on behalf of the specified provider. - * - * @param provider provider to which this service is being issued - */ - protected InternalMeterProviderService(MeterProvider provider) { - super(provider); - } - - @Override - public void meterOperationFailed(MeterOperation operation, - MeterFailReason reason) { - store.failedMeter(operation, reason); - } - - @Override - public void pushMeterMetrics(DeviceId deviceId, Collection<Meter> meterEntries) { - //FIXME: FOLLOWING CODE CANNOT BE TESTED UNTIL SOMETHING THAT - //FIXME: IMPLEMENTS METERS EXISTS - Map<MeterId, Meter> storedMeterMap = store.getAllMeters().stream() - .collect(Collectors.toMap(Meter::id, m -> m)); - - meterEntries.stream() - .filter(m -> storedMeterMap.remove(m.id()) != null) - .forEach(m -> store.updateMeterState(m)); - - storedMeterMap.values().stream().forEach(m -> { - if (m.state() == MeterState.PENDING_ADD) { - provider().performMeterOperation(m.deviceId(), - new MeterOperation(m, - MeterOperation.Type.ADD)); - } else { - store.deleteMeterNow(m); - } - }); - } - } - - private class InternalMeterStoreDelegate implements MeterStoreDelegate { - - @Override - public void notify(MeterEvent event) { - DeviceId deviceId = event.subject().deviceId(); - MeterProvider p = getProvider(event.subject().deviceId()); - switch (event.type()) { - case METER_ADD_REQ: - p.performMeterOperation(deviceId, new MeterOperation(event.subject(), - MeterOperation.Type.ADD)); - break; - case METER_REM_REQ: - p.performMeterOperation(deviceId, new MeterOperation(event.subject(), - MeterOperation.Type.REMOVE)); - break; - default: - log.warn("Unknown meter event {}", event.type()); - } - - } - } - -} diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/package-info.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/package-info.java deleted file mode 100644 index 5559d90b..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/package-info.java +++ /dev/null @@ -1,20 +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. - */ - -/** - * Provides implementation of the meter service APIs. - */ -package org.onosproject.incubator.net.meter.impl; diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/resource/label/impl/LabelResourceManager.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/resource/label/impl/LabelResourceManager.java deleted file mode 100644 index 8ecf1d29..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/resource/label/impl/LabelResourceManager.java +++ /dev/null @@ -1,236 +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.incubator.net.resource.label.impl; - -import com.google.common.collect.Multimap; -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.net.provider.AbstractListenerProviderRegistry; -import org.onosproject.incubator.net.resource.label.LabelResource; -import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; -import org.onosproject.incubator.net.resource.label.LabelResourceDelegate; -import org.onosproject.incubator.net.resource.label.LabelResourceEvent; -import org.onosproject.incubator.net.resource.label.LabelResourceId; -import org.onosproject.incubator.net.resource.label.LabelResourceListener; -import org.onosproject.incubator.net.resource.label.LabelResourcePool; -import org.onosproject.incubator.net.resource.label.LabelResourceProvider; -import org.onosproject.incubator.net.resource.label.LabelResourceProviderRegistry; -import org.onosproject.incubator.net.resource.label.LabelResourceProviderService; -import org.onosproject.incubator.net.resource.label.LabelResourceService; -import org.onosproject.incubator.net.resource.label.LabelResourceStore; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.device.DeviceEvent; -import org.onosproject.net.device.DeviceEvent.Type; -import org.onosproject.net.device.DeviceListener; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.provider.AbstractProviderService; -import org.slf4j.Logger; - -import java.util.Collection; -import java.util.Set; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * provides implementation of the label resource NB & SB APIs. - * - */ -@Component(immediate = true) -@Service -public class LabelResourceManager - extends AbstractListenerProviderRegistry<LabelResourceEvent, LabelResourceListener, - LabelResourceProvider, LabelResourceProviderService> - implements LabelResourceService, LabelResourceAdminService, LabelResourceProviderRegistry { - private final Logger log = getLogger(getClass()); - private final LabelResourceDelegate delegate = new InternalLabelResourceDelegate(); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected LabelResourceStore store; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - - private DeviceListener deviceListener = new InternalDeviceListener(); - - @Activate - public void activate() { - store.setDelegate(delegate); - eventDispatcher.addSink(LabelResourceEvent.class, listenerRegistry); - deviceService.addListener(deviceListener); - log.info("Started"); - - } - - @Deactivate - public void deactivate() { - deviceService.removeListener(deviceListener); - store.unsetDelegate(delegate); - eventDispatcher.removeSink(LabelResourceEvent.class); - log.info("Stopped"); - } - - @Override - public boolean createDevicePool(DeviceId deviceId, - LabelResourceId beginLabel, - LabelResourceId endLabel) { - checkNotNull(deviceId, "deviceId is not null"); - checkNotNull(beginLabel, "beginLabel is not null"); - checkNotNull(endLabel, "endLabel is not null"); - checkArgument(beginLabel.labelId() >= 0 || endLabel.labelId() >= 0, - "The value of beginLabel and the value of endLabel must be both positive number."); - checkArgument(beginLabel.labelId() < endLabel.labelId(), - "The value of endLabel must be greater than the value of beginLabel."); - return store.createDevicePool(deviceId, beginLabel, endLabel); - } - - @Override - public boolean createGlobalPool(LabelResourceId beginLabel, - LabelResourceId endLabel) { - checkNotNull(beginLabel, "beginLabel is not null"); - checkNotNull(endLabel, "endLabel is not null"); - checkArgument(beginLabel.labelId() >= 0 && endLabel.labelId() >= 0, - "The value of beginLabel and the value of endLabel must be both positive number."); - checkArgument(beginLabel.labelId() < endLabel.labelId(), - "The value of endLabel must be greater than the value of beginLabel."); - return store.createGlobalPool(beginLabel, endLabel); - } - - @Override - public boolean destroyDevicePool(DeviceId deviceId) { - checkNotNull(deviceId, "deviceId is not null"); - return store.destroyDevicePool(deviceId); - } - - @Override - public boolean destroyGlobalPool() { - return store.destroyGlobalPool(); - } - - @Override - public Collection<LabelResource> applyFromDevicePool(DeviceId deviceId, - long applyNum) { - checkNotNull(deviceId, "deviceId is not null"); - checkNotNull(applyNum, "applyNum is not null"); - return store.applyFromDevicePool(deviceId, applyNum); - } - - @Override - public Collection<LabelResource> applyFromGlobalPool(long applyNum) { - checkNotNull(applyNum, "applyNum is not null"); - return store.applyFromGlobalPool(applyNum); - } - - @Override - public boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release) { - checkNotNull(release, "release is not null"); - return store.releaseToDevicePool(release); - } - - @Override - public boolean releaseToGlobalPool(Set<LabelResourceId> release) { - checkNotNull(release, "release is not null"); - return store.releaseToGlobalPool(release); - } - - @Override - public boolean isDevicePoolFull(DeviceId deviceId) { - checkNotNull(deviceId, "deviceId is not null"); - return store.isDevicePoolFull(deviceId); - } - - @Override - public boolean isGlobalPoolFull() { - return store.isGlobalPoolFull(); - } - - @Override - public long getFreeNumOfDevicePool(DeviceId deviceId) { - checkNotNull(deviceId, "deviceId is not null"); - return store.getFreeNumOfDevicePool(deviceId); - } - - @Override - public long getFreeNumOfGlobalPool() { - return store.getFreeNumOfGlobalPool(); - } - - @Override - public LabelResourcePool getDeviceLabelResourcePool(DeviceId deviceId) { - checkNotNull(deviceId, "deviceId is not null"); - return store.getDeviceLabelResourcePool(deviceId); - } - - @Override - public LabelResourcePool getGlobalLabelResourcePool() { - return store.getGlobalLabelResourcePool(); - } - - private class InternalLabelResourceDelegate implements LabelResourceDelegate { - @Override - public void notify(LabelResourceEvent event) { - post(event); - } - - } - - private class InternalDeviceListener implements DeviceListener { - @Override - public void event(DeviceEvent event) { - Device device = event.subject(); - if (Type.DEVICE_REMOVED.equals(event.type())) { - destroyDevicePool(device.id()); - } - } - } - - private class InternalLabelResourceProviderService - extends AbstractProviderService<LabelResourceProvider> - implements LabelResourceProviderService { - - protected InternalLabelResourceProviderService(LabelResourceProvider provider) { - super(provider); - } - - @Override - public void deviceLabelResourcePoolDetected(DeviceId deviceId, - LabelResourceId beginLabel, - LabelResourceId endLabel) { - checkNotNull(deviceId, "deviceId is not null"); - checkNotNull(beginLabel, "beginLabel is not null"); - checkNotNull(endLabel, "endLabel is not null"); - createDevicePool(deviceId, beginLabel, endLabel); - } - - @Override - public void deviceLabelResourcePoolDestroyed(DeviceId deviceId) { - checkNotNull(deviceId, "deviceId is not null"); - destroyDevicePool(deviceId); - } - - } - - @Override - protected LabelResourceProviderService createProviderService(LabelResourceProvider provider) { - return new InternalLabelResourceProviderService(provider); - } -} diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/resource/label/impl/package-info.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/resource/label/impl/package-info.java deleted file mode 100644 index afd31b48..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/resource/label/impl/package-info.java +++ /dev/null @@ -1,20 +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. - */ - -/** - * Implementation of the label resource subsystem. - */ -package org.onosproject.incubator.net.resource.label.impl;
\ No newline at end of file diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/tunnel/impl/TunnelManager.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/tunnel/impl/TunnelManager.java deleted file mode 100644 index d316388f..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/tunnel/impl/TunnelManager.java +++ /dev/null @@ -1,366 +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.incubator.net.tunnel.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.net.provider.AbstractListenerProviderRegistry; -import org.onosproject.core.ApplicationId; -import org.onosproject.incubator.net.tunnel.DefaultTunnel; -import org.onosproject.incubator.net.tunnel.Tunnel; -import org.onosproject.incubator.net.tunnel.Tunnel.Type; -import org.onosproject.incubator.net.tunnel.TunnelAdminService; -import org.onosproject.incubator.net.tunnel.TunnelDescription; -import org.onosproject.incubator.net.tunnel.TunnelEndPoint; -import org.onosproject.incubator.net.tunnel.TunnelEvent; -import org.onosproject.incubator.net.tunnel.TunnelId; -import org.onosproject.incubator.net.tunnel.TunnelListener; -import org.onosproject.incubator.net.tunnel.TunnelName; -import org.onosproject.incubator.net.tunnel.TunnelProvider; -import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry; -import org.onosproject.incubator.net.tunnel.TunnelProviderService; -import org.onosproject.incubator.net.tunnel.TunnelService; -import org.onosproject.incubator.net.tunnel.TunnelStore; -import org.onosproject.incubator.net.tunnel.TunnelStoreDelegate; -import org.onosproject.incubator.net.tunnel.TunnelSubscription; -import org.onosproject.net.Annotations; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Path; -import org.onosproject.net.provider.AbstractProviderService; -import org.onosproject.net.provider.ProviderId; -import org.slf4j.Logger; - -import java.util.Collection; -import java.util.Collections; -import java.util.Set; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Provides implementation of the tunnel NB/SB APIs. - */ -@Component(immediate = true, enabled = true) -@Service -public class TunnelManager - extends AbstractListenerProviderRegistry<TunnelEvent, TunnelListener, - TunnelProvider, TunnelProviderService> - implements TunnelService, TunnelAdminService, TunnelProviderRegistry { - - private static final String TUNNNEL_ID_NULL = "Tunnel ID cannot be null"; - - private final Logger log = getLogger(getClass()); - - private final TunnelStoreDelegate delegate = new InternalStoreDelegate(); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected TunnelStore store; - - - @Activate - public void activate() { - store.setDelegate(delegate); - eventDispatcher.addSink(TunnelEvent.class, listenerRegistry); - log.info("Started"); - } - - @Deactivate - public void deactivate() { - store.unsetDelegate(delegate); - eventDispatcher.removeSink(TunnelEvent.class); - log.info("Stopped"); - } - - @Override - public void removeTunnel(TunnelId tunnelId) { - checkNotNull(tunnelId, TUNNNEL_ID_NULL); - store.deleteTunnel(tunnelId); - Tunnel tunnel = store.queryTunnel(tunnelId); - if (tunnel.providerId() != null) { - TunnelProvider provider = getProvider(tunnel.providerId()); - if (provider != null) { - provider.releaseTunnel(tunnel); - } - } else { - Set<ProviderId> ids = getProviders(); - for (ProviderId providerId : ids) { - TunnelProvider provider = getProvider(providerId); - provider.releaseTunnel(tunnel); - } - } - } - - @Override - public void updateTunnel(Tunnel tunnel, Path path) { - store.createOrUpdateTunnel(tunnel); - if (tunnel.providerId() != null) { - TunnelProvider provider = getProvider(tunnel.providerId()); - if (provider != null) { - provider.updateTunnel(tunnel, path); - } - } else { - Set<ProviderId> ids = getProviders(); - for (ProviderId providerId : ids) { - TunnelProvider provider = getProvider(providerId); - provider.updateTunnel(tunnel, path); - } - } - } - - @Override - public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, - ProviderId producerName) { - store.deleteTunnel(src, dst, producerName); - Collection<Tunnel> setTunnels = store.queryTunnel(src, dst); - for (Tunnel tunnel : setTunnels) { - if (producerName != null - && !tunnel.providerId().equals(producerName)) { - continue; - } - if (tunnel.providerId() != null) { - TunnelProvider provider = getProvider(tunnel.providerId()); - if (provider != null) { - provider.releaseTunnel(tunnel); - } - } else { - Set<ProviderId> ids = getProviders(); - for (ProviderId providerId : ids) { - TunnelProvider provider = getProvider(providerId); - provider.releaseTunnel(tunnel); - } - } - } - } - - @Override - public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type, - ProviderId producerName) { - store.deleteTunnel(src, dst, type, producerName); - Collection<Tunnel> setTunnels = store.queryTunnel(src, dst); - for (Tunnel tunnel : setTunnels) { - if (producerName != null - && !tunnel.providerId().equals(producerName) - || !type.equals(tunnel.type())) { - continue; - } - if (tunnel.providerId() != null) { - TunnelProvider provider = getProvider(tunnel.providerId()); - if (provider != null) { - provider.releaseTunnel(tunnel); - } - } else { - Set<ProviderId> ids = getProviders(); - for (ProviderId providerId : ids) { - TunnelProvider provider = getProvider(providerId); - provider.releaseTunnel(tunnel); - } - } - } - } - - @Override - public Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId, - Annotations... annotations) { - return store.borrowTunnel(consumerId, tunnelId, annotations); - } - - @Override - public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, - TunnelName tunnelName, - Annotations... annotations) { - return store.borrowTunnel(consumerId, tunnelName, annotations); - } - - @Override - public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, - TunnelEndPoint src, TunnelEndPoint dst, - Annotations... annotations) { - Collection<Tunnel> tunnels = store.borrowTunnel(consumerId, src, - dst, annotations); - if (tunnels == null || tunnels.size() == 0) { - Tunnel tunnel = new DefaultTunnel(null, src, dst, null, null, null, - null, null, annotations); - Set<ProviderId> ids = getProviders(); - for (ProviderId providerId : ids) { - TunnelProvider provider = getProvider(providerId); - provider.setupTunnel(tunnel, null); - } - } - return tunnels; - } - - @Override - public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, - TunnelEndPoint src, TunnelEndPoint dst, - Type type, Annotations... annotations) { - Collection<Tunnel> tunnels = store.borrowTunnel(consumerId, src, - dst, type, - annotations); - if (tunnels == null || tunnels.size() == 0) { - Tunnel tunnel = new DefaultTunnel(null, src, dst, type, null, null, - null, null, annotations); - Set<ProviderId> ids = getProviders(); - for (ProviderId providerId : ids) { - TunnelProvider provider = getProvider(providerId); - provider.setupTunnel(tunnel, null); - } - } - return tunnels; - } - - @Override - public boolean returnTunnel(ApplicationId consumerId, - TunnelId tunnelId, Annotations... annotations) { - return store.returnTunnel(consumerId, tunnelId, annotations); - } - - @Override - public boolean returnTunnel(ApplicationId consumerId, - TunnelName tunnelName, - Annotations... annotations) { - return store.returnTunnel(consumerId, tunnelName, annotations); - } - - @Override - public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src, - TunnelEndPoint dst, Type type, - Annotations... annotations) { - return store.returnTunnel(consumerId, src, dst, type, annotations); - } - - @Override - public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src, - TunnelEndPoint dst, Annotations... annotations) { - return store.returnTunnel(consumerId, src, dst, annotations); - } - - @Override - public Tunnel queryTunnel(TunnelId tunnelId) { - return store.queryTunnel(tunnelId); - } - - @Override - public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId consumerId) { - return store.queryTunnelSubscription(consumerId); - } - - @Override - public Collection<Tunnel> queryTunnel(Type type) { - return store.queryTunnel(type); - } - - @Override - public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) { - return store.queryTunnel(src, dst); - } - - - @Override - public Collection<Tunnel> queryAllTunnels() { - return store.queryAllTunnels(); - } - - @Override - public int tunnelCount() { - return store.tunnelCount(); - } - - @Override - protected TunnelProviderService createProviderService(TunnelProvider provider) { - return new InternalTunnelProviderService(provider); - } - - private class InternalTunnelProviderService - extends AbstractProviderService<TunnelProvider> - implements TunnelProviderService { - protected InternalTunnelProviderService(TunnelProvider provider) { - super(provider); - } - - - @Override - public TunnelId tunnelAdded(TunnelDescription tunnel) { - Tunnel storedTunnel = new DefaultTunnel(provider().id(), - tunnel.src(), tunnel.dst(), - tunnel.type(), - tunnel.groupId(), - tunnel.id(), - tunnel.tunnelName(), - tunnel.path(), - tunnel.annotations()); - return store.createOrUpdateTunnel(storedTunnel); - } - - @Override - public void tunnelUpdated(TunnelDescription tunnel) { - Tunnel storedTunnel = new DefaultTunnel(provider().id(), - tunnel.src(), tunnel.dst(), - tunnel.type(), - tunnel.groupId(), - tunnel.id(), - tunnel.tunnelName(), - tunnel.path(), - tunnel.annotations()); - store.createOrUpdateTunnel(storedTunnel); - } - - @Override - public void tunnelRemoved(TunnelDescription tunnel) { - if (tunnel.id() != null) { - store.deleteTunnel(tunnel.id()); - return; - } - if (tunnel.src() != null && tunnel.dst() != null - && tunnel.type() != null) { - store.deleteTunnel(tunnel.src(), tunnel.dst(), tunnel.type(), - provider().id()); - return; - } - if (tunnel.src() != null && tunnel.dst() != null - && tunnel.type() == null) { - store.deleteTunnel(tunnel.src(), tunnel.dst(), provider().id()); - return; - } - } - - - @Override - public Tunnel tunnelQueryById(TunnelId tunnelId) { - return store.queryTunnel(tunnelId); - } - - - } - - private class InternalStoreDelegate implements TunnelStoreDelegate { - @Override - public void notify(TunnelEvent event) { - if (event != null) { - post(event); - } - } - } - - @Override - public Iterable<Tunnel> getTunnels(DeviceId deviceId) { - return Collections.emptyList(); - } - -} diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/tunnel/impl/package-info.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/tunnel/impl/package-info.java deleted file mode 100644 index 6e0de551..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/tunnel/impl/package-info.java +++ /dev/null @@ -1,20 +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. - */ - -/** - * Core subsystem for tracking global inventory of tunnels. - */ -package org.onosproject.incubator.net.tunnel.impl; 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 deleted file mode 100644 index fe9f8841..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java +++ /dev/null @@ -1,223 +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.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<VirtualNetworkEvent, VirtualNetworkListener, - VirtualNetworkProvider, VirtualNetworkProviderService> - 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<TenantId> 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<VirtualNetwork> getVirtualNetworks(TenantId tenantId) { - checkNotNull(tenantId, TENANT_NULL); - return store.getNetworks(tenantId); - } - - @Override - public Set<VirtualDevice> getVirtualDevices(NetworkId networkId) { - checkNotNull(networkId, NETWORK_NULL); - return store.getDevices(networkId); - } - - @Override - public Set<VirtualLink> getVirtualLinks(NetworkId networkId) { - checkNotNull(networkId, NETWORK_NULL); - return store.getLinks(networkId); - } - - @Override - public Set<VirtualPort> getVirtualPorts(NetworkId networkId, DeviceId deviceId) { - checkNotNull(networkId, NETWORK_NULL); - checkNotNull(deviceId, DEVICE_NULL); - return store.getPorts(networkId, deviceId); - } - - @Override - public <T> T get(NetworkId networkId, Class<T> 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<VirtualNetworkProvider> - 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 deleted file mode 100644 index da4be5aa..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/package-info.java +++ /dev/null @@ -1,20 +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. - */ - -/** - * 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/intf/impl/InterfaceManagerTest.java b/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/intf/impl/InterfaceManagerTest.java deleted file mode 100644 index cc2908bc..00000000 --- a/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/intf/impl/InterfaceManagerTest.java +++ /dev/null @@ -1,287 +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.incubator.net.intf.impl; - -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import org.junit.Before; -import org.junit.Test; -import org.onlab.packet.Ip4Address; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -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.net.ConnectPoint; -import org.onosproject.net.config.Config; -import org.onosproject.net.config.NetworkConfigEvent; -import org.onosproject.net.config.NetworkConfigListener; -import org.onosproject.net.config.NetworkConfigServiceAdapter; -import org.onosproject.net.host.InterfaceIpAddress; - -import java.util.Collections; -import java.util.Map; -import java.util.Set; - -import static junit.framework.TestCase.assertEquals; -import static org.junit.Assert.assertNull; - -/** - * Unit tests for InterfaceManager. - */ -public class InterfaceManagerTest { - private static final Class<InterfaceConfig> CONFIG_CLASS = InterfaceConfig.class; - - private static final int NUM_INTERFACES = 4; - - private Set<ConnectPoint> subjects = Sets.newHashSet(); - private Map<ConnectPoint, InterfaceConfig> configs = Maps.newHashMap(); - - private Set<Interface> interfaces = Sets.newHashSet(); - - private NetworkConfigListener listener; - - private InterfaceManager interfaceManager; - - @Before - public void setUp() throws Exception { - for (int i = 0; i < NUM_INTERFACES; i++) { - ConnectPoint cp = createConnectPoint(i); - subjects.add(cp); - - Interface intf = createInterface(i); - - interfaces.add(intf); - - InterfaceConfig ic = new TestInterfaceConfig(cp, Sets.newHashSet(intf)); - - configs.put(cp, ic); - } - - TestNetworkConfigService configService = - new TestNetworkConfigService(subjects, configs); - - interfaceManager = new InterfaceManager(); - interfaceManager.configService = configService; - interfaceManager.activate(); - } - - private Interface createInterface(int i) { - ConnectPoint cp = createConnectPoint(i); - - InterfaceIpAddress ia = InterfaceIpAddress.valueOf("192.168." + i + ".1/24"); - - Interface intf = new Interface(cp, - Sets.newHashSet(ia), - MacAddress.valueOf(i), - VlanId.vlanId((short) i)); - - return intf; - } - - private ConnectPoint createConnectPoint(int i) { - return ConnectPoint.deviceConnectPoint("of:000000000000000" + i + "/1"); - } - - @Test - public void testGetInterfaces() throws Exception { - assertEquals(interfaces, interfaceManager.getInterfaces()); - } - - @Test - public void testGetInterfacesByPort() throws Exception { - ConnectPoint cp = ConnectPoint.deviceConnectPoint("of:0000000000000001/1"); - - Set<Interface> byPort = Collections.singleton(createInterface(1)); - - assertEquals(byPort, interfaceManager.getInterfacesByPort(cp)); - } - - @Test - public void testGetInterfacesByIp() throws Exception { - IpAddress ip = Ip4Address.valueOf("192.168.2.1"); - - Set<Interface> byIp = Collections.singleton(createInterface(2)); - - assertEquals(byIp, interfaceManager.getInterfacesByIp(ip)); - } - - @Test - public void testGetMatchingInterface() throws Exception { - IpAddress ip = Ip4Address.valueOf("192.168.1.100"); - - Interface matchingIntf = createInterface(1); - - assertEquals(matchingIntf, interfaceManager.getMatchingInterface(ip)); - - // Searching for an IP with no match should return null - ip = Ip4Address.valueOf("1.1.1.1"); - - assertNull(interfaceManager.getMatchingInterface(ip)); - } - - @Test - public void testGetInterfacesByVlan() throws Exception { - VlanId vlanId = VlanId.vlanId((short) 1); - - Set<Interface> byVlan = Collections.singleton(createInterface(1)); - - assertEquals(byVlan, interfaceManager.getInterfacesByVlan(vlanId)); - } - - @Test - public void testAddInterface() throws Exception { - // Create a new InterfaceConfig which will get added - VlanId vlanId = VlanId.vlanId((short) 1); - ConnectPoint cp = ConnectPoint.deviceConnectPoint("of:0000000000000001/2"); - Interface newIntf = new Interface(cp, - Collections.emptySet(), - MacAddress.valueOf(100), - vlanId); - - InterfaceConfig ic = new TestInterfaceConfig(cp, Collections.singleton(newIntf)); - - subjects.add(cp); - configs.put(cp, ic); - interfaces.add(newIntf); - - NetworkConfigEvent event = new NetworkConfigEvent( - NetworkConfigEvent.Type.CONFIG_ADDED, cp, CONFIG_CLASS); - - assertEquals(NUM_INTERFACES, interfaceManager.getInterfaces().size()); - - // Send in a config event containing a new interface config - listener.event(event); - - // Check the new interface exists in the InterfaceManager's inventory - assertEquals(interfaces, interfaceManager.getInterfaces()); - assertEquals(NUM_INTERFACES + 1, interfaceManager.getInterfaces().size()); - - // There are now two interfaces with vlan ID 1 - Set<Interface> byVlan = Sets.newHashSet(createInterface(1), newIntf); - assertEquals(byVlan, interfaceManager.getInterfacesByVlan(vlanId)); - } - - @Test - public void testUpdateInterface() throws Exception { - ConnectPoint cp = createConnectPoint(1); - - // Create an interface that is the same as the existing one, but adds a - // new IP address - Interface intf = createInterface(1); - Set<InterfaceIpAddress> addresses = Sets.newHashSet(intf.ipAddresses()); - addresses.add(InterfaceIpAddress.valueOf("192.168.100.1/24")); - intf = new Interface(intf.connectPoint(), addresses, intf.mac(), intf.vlan()); - - // Create a new interface on the same connect point as the existing one - InterfaceIpAddress newAddr = InterfaceIpAddress.valueOf("192.168.101.1/24"); - Interface newIntf = new Interface(cp, - Collections.singleton(newAddr), - MacAddress.valueOf(101), - VlanId.vlanId((short) 101)); - - Set<Interface> interfaces = Sets.newHashSet(intf, newIntf); - - // New interface config updates the existing interface and adds a new - // interface to the same connect point - InterfaceConfig ic = new TestInterfaceConfig(cp, interfaces); - - configs.put(cp, ic); - - NetworkConfigEvent event = new NetworkConfigEvent( - NetworkConfigEvent.Type.CONFIG_UPDATED, cp, CONFIG_CLASS); - - // Send in the event signalling the interfaces for this connect point - // have been updated - listener.event(event); - - assertEquals(NUM_INTERFACES + 1, interfaceManager.getInterfaces().size()); - assertEquals(interfaces, interfaceManager.getInterfacesByPort(cp)); - } - - @Test - public void testRemoveInterface() throws Exception { - ConnectPoint cp = createConnectPoint(1); - - NetworkConfigEvent event = new NetworkConfigEvent( - NetworkConfigEvent.Type.CONFIG_REMOVED, cp, CONFIG_CLASS); - - assertEquals(NUM_INTERFACES, interfaceManager.getInterfaces().size()); - - // Send in a config event removing an interface config - listener.event(event); - - assertEquals(NUM_INTERFACES - 1, interfaceManager.getInterfaces().size()); - } - - /** - * Test version of NetworkConfigService which allows us to pass in subjects - * and InterfaceConfigs directly. - */ - private class TestNetworkConfigService extends NetworkConfigServiceAdapter { - private final Set<ConnectPoint> subjects; - private final Map<ConnectPoint, InterfaceConfig> configs; - - public TestNetworkConfigService(Set<ConnectPoint> subjects, - Map<ConnectPoint, InterfaceConfig> configs) { - this.subjects = subjects; - this.configs = configs; - } - - @Override - public <S, C extends Config<S>> Set<S> getSubjects(Class<S> subjectClass, - Class<C> configClass) { - return (Set<S>) subjects; - } - - @Override - public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { - return (C) configs.get(subject); - } - - @Override - public void addListener(NetworkConfigListener listener) { - InterfaceManagerTest.this.listener = listener; - } - } - - /** - * Test version of InterfaceConfig where we can inject interfaces directly, - * rather than parsing them from JSON. - */ - private class TestInterfaceConfig extends InterfaceConfig { - private final ConnectPoint subject; - private final Set<Interface> interfaces; - - @Override - public ConnectPoint subject() { - return subject; - } - - public TestInterfaceConfig(ConnectPoint subject, Set<Interface> interfaces) { - this.subject = subject; - this.interfaces = interfaces; - } - - @Override - public Set<Interface> getInterfaces() throws ConfigException { - return interfaces; - } - } - -} 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 deleted file mode 100644 index bec9cded..00000000 --- a/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManagerTest.java +++ /dev/null @@ -1,171 +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.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.CoreServiceAdapter; -import org.onosproject.core.DefaultApplicationId; -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 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<McastEvent> 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("Mismatched events# obtained -> %s : expected %s", - events, evs)); - } - } - } - - class TestMulticastListener implements McastListener { - @Override - public void event(McastEvent event) { - events.add(event); - } - } - - private class TestCoreService extends CoreServiceAdapter { - @Override - public ApplicationId registerApplication(String name) { - return new DefaultApplicationId(0, name); - } - } -} 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 deleted file mode 100644 index 76caebcb..00000000 --- a/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/meter/impl/MeterManagerTest.java +++ /dev/null @@ -1,243 +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.incubator.net.meter.impl; - -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onlab.junit.TestUtils; -import org.onlab.packet.IpAddress; -import org.onosproject.cluster.ClusterServiceAdapter; -import org.onosproject.cluster.ControllerNode; -import org.onosproject.cluster.DefaultControllerNode; -import org.onosproject.cluster.NodeId; -import org.onosproject.common.event.impl.TestEventDispatcher; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.DefaultApplicationId; -import org.onosproject.incubator.store.meter.impl.DistributedMeterStore; -import org.onosproject.mastership.MastershipServiceAdapter; -import org.onosproject.net.DeviceId; -import org.onosproject.net.meter.Band; -import org.onosproject.net.meter.DefaultBand; -import org.onosproject.net.meter.DefaultMeter; -import org.onosproject.net.meter.DefaultMeterRequest; -import org.onosproject.net.meter.Meter; -import org.onosproject.net.meter.MeterId; -import org.onosproject.net.meter.MeterOperation; -import org.onosproject.net.meter.MeterOperations; -import org.onosproject.net.meter.MeterProvider; -import org.onosproject.net.meter.MeterProviderRegistry; -import org.onosproject.net.meter.MeterProviderService; -import org.onosproject.net.meter.MeterRequest; -import org.onosproject.net.meter.MeterService; -import org.onosproject.net.meter.MeterState; -import org.onosproject.net.provider.AbstractProvider; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.store.service.TestStorageService; - -import java.util.Collections; -import java.util.Map; -import java.util.Set; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.onosproject.net.NetTestTools.APP_ID; -import static org.onosproject.net.NetTestTools.did; -import static org.onosproject.net.NetTestTools.injectEventDispatcher; - -/** - * Meter manager tests. - */ -public class MeterManagerTest { - - private static final ProviderId PID = new ProviderId("of", "foo"); - private static final NodeId NID_LOCAL = new NodeId("local"); - private static final IpAddress LOCALHOST = IpAddress.valueOf("127.0.0.1"); - - private MeterService service; - private MeterManager manager; - private DistributedMeterStore meterStore; - private MeterProviderRegistry registry; - private MeterProviderService providerService; - - private TestProvider provider; - - private ApplicationId appId; - - - private Meter m1; - private Meter m2; - private MeterRequest.Builder m1Request; - private MeterRequest.Builder m2Request; - - private Map<MeterId, Meter> meters = Maps.newHashMap(); - - @Before - public void setup() throws Exception { - meterStore = new DistributedMeterStore(); - TestUtils.setField(meterStore, "storageService", new TestStorageService()); - TestUtils.setField(meterStore, "clusterService", new TestClusterService()); - TestUtils.setField(meterStore, "mastershipService", new TestMastershipService()); - meterStore.activate(); - - manager = new MeterManager(); - manager.store = meterStore; - TestUtils.setField(manager, "storageService", new TestStorageService()); - injectEventDispatcher(manager, new TestEventDispatcher()); - service = manager; - registry = manager; - - manager.activate(); - - provider = new TestProvider(PID); - providerService = registry.register(provider); - - appId = new TestApplicationId(0, "MeterManagerTest"); - - assertTrue("provider should be registered", - registry.getProviders().contains(provider.id())); - - Band band = DefaultBand.builder() - .ofType(Band.Type.DROP) - .withRate(500) - .build(); - - m1 = DefaultMeter.builder() - .forDevice(did("1")) - .fromApp(APP_ID) - .withId(MeterId.meterId(1)) - .withUnit(Meter.Unit.KB_PER_SEC) - .withBands(Collections.singletonList(band)) - .build(); - - m2 = DefaultMeter.builder() - .forDevice(did("2")) - .fromApp(APP_ID) - .withId(MeterId.meterId(1)) - .withUnit(Meter.Unit.KB_PER_SEC) - .withBands(Collections.singletonList(band)) - .build(); - - m1Request = DefaultMeterRequest.builder() - .forDevice(did("1")) - .fromApp(APP_ID) - .withUnit(Meter.Unit.KB_PER_SEC) - .withBands(Collections.singletonList(band)); - - m2Request = DefaultMeterRequest.builder() - .forDevice(did("2")) - .fromApp(APP_ID) - .withUnit(Meter.Unit.KB_PER_SEC) - .withBands(Collections.singletonList(band)); - - - } - - @After - public void tearDown() { - registry.unregister(provider); - assertFalse("provider should not be registered", - registry.getProviders().contains(provider.id())); - - manager.deactivate(); - injectEventDispatcher(manager, null); - - } - - @Test - public void testAddition() { - manager.submit(m1Request.add()); - - assertTrue("The meter was not added", manager.getAllMeters().size() == 1); - - assertThat(manager.getMeter(did("1"), MeterId.meterId(1)), is(m1)); - } - - @Test - public void testRemove() { - manager.submit(m1Request.add()); - manager.withdraw(m1Request.remove(), m1.id()); - - assertThat(manager.getMeter(did("1"), MeterId.meterId(1)).state(), - is(MeterState.PENDING_REMOVE)); - - providerService.pushMeterMetrics(m1.deviceId(), Collections.emptyList()); - - assertTrue("The meter was not removed", manager.getAllMeters().size() == 0); - - } - - @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) { - super(id, name); - } - } - - private class TestProvider extends AbstractProvider implements MeterProvider { - - protected TestProvider(ProviderId id) { - super(PID); - } - - @Override - public void performMeterOperation(DeviceId deviceId, MeterOperations meterOps) { - //Currently unused. - } - - @Override - public void performMeterOperation(DeviceId deviceId, MeterOperation meterOp) { - meters.put(meterOp.meter().id(), meterOp.meter()); - } - } - - private final class TestClusterService extends ClusterServiceAdapter { - - ControllerNode local = new DefaultControllerNode(NID_LOCAL, LOCALHOST); - - @Override - public ControllerNode getLocalNode() { - return local; - } - - @Override - public Set<ControllerNode> getNodes() { - return Sets.newHashSet(); - } - - } - - private class TestMastershipService extends MastershipServiceAdapter { - @Override - public NodeId getMasterFor(DeviceId deviceId) { - return NID_LOCAL; - } - } -} diff --git a/framework/src/onos/incubator/net/src/test/resources/domain-config.json b/framework/src/onos/incubator/net/src/test/resources/domain-config.json deleted file mode 100644 index beda11aa..00000000 --- a/framework/src/onos/incubator/net/src/test/resources/domain-config.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "domains" : { - "cord" : { - "basic" : { - "name" : "Core Fabric", - "applicationName" : "org.onosproject.testdomain", - "internalDevices" : [ "of:1" ], - "edgePorts" : [ "of:12/1", "of:14/1" ] - } - }, - "mpls" : { - "basic" : { - "name" : "MPLS Core", - "applicationName" : "org.onosproject.testdomain", - "internalDevices" : [ "of:2" ], - "edgePorts" : [ "of:12/2", "of:23/2" ] - } - }, - "dc" : { - "basic" : { - "name" : "Data Center Fabric", - "applicationName" : "org.onosproject.testdomain", - "internalDevices" : [ "of:3" ], - "edgePorts" : [ "of:23/3", "of:34/3" ] - } - }, - "optical" : { - "basic" : { - "name" : "Optical Core", - "applicationName" : "org.onosproject.testdomain", - "internalDevices" : [ "of:4" ], - "edgePorts" : [ "of:14/4", "of:34/4" ] - } - } - } -}
\ No newline at end of file diff --git a/framework/src/onos/incubator/net/src/test/resources/fractal-domain-config.json b/framework/src/onos/incubator/net/src/test/resources/fractal-domain-config.json deleted file mode 100644 index 521c840b..00000000 --- a/framework/src/onos/incubator/net/src/test/resources/fractal-domain-config.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "domains" : { - "domain1" : { - "basic" : { - "name" : "Domain 1", - "applicationName" : "org.onosproject.meshdomain", - "internalDevices" : [ "of:0000000000001001", "of:0000000000001002", "of:0000000000001003" ], - "edgePorts" : [ "of:0000000000010000/1", "of:0000000003010000/2", "of:0000000002010000/1" ] - } - }, - "domain2" : { - "basic" : { - "name" : "Domain 2", - "applicationName" : "org.onosproject.meshdomain", - "internalDevices" : [ "of:0000000000002001", "of:0000000000002002", "of:0000000000002003" ], - "edgePorts" : [ "of:0000000000020000/1", "of:0000000003020000/1", "of:0000000002010000/2" ] - } - }, - "domain3" : { - "basic" : { - "name" : "Domain 3", - "applicationName" : "org.onosproject.meshdomain", - "internalDevices" : [ "of:0000000000003001", "of:0000000000003002", "of:0000000000003003" ], - "edgePorts" : [ "of:0000000000030000/1", "of:0000000003010000/1", "of:0000000003020000/2" ] - } - } - } -}
\ No newline at end of file |