diff options
Diffstat (limited to 'framework/src')
45 files changed, 2230 insertions, 233 deletions
diff --git a/framework/src/onos/apps/routing/pom.xml b/framework/src/onos/apps/routing/pom.xml index c461ef3f..2882f52e 100644 --- a/framework/src/onos/apps/routing/pom.xml +++ b/framework/src/onos/apps/routing/pom.xml @@ -43,7 +43,7 @@ <version>${project.version}</version> </dependency> - <dependency> + <dependency> <groupId>org.onosproject</groupId> <artifactId>onlab-thirdparty</artifactId> </dependency> diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java index f2d5b5e2..a3cd6875 100644 --- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java @@ -15,24 +15,25 @@ */ package org.onosproject.sdnip; -import org.onosproject.core.ApplicationId; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentService; -import org.onosproject.net.intent.IntentState; -import org.onosproject.net.intent.Key; -import org.onosproject.routing.IntentSynchronizationService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static java.util.concurrent.Executors.newSingleThreadExecutor; +import static org.onlab.util.Tools.groupedThreads; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; -import static java.util.concurrent.Executors.newSingleThreadExecutor; -import static org.onlab.util.Tools.groupedThreads; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.intent.Intent; +import org.onosproject.net.intent.IntentService; +import org.onosproject.net.intent.IntentState; +import org.onosproject.net.intent.Key; +import org.onosproject.routing.IntentSynchronizationService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Synchronizes intents between the in-memory intent store and the @@ -97,55 +98,30 @@ public class IntentSynchronizer implements IntentSynchronizationService { synchronized (this) { // Stop the thread(s) intentsSynchronizerExecutor.shutdownNow(); + log.info("Intents Synchronizer Executor shutdown completed"); - // - // Withdraw all app related intents - // - if (!isElectedLeader) { - return; // Nothing to do: not the leader anymore - } + } + } - // - // NOTE: We don't withdraw the intents during shutdown, because - // it creates flux in the data plane during switchover. - // - - /* - // - // Build a batch operation to withdraw all intents from this - // application. - // - log.debug("Intent Synchronizer shutdown: " + - "withdrawing all intents..."); - IntentOperations.Builder builder = IntentOperations.builder(appId); - for (Intent intent : intentService.getIntents()) { - // Skip the intents from other applications - if (!intent.appId().equals(appId)) { - continue; - } + /** + * Withdraws all intents. + */ + public void removeIntents() { + if (!isElectedLeader) { + // only leader will withdraw intents + return; + } - // Skip the intents that are already withdrawn - IntentState intentState = - intentService.getIntentState(intent.id()); - if ((intentState == null) || - intentState.equals(IntentState.WITHDRAWING) || - intentState.equals(IntentState.WITHDRAWN)) { - continue; - } + log.debug("Intent Synchronizer shutdown: withdrawing all intents..."); - log.trace("Intent Synchronizer withdrawing intent: {}", - intent); - builder.addWithdrawOperation(intent.id()); - } - IntentOperations intentOperations = builder.build(); - intentService.execute(intentOperations); - leaderChanged(false); - - peerIntents.clear(); - routeIntents.clear(); - log.debug("Intent Synchronizer shutdown completed"); - */ + for (Entry<Key, Intent> entry : intents.entrySet()) { + intentService.withdraw(entry.getValue()); + log.debug("Intent Synchronizer withdrawing intent: {}", + entry.getValue()); } + + intents.clear(); + log.info("Tried to clean all intents"); } @Override @@ -261,5 +237,4 @@ public class IntentSynchronizer implements IntentSynchronizationService { } log.debug("Intent synchronization completed"); } - } diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java index a27baaf9..fb008aad 100644 --- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java @@ -340,15 +340,15 @@ public class PeerConnectivityManager { private TrafficSelector buildSelector(byte ipProto, IpAddress srcIp, IpAddress dstIp, Short srcTcpPort, Short dstTcpPort) { - TrafficSelector.Builder builder = DefaultTrafficSelector.builder() - .matchEthType(Ethernet.TYPE_IPV4) - .matchIPProtocol(ipProto); + TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchIPProtocol(ipProto); if (dstIp.isIp4()) { - builder.matchIPSrc(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET_MASK_LENGTH)) + builder.matchEthType(Ethernet.TYPE_IPV4) + .matchIPSrc(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET_MASK_LENGTH)) .matchIPDst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET_MASK_LENGTH)); } else { - builder.matchIPv6Src(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET6_MASK_LENGTH)) + builder.matchEthType(Ethernet.TYPE_IPV6) + .matchIPv6Src(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET6_MASK_LENGTH)) .matchIPv6Dst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET6_MASK_LENGTH)); } diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java index 1b3eda9d..ace888d1 100644 --- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java @@ -15,12 +15,17 @@ */ package org.onosproject.sdnip; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Objects; + 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.app.ApplicationService; import org.onosproject.cluster.ClusterService; import org.onosproject.cluster.ControllerNode; import org.onosproject.cluster.LeadershipEvent; @@ -28,8 +33,8 @@ import org.onosproject.cluster.LeadershipEventListener; import org.onosproject.cluster.LeadershipService; import org.onosproject.core.ApplicationId; import org.onosproject.core.CoreService; -import org.onosproject.net.config.NetworkConfigService; import org.onosproject.incubator.net.intf.InterfaceService; +import org.onosproject.net.config.NetworkConfigService; import org.onosproject.net.host.HostService; import org.onosproject.net.intent.IntentService; import org.onosproject.routing.IntentSynchronizationService; @@ -38,10 +43,6 @@ import org.onosproject.routing.SdnIpService; import org.onosproject.routing.config.RoutingConfigurationService; import org.slf4j.Logger; -import java.util.Objects; - -import static org.slf4j.LoggerFactory.getLogger; - /** * Component for the SDN-IP peering application. */ @@ -59,6 +60,9 @@ public class SdnIp implements SdnIpService { protected IntentService intentService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected ApplicationService applicationService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected HostService hostService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) @@ -84,7 +88,7 @@ public class SdnIp implements SdnIpService { private SdnIpFib fib; private LeadershipEventListener leadershipEventListener = - new InnerLeadershipEventListener(); + new InnerLeadershipEventListener(); private ApplicationId appId; private ControllerNode localControllerNode; @@ -113,6 +117,10 @@ public class SdnIp implements SdnIpService { leadershipService.addListener(leadershipEventListener); leadershipService.runForLeadership(appId.name()); + + applicationService.registerDeactivateHook(appId, + intentSynchronizer::removeIntents); + } @Deactivate diff --git a/framework/src/onos/apps/vtn/app/pom.xml b/framework/src/onos/apps/vtn/app/pom.xml index 4ed66172..5a877363 100644 --- a/framework/src/onos/apps/vtn/app/pom.xml +++ b/framework/src/onos/apps/vtn/app/pom.xml @@ -1,44 +1,44 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- ~ Copyright 2014 Open Networking Laboratory ~ ~ Licensed under the Apache - License, Version 2.0 (the "License"); ~ you may not use this file except - in compliance with the License. ~ You may obtain a copy of the License at - ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable - law or agreed to in writing, software ~ distributed under the License is - distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. ~ See the License for the specific language - governing permissions and ~ limitations under the License. --> +<!-- ~ Copyright 2014 Open Networking Laboratory ~ ~ Licensed under the Apache + License, Version 2.0 (the "License"); ~ you may not use this file except + in compliance with the License. ~ You may obtain a copy of the License at + ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable + law or agreed to in writing, software ~ distributed under the License is + distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. ~ See the License for the specific language + governing permissions and ~ limitations under the License. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <artifactId>onos-app-vtn-onosfw</artifactId> - <packaging>pom</packaging> + <artifactId>onos-app-vtn-onosfw</artifactId> + <packaging>pom</packaging> - <description>ONOS framework applications</description> + <description>ONOS framework applications</description> - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-rsc</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-web</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-mgr</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-rsc</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-web</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-mgr</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> </project> diff --git a/framework/src/onos/apps/vtn/pom.xml b/framework/src/onos/apps/vtn/pom.xml index e91b0c9b..e8387cb7 100644 --- a/framework/src/onos/apps/vtn/pom.xml +++ b/framework/src/onos/apps/vtn/pom.xml @@ -36,9 +36,9 @@ <module>vtnmgr</module> <module>vtnweb</module> <module>app</module> - </modules> - <dependencies> - <dependency> + </modules> + <dependencies> + <dependency> <groupId>org.onosproject</groupId> <artifactId>onlab-junit</artifactId> <scope>test</scope> diff --git a/framework/src/onos/apps/vtn/vtnrsc/pom.xml b/framework/src/onos/apps/vtn/vtnrsc/pom.xml index 8696295c..816624cb 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/pom.xml +++ b/framework/src/onos/apps/vtn/vtnrsc/pom.xml @@ -15,42 +15,42 @@ ~ limitations under the License. --> <project - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <artifactId>onos-app-vtn-rsc</artifactId> - <packaging>bundle</packaging> + <artifactId>onos-app-vtn-rsc</artifactId> + <packaging>bundle</packaging> - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-api</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-cli</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - <dependency> - <groupId>org.apache.karaf.shell</groupId> - <artifactId>org.apache.karaf.shell.console</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-core-serializers</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-api</artifactId> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-cli</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + </dependency> + <dependency> + <groupId>org.apache.karaf.shell</groupId> + <artifactId>org.apache.karaf.shell.console</artifactId> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-core-serializers</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> </project> diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.java new file mode 100644 index 00000000..6b0d9a64 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.java @@ -0,0 +1,148 @@ +/* + * 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.vtnrsc.flowclassifier; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onlab.packet.IpPrefix; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.DefaultFlowClassifier; +import org.onosproject.vtnrsc.FlowClassifierId; +import org.onosproject.vtnrsc.VirtualPortId; +import org.onosproject.vtnrsc.FlowClassifier; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultFlowClassifier class. + */ +public class DefaultFlowClassifierTest { + /** + * Checks that the DefaultFlowClassifier class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(DefaultFlowClassifier.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + // Create same two flow classifier objects. + final String name = "FlowClassifier1"; + final String description = "FlowClassifier1"; + final String ethType = "IPv4"; + final String protocol = "tcp"; + final int minSrcPortRange = 5; + final int maxSrcPortRange = 10; + final int minDstPortRange = 5; + final int maxDstPortRange = 10; + final FlowClassifierId flowClassifierId = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0"); + final IpPrefix dstIpPrefix = IpPrefix.valueOf("10.10.10.10/0"); + final VirtualPortId virtualSrcPort = VirtualPortId.portId("1"); + final VirtualPortId virtualDstPort = VirtualPortId.portId("2"); + + DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder(); + final FlowClassifier flowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId) + .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType) + .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange) + .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix) + .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build(); + + flowClassifierBuilder = new DefaultFlowClassifier.Builder(); + final FlowClassifier sameAsFlowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId) + .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType) + .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange) + .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix) + .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build(); + + // Create different classifier object. + final String name2 = "FlowClassifier2"; + final String description2 = "FlowClassifier2"; + final String ethType2 = "IPv6"; + final String protocol2 = "udp"; + final int minSrcPortRange2 = 5; + final int maxSrcPortRange2 = 10; + final int minDstPortRange2 = 5; + final int maxDstPortRange2 = 10; + final FlowClassifierId flowClassifierId2 = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId2 = TenantId.tenantId("2"); + final IpPrefix srcIpPrefix2 = IpPrefix.valueOf("0.0.0.0/0"); + final IpPrefix dstIpPrefix2 = IpPrefix.valueOf("10.10.10.10/0"); + final VirtualPortId virtualSrcPort2 = VirtualPortId.portId("3"); + final VirtualPortId virtualDstPort2 = VirtualPortId.portId("4"); + + DefaultFlowClassifier.Builder flowClassifierBuilder3 = new DefaultFlowClassifier.Builder(); + final FlowClassifier flowClassifier2 = flowClassifierBuilder3.setFlowClassifierId(flowClassifierId2) + .setTenantId(tenantId2).setName(name2).setDescription(description2).setEtherType(ethType2) + .setProtocol(protocol2).setMinSrcPortRange(minSrcPortRange2).setMaxSrcPortRange(maxSrcPortRange2) + .setMinDstPortRange(minDstPortRange2).setMaxDstPortRange(maxDstPortRange2).setSrcIpPrefix(srcIpPrefix2) + .setDstIpPrefix(dstIpPrefix2).setSrcPort(virtualSrcPort2).setDstPort(virtualDstPort2).build(); + + new EqualsTester().addEqualityGroup(flowClassifier1, sameAsFlowClassifier1).addEqualityGroup(flowClassifier2) + .testEquals(); + } + + /** + * Checks the construction of a DefaultFlowClassifier object. + */ + @Test + public void testConstruction() { + final String name = "FlowClassifier"; + final String description = "FlowClassifier"; + final String ethType = "IPv4"; + final String protocol = "tcp"; + final int minSrcPortRange = 5; + final int maxSrcPortRange = 10; + final int minDstPortRange = 5; + final int maxDstPortRange = 10; + final FlowClassifierId flowClassifierId = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0"); + final IpPrefix dstIpPrefix = IpPrefix.valueOf("10.10.10.10/0"); + final VirtualPortId virtualSrcPort = VirtualPortId.portId("1"); + final VirtualPortId virtualDstPort = VirtualPortId.portId("2"); + + DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder(); + final FlowClassifier flowClassifier = flowClassifierBuilder.setFlowClassifierId(flowClassifierId) + .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType) + .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange) + .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix) + .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build(); + + assertThat(flowClassifierId, is(flowClassifier.flowClassifierId())); + assertThat(tenantId, is(flowClassifier.tenantId())); + assertThat(name, is(flowClassifier.name())); + assertThat(description, is(flowClassifier.description())); + assertThat(ethType, is(flowClassifier.etherType())); + assertThat(protocol, is(flowClassifier.protocol())); + assertThat(minSrcPortRange, is(flowClassifier.minSrcPortRange())); + assertThat(maxSrcPortRange, is(flowClassifier.maxSrcPortRange())); + assertThat(minDstPortRange, is(flowClassifier.minDstPortRange())); + assertThat(maxDstPortRange, is(flowClassifier.maxDstPortRange())); + assertThat(srcIpPrefix, is(flowClassifier.srcIpPrefix())); + assertThat(dstIpPrefix, is(flowClassifier.dstIpPrefix())); + assertThat(virtualSrcPort, is(flowClassifier.srcPort())); + assertThat(virtualDstPort, is(flowClassifier.dstPort())); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/DefaultPortChainTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/DefaultPortChainTest.java new file mode 100644 index 00000000..b9ce73d8 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/DefaultPortChainTest.java @@ -0,0 +1,140 @@ +/* + * 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.vtnrsc.flowclassifier; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import java.util.List; +import java.util.LinkedList; + +import org.onosproject.vtnrsc.PortChainId; +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.FlowClassifierId; +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.DefaultPortChain; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultPortChain class. + */ +public class DefaultPortChainTest { + /** + * Checks that the DefaultPortChain class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(DefaultPortChain.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + // Create same two port chain objects. + final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortChain1"; + final String description = "PortChain1"; + // create list of Port Pair Groups. + final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>(); + PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairGroups.add(portPairGroupId); + portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af"); + portPairGroups.add(portPairGroupId); + // create list of Flow classifiers. + final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>(); + FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); + flowClassifiers.add(flowClassifierId); + flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af"); + flowClassifiers.add(flowClassifierId); + + DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder(); + final PortChain portChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name) + .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers) + .build(); + + portChainBuilder = new DefaultPortChain.Builder(); + final PortChain samePortChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name) + .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers) + .build(); + + // Create different port chain object. + final PortChainId portChainId2 = PortChainId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId2 = TenantId.tenantId("2"); + final String name2 = "PortChain2"; + final String description2 = "PortChain2"; + // create list of Port Pair Groups. + final List<PortPairGroupId> portPairGroups2 = new LinkedList<PortPairGroupId>(); + portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairGroups2.add(portPairGroupId); + portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3af"); + portPairGroups2.add(portPairGroupId); + // create list of Flow classifiers. + final List<FlowClassifierId> flowClassifiers2 = new LinkedList<FlowClassifierId>(); + flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae"); + flowClassifiers2.add(flowClassifierId); + flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3af"); + flowClassifiers2.add(flowClassifierId); + + portChainBuilder = new DefaultPortChain.Builder(); + final PortChain portChain2 = portChainBuilder.setId(portChainId2).setTenantId(tenantId2).setName(name2) + .setDescription(description2).setPortPairGroups(portPairGroups2).setFlowClassifiers(flowClassifiers2) + .build(); + + new EqualsTester().addEqualityGroup(portChain1, samePortChain1).addEqualityGroup(portChain2).testEquals(); + } + + /** + * Checks the construction of a DefaultPortChain object. + */ + @Test + public void testConstruction() { + final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortChain"; + final String description = "PortChain"; + // create list of Port Pair Groups. + final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>(); + PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairGroups.add(portPairGroupId); + portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af"); + portPairGroups.add(portPairGroupId); + // create list of Flow classifiers. + final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>(); + FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); + flowClassifiers.add(flowClassifierId); + flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af"); + flowClassifiers.add(flowClassifierId); + + DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder(); + final PortChain portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name) + .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers) + .build(); + + assertThat(portChainId, is(portChain.portChainId())); + assertThat(tenantId, is(portChain.tenantId())); + assertThat(name, is(portChain.name())); + assertThat(description, is(portChain.description())); + assertThat(portPairGroups, is(portChain.portPairGroups())); + assertThat(flowClassifiers, is(portChain.flowClassifiers())); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/DefaultPortPairTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/DefaultPortPairTest.java new file mode 100644 index 00000000..91e7ab37 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/DefaultPortPairTest.java @@ -0,0 +1,102 @@ +/* + * 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.vtnrsc.flowclassifier; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; + +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.DefaultPortPair; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultPortPair class. + */ +public class DefaultPortPairTest { + /** + * Checks that the DefaultPortPair class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(DefaultPortPair.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + // Create same two port pair objects. + final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortPair1"; + final String description = "PortPair1"; + final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1"; + final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345"; + + DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder(); + final PortPair portPair1 = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name) + .setDescription(description).setIngress(ingress).setEgress(egress).build(); + + portPairBuilder = new DefaultPortPair.Builder(); + final PortPair samePortPair1 = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name) + .setDescription(description).setIngress(ingress).setEgress(egress).build(); + + // Create different port pair object. + final PortPairId portPairId2 = PortPairId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId2 = TenantId.tenantId("2"); + final String name2 = "PortPair2"; + final String description2 = "PortPair2"; + final String ingress2 = "d5555555-24fc-4fae-af4b-321c5e2eb3d1"; + final String egress2 = "a6666666-4a56-2a6e-cd3a-9dee4e2ec345"; + + portPairBuilder = new DefaultPortPair.Builder(); + final PortPair portPair2 = portPairBuilder.setId(portPairId2).setTenantId(tenantId2).setName(name2) + .setDescription(description2).setIngress(ingress2).setEgress(egress2).build(); + + new EqualsTester().addEqualityGroup(portPair1, samePortPair1).addEqualityGroup(portPair2).testEquals(); + } + + /** + * Checks the construction of a DefaultPortPair object. + */ + @Test + public void testConstruction() { + final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortPair"; + final String description = "PortPair"; + final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1"; + final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345"; + + DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder(); + final PortPair portPair = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name) + .setDescription(description).setIngress(ingress).setEgress(egress).build(); + + assertThat(portPairId, is(portPair.portPairId())); + assertThat(tenantId, is(portPair.tenantId())); + assertThat(name, is(portPair.name())); + assertThat(description, is(portPair.description())); + assertThat(ingress, is(portPair.ingress())); + assertThat(egress, is(portPair.egress())); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/DefaultPortPairGroupTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/DefaultPortPairGroupTest.java new file mode 100644 index 00000000..2528fb29 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/DefaultPortPairGroupTest.java @@ -0,0 +1,117 @@ +/* + * 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.vtnrsc.flowclassifier; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import java.util.List; +import java.util.LinkedList; + +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.DefaultPortPairGroup; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultPortPairGroup class. + */ +public class DefaultPortPairGroupTest { + /** + * Checks that the DefaultPortPairGroup class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(DefaultPortPairGroup.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + // Create same two port-pair-group objects. + final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortPairGroup1"; + final String description = "PortPairGroup1"; + // create port-pair-id list + final List<PortPairId> portPairList = new LinkedList<PortPairId>(); + PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList.add(portPairId); + portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList.add(portPairId); + + DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder(); + final PortPairGroup portPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId) + .setName(name).setDescription(description).setPortPairs(portPairList).build(); + + portPairGroupBuilder = new DefaultPortPairGroup.Builder(); + final PortPairGroup samePortPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId) + .setName(name).setDescription(description).setPortPairs(portPairList).build(); + + // Create different port-pair-group object. + final PortPairGroupId portPairGroupId2 = PortPairGroupId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId2 = TenantId.tenantId("2"); + final String name2 = "PortPairGroup2"; + final String description2 = "PortPairGroup2"; + // create port-pair-id list + final List<PortPairId> portPairList2 = new LinkedList<PortPairId>(); + portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList2.add(portPairId); + portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList2.add(portPairId); + + portPairGroupBuilder = new DefaultPortPairGroup.Builder(); + final PortPairGroup portPairGroup2 = portPairGroupBuilder.setId(portPairGroupId2).setTenantId(tenantId2) + .setName(name2).setDescription(description2).setPortPairs(portPairList2).build(); + + new EqualsTester().addEqualityGroup(portPairGroup1, samePortPairGroup1).addEqualityGroup(portPairGroup2) + .testEquals(); + } + + /** + * Checks the construction of a DefaultPortPairGroup object. + */ + @Test + public void testConstruction() { + final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortPairGroup"; + final String description = "PortPairGroup"; + // create port-pair-id list + final List<PortPairId> portPairList = new LinkedList<PortPairId>(); + PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList.add(portPairId); + portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList.add(portPairId); + + DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder(); + final PortPairGroup portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId) + .setName(name).setDescription(description).setPortPairs(portPairList).build(); + + assertThat(portPairGroupId, is(portPairGroup.portPairGroupId())); + assertThat(tenantId, is(portPairGroup.tenantId())); + assertThat(name, is(portPairGroup.name())); + assertThat(description, is(portPairGroup.description())); + assertThat(portPairList, is(portPairGroup.portPairs())); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java new file mode 100644 index 00000000..1445c763 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java @@ -0,0 +1,47 @@ +/* + * 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.bgpio.protocol; + +import java.util.List; + +import org.onosproject.bgpio.types.BGPValueType; +import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; + +/** + * Abstraction of an entity providing BGP-LS Link NLRI. + */ +public interface BgpLinkLsNlri extends BGPLSNlri { + /** + * Returns local node descriptors. + * + * @return local node descriptors + */ + NodeDescriptors getLocalNodeDescriptors(); + + /** + * Returns remote node descriptors. + * + * @return remote node descriptors + */ + NodeDescriptors getRemoteNodeDescriptors(); + + /** + * Returns link descriptors. + * + * @return link descriptors + */ + List<BGPValueType> getLinkDescriptors(); +}
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java new file mode 100644 index 00000000..969936c8 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java @@ -0,0 +1,48 @@ +/* + * 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.bgpio.protocol; + +import java.util.List; + +import org.onlab.packet.IpPrefix; +import org.onosproject.bgpio.protocol.ver4.BgpPathAttributes; + +/** + * Abstraction of an entity providing BGP Update Message. + */ +public interface BgpUpdateMsg extends BGPMessage { + /** + * Returns path attributes in BGP Update Message. + * + * @return path attributes in BGP Update Message + */ + BgpPathAttributes bgpPathAttributes(); + + /** + * Returns withdrawn Routes. + * + * @return withdrawn Routes + */ + List<IpPrefix> withdrawnRoutes(); + + /** + * Returns NLRI list of prefix. + * + * @return NLRI list of prefix + */ + List<IpPrefix> nlri(); +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java new file mode 100644 index 00000000..9f4cf9b9 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java @@ -0,0 +1,285 @@ +/* + * 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.bgpio.protocol.ver4; + +import java.util.LinkedList; +import java.util.List; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onlab.packet.IpPrefix; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.protocol.BGPMessageReader; +import org.onosproject.bgpio.protocol.BGPType; +import org.onosproject.bgpio.protocol.BgpUpdateMsg; +import org.onosproject.bgpio.types.BGPErrorType; +import org.onosproject.bgpio.types.BGPHeader; +import org.onosproject.bgpio.util.Validation; +import org.onosproject.bgpio.protocol.BGPVersion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * BGP Update Message: UPDATE messages are used to transfer routing information + * between BGP peers. The information in the UPDATE message is used by core to + * construct a graph + */ +public class BgpUpdateMsgVer4 implements BgpUpdateMsg { + + /* 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | + + + + | | + + + + | Marker | + + + + | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Length | Type | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Withdrawn Routes Length (2 octets) | + +-----------------------------------------------------+ + | Withdrawn Routes (variable) | + +-----------------------------------------------------+ + | Total Path Attribute Length (2 octets) | + +-----------------------------------------------------+ + | Path Attributes (variable) | + +-----------------------------------------------------+ + | Network Layer Reachability Information (variable) | + +-----------------------------------------------------+ + REFERENCE : RFC 4271 + */ + + protected static final Logger log = LoggerFactory + .getLogger(BgpUpdateMsgVer4.class); + + public static final byte PACKET_VERSION = 4; + //Withdrawn Routes Length(2) + Total Path Attribute Length(2) + public static final int PACKET_MINIMUM_LENGTH = 4; + public static final int BYTE_IN_BITS = 8; + public static final int MIN_LEN_AFTER_WITHDRW_ROUTES = 2; + public static final int MINIMUM_COMMON_HEADER_LENGTH = 19; + public static final BGPType MSG_TYPE = BGPType.UPDATE; + public static final BgpUpdateMsgVer4.Reader READER = new Reader(); + + private List<IpPrefix> withdrawnRoutes; + private BgpPathAttributes bgpPathAttributes; + private BGPHeader bgpHeader; + private List<IpPrefix> nlri; + + /** + * Constructor to initialize parameters for BGP Update message. + * + * @param bgpHeader in Update message + * @param withdrawnRoutes withdrawn routes + * @param bgpPathAttributes BGP Path attributes + * @param nlri Network Layer Reachability Information + */ + public BgpUpdateMsgVer4(BGPHeader bgpHeader, List<IpPrefix> withdrawnRoutes, + BgpPathAttributes bgpPathAttributes, List<IpPrefix> nlri) { + this.bgpHeader = bgpHeader; + this.withdrawnRoutes = withdrawnRoutes; + this.bgpPathAttributes = bgpPathAttributes; + this.nlri = nlri; + } + + /** + * Reader reads BGP Update Message from the channel buffer. + */ + static class Reader implements BGPMessageReader<BgpUpdateMsg> { + + @Override + public BgpUpdateMsg readFrom(ChannelBuffer cb, BGPHeader bgpHeader) + throws BGPParseException { + + if (cb.readableBytes() != (bgpHeader.getLength() - MINIMUM_COMMON_HEADER_LENGTH)) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.BAD_MESSAGE_LENGTH, bgpHeader.getLength()); + } + + LinkedList<IpPrefix> withDrwRoutes = new LinkedList<>(); + LinkedList<IpPrefix> nlri = new LinkedList<>(); + BgpPathAttributes bgpPathAttributes = new BgpPathAttributes(); + // Reading Withdrawn Routes Length + Short withDrwLen = cb.readShort(); + + if (cb.readableBytes() < withDrwLen) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + ChannelBuffer tempCb = cb.readBytes(withDrwLen); + if (withDrwLen != 0) { + // Parsing WithdrawnRoutes + withDrwRoutes = parseWithdrawnRoutes(tempCb); + } + if (cb.readableBytes() < MIN_LEN_AFTER_WITHDRW_ROUTES) { + log.debug("Bgp Path Attribute len field not present"); + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null); + } + + // Reading Total Path Attribute Length + short totPathAttrLen = cb.readShort(); + int len = withDrwLen + totPathAttrLen + PACKET_MINIMUM_LENGTH; + if (len > bgpHeader.getLength()) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null); + } + if (totPathAttrLen != 0) { + // Parsing BGPPathAttributes + if (cb.readableBytes() < totPathAttrLen) { + Validation + .validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + tempCb = cb.readBytes(totPathAttrLen); + bgpPathAttributes = BgpPathAttributes.read(tempCb); + } + if (cb.readableBytes() > 0) { + // Parsing NLRI + nlri = parseNlri(cb); + } + return new BgpUpdateMsgVer4(bgpHeader, withDrwRoutes, + bgpPathAttributes, nlri); + } + } + + /** + * Parses NLRI from channel buffer. + * + * @param cb channelBuffer + * @return list of IP Prefix + * @throws BGPParseException while parsing NLRI + */ + public static LinkedList<IpPrefix> parseNlri(ChannelBuffer cb) + throws BGPParseException { + LinkedList<IpPrefix> nlri = new LinkedList<>(); + while (cb.readableBytes() > 0) { + int length = cb.readByte(); + IpPrefix ipPrefix; + if (length == 0) { + byte[] prefix = new byte[] {0}; + ipPrefix = Validation.bytesToPrefix(prefix, length); + nlri.add(ipPrefix); + } else { + int len = length / BYTE_IN_BITS; + int reminder = length % BYTE_IN_BITS; + if (reminder > 0) { + len = len + 1; + } + if (cb.readableBytes() < len) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + byte[] prefix = new byte[len]; + cb.readBytes(prefix, 0, len); + ipPrefix = Validation.bytesToPrefix(prefix, length); + nlri.add(ipPrefix); + } + } + return nlri; + } + + /** + * Parsing withdrawn routes from channel buffer. + * + * @param cb channelBuffer + * @return list of IP prefix + * @throws BGPParseException while parsing withdrawn routes + */ + public static LinkedList<IpPrefix> parseWithdrawnRoutes(ChannelBuffer cb) + throws BGPParseException { + LinkedList<IpPrefix> withDrwRoutes = new LinkedList<>(); + while (cb.readableBytes() > 0) { + int length = cb.readByte(); + IpPrefix ipPrefix; + if (length == 0) { + byte[] prefix = new byte[] {0}; + ipPrefix = Validation.bytesToPrefix(prefix, length); + withDrwRoutes.add(ipPrefix); + } else { + int len = length / BYTE_IN_BITS; + int reminder = length % BYTE_IN_BITS; + if (reminder > 0) { + len = len + 1; + } + if (cb.readableBytes() < len) { + Validation + .validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + byte[] prefix = new byte[len]; + cb.readBytes(prefix, 0, len); + ipPrefix = Validation.bytesToPrefix(prefix, length); + withDrwRoutes.add(ipPrefix); + } + } + return withDrwRoutes; + } + + @Override + public BGPVersion getVersion() { + return BGPVersion.BGP_4; + } + + @Override + public BGPType getType() { + return BGPType.UPDATE; + } + + @Override + public void writeTo(ChannelBuffer channelBuffer) throws BGPParseException { + //Not to be implemented as of now + } + + @Override + public BgpPathAttributes bgpPathAttributes() { + return this.bgpPathAttributes; + } + + @Override + public List<IpPrefix> withdrawnRoutes() { + return withdrawnRoutes; + } + + @Override + public List<IpPrefix> nlri() { + return nlri; + } + + @Override + public BGPHeader getHeader() { + return this.bgpHeader; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .omitNullValues() + .add("bgpHeader", bgpHeader) + .add("withDrawnRoutes", withdrawnRoutes) + .add("nlri", nlri) + .add("bgpPathAttributes", bgpPathAttributes) + .toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java new file mode 100644 index 00000000..90a1cc6b --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java @@ -0,0 +1,221 @@ +/* + * 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.bgpio.types; + +import java.net.InetAddress; +import java.util.LinkedList; +import java.util.List; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onlab.packet.Ip4Address; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.protocol.BGPLSNlri; +import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4; +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4; +import org.onosproject.bgpio.util.Constants; +import org.onosproject.bgpio.util.Validation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/* + * Provides Implementation of MpReach Nlri BGP Path Attribute. + */ +public class MpReachNlri implements BGPValueType { + + private static final Logger log = LoggerFactory.getLogger(MpReachNlri.class); + + public static final byte MPREACHNLRI_TYPE = 14; + public static final byte LINK_NLRITYPE = 2; + + private boolean isMpReachNlri = false; + private final List<BGPLSNlri> mpReachNlri; + private final int length; + private final short afi; + private final byte safi; + private final Ip4Address ipNextHop; + + /** + * Constructor to initialize parameters. + * + * @param mpReachNlri MpReach Nlri attribute + * @param afi address family identifier + * @param safi subsequent address family identifier + * @param ipNextHop nexthop IpAddress + * @param length of MpReachNlri + */ + public MpReachNlri(List<BGPLSNlri> mpReachNlri, short afi, byte safi, Ip4Address ipNextHop, int length) { + this.mpReachNlri = mpReachNlri; + this.isMpReachNlri = true; + this.ipNextHop = ipNextHop; + this.afi = afi; + this.safi = safi; + this.length = length; + } + + /** + * Returns whether MpReachNlri is present. + * + * @return whether MpReachNlri is present + */ + public boolean isMpReachNlriSet() { + return this.isMpReachNlri; + } + + /** + * Returns list of MpReach Nlri. + * + * @return list of MpReach Nlri + */ + public List<BGPLSNlri> mpReachNlri() { + return this.mpReachNlri; + } + + /** + * Returns length of MpReachNlri. + * + * @return length of MpReachNlri + */ + public int mpReachNlriLen() { + return this.length; + } + + /** + * Reads from ChannelBuffer and parses MpReachNlri. + * + * @param cb channelBuffer + * @return object of MpReachNlri + * @throws BGPParseException while parsing MpReachNlri + */ + public static MpReachNlri read(ChannelBuffer cb) throws BGPParseException { + ChannelBuffer tempBuf = cb.copy(); + Validation parseFlags = Validation.parseAttributeHeader(cb); + int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : + parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE; + ChannelBuffer data = tempBuf.readBytes(len); + + if (cb.readableBytes() < parseFlags.getLength()) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + parseFlags.getLength()); + } + if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data); + } + + BGPLSNlri bgpLSNlri = null; + List<BGPLSNlri> mpReachNlri = new LinkedList<>(); + ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength()); + short afi = 0; + byte safi = 0; + Ip4Address ipNextHop = null; + while (tempCb.readableBytes() > 0) { + afi = tempCb.readShort(); + safi = tempCb.readByte(); + + //Supporting for AFI 16388 / SAFI 71 and VPN AFI 16388 / SAFI 128 + if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE) || (afi == Constants.AFI_VALUE) + && (safi == Constants.VPN_SAFI_VALUE)) { + byte nextHopLen = tempCb.readByte(); + //TODO: use Validation.toInetAddress once Validation is merged + InetAddress ipAddress = (InetAddress) cb.readBytes(nextHopLen); + if (ipAddress.isMulticastAddress()) { + throw new BGPParseException("Multicast not supported"); + } + ipNextHop = Ip4Address.valueOf(ipAddress); + byte reserved = tempCb.readByte(); + + while (tempCb.readableBytes() > 0) { + short nlriType = tempCb.readShort(); + short totNlriLen = tempCb.readShort(); + if (tempCb.readableBytes() < totNlriLen) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); + } + tempBuf = tempCb.readBytes(totNlriLen); + switch (nlriType) { + case BGPNodeLSNlriVer4.NODE_NLRITYPE: + bgpLSNlri = BGPNodeLSNlriVer4.read(tempBuf, afi, safi); + break; + case LINK_NLRITYPE: + //TODO: To be merged later + break; + case BGPPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE: + bgpLSNlri = BGPPrefixIPv4LSNlriVer4.read(tempBuf, afi, safi); + break; + default: + log.debug("nlriType not supported" + nlriType); + } + mpReachNlri.add(bgpLSNlri); + } + } else { + //TODO: check with the values got from capability + throw new BGPParseException("Not Supporting afi " + afi + "safi " + safi); + } + } + return new MpReachNlri(mpReachNlri, afi, safi, ipNextHop, parseFlags.getLength()); + } + + @Override + public short getType() { + return MPREACHNLRI_TYPE; + } + + /** + * Returns AFI. + * + * @return AFI + */ + public short afi() { + return this.afi; + } + + /** + * Returns Nexthop IpAddress. + * + * @return Nexthop IpAddress + */ + public Ip4Address nexthop4() { + return this.ipNextHop; + } + + /** + * Returns SAFI. + * + * @return SAFI + */ + public byte safi() { + return this.safi; + } + + @Override + public int write(ChannelBuffer cb) { + //Not to be Implemented as of now + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("mpReachNlri", mpReachNlri) + .add("afi", afi) + .add("safi", safi) + .add("ipNextHop", ipNextHop) + .add("length", length) + .toString(); + } +}
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java new file mode 100644 index 00000000..3efed95c --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java @@ -0,0 +1,203 @@ +/* + * 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.bgpio.types; + +import java.util.LinkedList; +import java.util.List; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.protocol.BGPLSNlri; +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4; +import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4; +import org.onosproject.bgpio.util.Constants; +import org.onosproject.bgpio.util.Validation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * Provides Implementation of MpUnReach Nlri BGP Path Attribute. + */ +public class MpUnReachNlri implements BGPValueType { + + protected static final Logger log = LoggerFactory.getLogger(MpUnReachNlri.class); + + public static final byte MPUNREACHNLRI_TYPE = 15; + public static final byte LINK_NLRITYPE = 2; + private boolean isMpUnReachNlri = false; + private final short afi; + private final byte safi; + private final List<BGPLSNlri> mpUnReachNlri; + private final int length; + + /** + * Constructor to initialize parameters. + * + * @param mpUnReachNlri MpUnReach Nlri attribute + * @param afi address family identifier + * @param safi subsequent address family identifier + * @param length of MpUnReachNlri + */ + public MpUnReachNlri(List<BGPLSNlri> mpUnReachNlri, short afi, byte safi, + int length) { + this.mpUnReachNlri = mpUnReachNlri; + this.isMpUnReachNlri = true; + this.afi = afi; + this.safi = safi; + this.length = length; + } + + /** + * Reads from ChannelBuffer and parses MpUnReachNlri. + * + * @param cb ChannelBuffer + * @return object of MpUnReachNlri + * @throws BGPParseException while parsing MpUnReachNlri + */ + public static MpUnReachNlri read(ChannelBuffer cb) throws BGPParseException { + ChannelBuffer tempBuf = cb.copy(); + Validation parseFlags = Validation.parseAttributeHeader(cb); + int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT + : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE; + ChannelBuffer data = tempBuf.readBytes(len); + + if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() + && parseFlags.getThirdBit()) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data); + } + + if (cb.readableBytes() < parseFlags.getLength()) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, parseFlags.getLength()); + } + + LinkedList<BGPLSNlri> mpUnReachNlri = new LinkedList<>(); + BGPLSNlri bgpLSNlri = null; + short afi = 0; + byte safi = 0; + ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength()); + while (tempCb.readableBytes() > 0) { + afi = tempCb.readShort(); + safi = tempCb.readByte(); + + //Supporting only for AFI 16388 / SAFI 71 + if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE) + || (afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) { + while (tempCb.readableBytes() > 0) { + short nlriType = tempCb.readShort(); + short totNlriLen = tempCb.readShort(); + if (tempCb.readableBytes() < totNlriLen) { + Validation.validateLen( + BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); + } + tempBuf = tempCb.readBytes(totNlriLen); + switch (nlriType) { + case BGPNodeLSNlriVer4.NODE_NLRITYPE: + bgpLSNlri = BGPNodeLSNlriVer4.read(tempBuf, afi, safi); + break; + case LINK_NLRITYPE: + //TODO: to be merged later + break; + case BGPPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE: + bgpLSNlri = BGPPrefixIPv4LSNlriVer4.read(tempBuf, afi, + safi); + break; + default: + log.debug("nlriType not supported" + nlriType); + } + mpUnReachNlri.add(bgpLSNlri); + } + } else { + //TODO: check with the values got from capability + throw new BGPParseException("Not Supporting afi " + afi + + "safi " + safi); + } + } + return new MpUnReachNlri(mpUnReachNlri, afi, safi, + parseFlags.getLength()); + } + + @Override + public short getType() { + return MPUNREACHNLRI_TYPE; + } + + /** + * Returns SAFI. + * + * @return SAFI + */ + public byte safi() { + return this.safi; + } + + /** + * Returns AFI. + * + * @return AFI + */ + public short afi() { + return this.afi; + } + + /** + * Returns list of MpUnReach Nlri. + * + * @return list of MpUnReach Nlri + */ + public List<BGPLSNlri> mpUnReachNlri() { + return this.mpUnReachNlri; + } + + /** + * Returns whether MpReachNlri is present. + * + * @return whether MpReachNlri is present + */ + public boolean isMpUnReachNlriSet() { + return this.isMpUnReachNlri; + } + + /** + * Returns length of MpUnReach. + * + * @return length of MpUnReach + */ + public int mpUnReachNlriLen() { + return this.length; + } + + @Override + public int write(ChannelBuffer cb) { + //Not to be Implemented as of now + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("mpReachNlri", mpUnReachNlri) + .add("afi", afi) + .add("safi", safi) + .add("length", length) + .toString(); + } +}
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java new file mode 100644 index 00000000..086e8b06 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java @@ -0,0 +1,130 @@ +/* + * 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.bgpio.types.attr; + +import java.util.Objects; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.types.BGPErrorType; +import org.onosproject.bgpio.types.BGPValueType; +import org.onosproject.bgpio.util.Validation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * Implements BGP attribute Is Is Administrative area. + */ +public final class BgpLinkAttrIsIsAdminstGrp implements BGPValueType { + + protected static final Logger log = LoggerFactory + .getLogger(BgpLinkAttrIsIsAdminstGrp.class); + + public static final int ATTRLINK_PROTECTIONTYPE = 1088; + public static final int ISIS_ADMIN_DATA_LEN = 4; + + /* ISIS administrative group */ + private final long isisAdminGrp; + + /** + * Constructor to initialize the values. + * + * @param isisAdminGrp ISIS protocol admin group + */ + public BgpLinkAttrIsIsAdminstGrp(long isisAdminGrp) { + this.isisAdminGrp = isisAdminGrp; + } + + /** + * Returns object of this class with specified values. + * + * @param isisAdminGrp ISIS admin group + * @return object of BgpLinkAttrIsIsAdminstGrp + */ + public static BgpLinkAttrIsIsAdminstGrp of(final long isisAdminGrp) { + return new BgpLinkAttrIsIsAdminstGrp(isisAdminGrp); + } + + /** + * Reads the BGP link attributes of ISIS administrative group area. + * + * @param cb Channel buffer + * @return object of type BgpLinkAttrIsIsAdminstGrp + * @throws BGPParseException while parsing BgpLinkAttrIsIsAdminstGrp + */ + public static BgpLinkAttrIsIsAdminstGrp read(ChannelBuffer cb) + throws BGPParseException { + long isisAdminGrp; + short lsAttrLength = cb.readShort(); + + if ((lsAttrLength != ISIS_ADMIN_DATA_LEN) + || (cb.readableBytes() < lsAttrLength)) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + lsAttrLength); + } + + isisAdminGrp = cb.readUnsignedInt(); + + return BgpLinkAttrIsIsAdminstGrp.of(isisAdminGrp); + } + + /** + * Link attributes of ISIS administrative group area. + * + * @return long value of the administrative group area + */ + public long linkAttrIsIsAdminGrp() { + return isisAdminGrp; + } + + @Override + public short getType() { + return ATTRLINK_PROTECTIONTYPE; + } + + @Override + public int hashCode() { + return Objects.hash(isisAdminGrp); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof BgpLinkAttrIsIsAdminstGrp) { + BgpLinkAttrIsIsAdminstGrp other = (BgpLinkAttrIsIsAdminstGrp) obj; + return Objects.equals(isisAdminGrp, other.isisAdminGrp); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + // TODO This will be implemented in the next version + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("isisAdminGrp", isisAdminGrp).toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java new file mode 100644 index 00000000..a1f0198b --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java @@ -0,0 +1,150 @@ +/* + * 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.bgpio.types.attr; + +import java.util.Objects; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.types.BGPErrorType; +import org.onosproject.bgpio.types.BGPValueType; +import org.onosproject.bgpio.util.Validation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * Implements BGP attribute Max Link bandwidth. + */ +public final class BgpLinkAttrMaxLinkBandwidth implements BGPValueType { + + protected static final Logger log = LoggerFactory + .getLogger(BgpLinkAttrMaxLinkBandwidth.class); + + public static final int MAX_BANDWIDTH_LEN = 4; + public static final int NO_OF_BITS = 8; + + public short type; + + /* ISIS administrative group */ + private final float maxBandwidth; + + /** + * Constructor to initialize the values. + * + * @param maxBandwidth Maximum link bandwidth. + * @param type TLV type + */ + private BgpLinkAttrMaxLinkBandwidth(float maxBandwidth, short type) { + this.maxBandwidth = maxBandwidth; + this.type = type; + } + + /** + * Returns object of this class with specified values. + * + * @param maxBandwidth Maximum link bandwidth. + * @param type TLV type + * @return object of BgpLinkAttrMaxLinkBandwidth + */ + public static BgpLinkAttrMaxLinkBandwidth of(final float maxBandwidth, + final short type) { + return new BgpLinkAttrMaxLinkBandwidth(maxBandwidth, type); + } + + /** + * Reads the BGP link attributes of Maximum link bandwidth. + * + * @param cb Channel buffer + * @param type type of this tlv + * @return object of type BgpLinkAttrMaxLinkBandwidth + * @throws BGPParseException while parsing BgpLinkAttrMaxLinkBandwidth + */ + public static BgpLinkAttrMaxLinkBandwidth read(ChannelBuffer cb, short type) + throws BGPParseException { + float maxBandwidth; + short lsAttrLength = cb.readShort(); + + if ((lsAttrLength != MAX_BANDWIDTH_LEN) + || (cb.readableBytes() < lsAttrLength)) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + lsAttrLength); + } + + maxBandwidth = ieeeToFloatRead(cb.readInt()) * NO_OF_BITS; + + return BgpLinkAttrMaxLinkBandwidth.of(maxBandwidth, type); + } + + /** + * Returns Maximum link bandwidth. + * + * @return Maximum link bandwidth + */ + float linkAttrMaxLinkBandwidth() { + return maxBandwidth; + } + + /** + * Parse the IEEE floating point notation and returns it in normal float. + * + * @param iVal IEEE floating point number + * @return normal float + */ + static float ieeeToFloatRead(int iVal) { + iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8) + | ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF)); + + return Float.intBitsToFloat(iVal); + } + + @Override + public short getType() { + return this.type; + } + + @Override + public int hashCode() { + return Objects.hash(maxBandwidth); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof BgpLinkAttrMaxLinkBandwidth) { + BgpLinkAttrMaxLinkBandwidth other = (BgpLinkAttrMaxLinkBandwidth) obj; + return Objects.equals(maxBandwidth, other.maxBandwidth); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + // TODO This will be implemented in the next version + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("maxBandwidth", maxBandwidth).toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java new file mode 100755 index 00000000..258598be --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java @@ -0,0 +1,133 @@ +/* + * 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.bgpio.types.attr; + +import java.util.Arrays; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.types.BGPErrorType; +import org.onosproject.bgpio.types.BGPValueType; +import org.onosproject.bgpio.util.Validation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * Implements BGP link opaque attribute. + */ +public final class BgpLinkAttrOpaqLnkAttrib implements BGPValueType { + + protected static final Logger log = LoggerFactory + .getLogger(BgpLinkAttrOpaqLnkAttrib.class); + + public static final int ATTRNODE_OPAQUELNKATTRIB = 1097; + + /* Opaque Node Attribute */ + private final byte[] opaqueLinkAttribute; + + /** + * Constructor to initialize the data. + * + * @param opaqueLinkAttribute opaque link attribute + */ + private BgpLinkAttrOpaqLnkAttrib(byte[] opaqueLinkAttribute) { + this.opaqueLinkAttribute = Arrays.copyOf(opaqueLinkAttribute, + opaqueLinkAttribute.length); + } + + /** + * Returns object of this class with specified values. + * + * @param opaqueLinkAttribute opaque link attribute + * @return object of BgpLinkAttrOpaqLnkAttrib + */ + public static BgpLinkAttrOpaqLnkAttrib of(final byte[] opaqueLinkAttribute) { + return new BgpLinkAttrOpaqLnkAttrib(opaqueLinkAttribute); + } + + /** + * Reads the BGP link attributes Opaque link attribute. + * + * @param cb Channel buffer + * @return object of type BgpLinkAttrOpaqLnkAttrib + * @throws BGPParseException while parsing BgpLinkAttrOpaqLnkAttrib + */ + public static BgpLinkAttrOpaqLnkAttrib read(ChannelBuffer cb) + throws BGPParseException { + + byte[] opaqueLinkAttribute; + + short lsAttrLength = cb.readShort(); + + if (cb.readableBytes() < lsAttrLength) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + lsAttrLength); + } + + opaqueLinkAttribute = new byte[lsAttrLength]; + cb.readBytes(opaqueLinkAttribute); + + return BgpLinkAttrOpaqLnkAttrib.of(opaqueLinkAttribute); + } + + /** + * Returns the Opaque link attribute. + * + * @return byte array of opaque link attribute. + */ + public byte[] attrOpaqueLnk() { + return opaqueLinkAttribute; + } + + @Override + public short getType() { + return ATTRNODE_OPAQUELNKATTRIB; + } + + @Override + public int hashCode() { + return Arrays.hashCode(opaqueLinkAttribute); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof BgpLinkAttrOpaqLnkAttrib) { + BgpLinkAttrOpaqLnkAttrib other = (BgpLinkAttrOpaqLnkAttrib) obj; + return Arrays + .equals(opaqueLinkAttribute, other.opaqueLinkAttribute); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + // TODO This will be implemented in the next version + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()).omitNullValues() + .add("opaqueLinkAttribute", opaqueLinkAttribute).toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMaxLinkBandwidthTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMaxLinkBandwidthTest.java new file mode 100644 index 00000000..d4c3b610 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMaxLinkBandwidthTest.java @@ -0,0 +1,44 @@ +/* + * 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.bgp; + +import org.junit.Test; +import org.onosproject.bgpio.types.attr.BgpLinkAttrMaxLinkBandwidth; + +import com.google.common.testing.EqualsTester; + +/** + * Test for BGP link max bandwidth attribute. + */ +public class BgpLinkAttrMaxLinkBandwidthTest { + private final float val = 0x010203; + private final short valLen = 3; + private final float val1 = 0x01020304; + private final short val1Len = 4; + + private final BgpLinkAttrMaxLinkBandwidth data = BgpLinkAttrMaxLinkBandwidth + .of(val, valLen); + private final BgpLinkAttrMaxLinkBandwidth sameAsData = BgpLinkAttrMaxLinkBandwidth + .of(val, valLen); + private final BgpLinkAttrMaxLinkBandwidth diffData = BgpLinkAttrMaxLinkBandwidth + .of(val1, val1Len); + + @Test + public void basics() { + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } +}
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOpaqueDataTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOpaqueDataTest.java new file mode 100644 index 00000000..7ba6a880 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOpaqueDataTest.java @@ -0,0 +1,42 @@ +/* + * 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.bgp; + +import org.junit.Test; +import org.onosproject.bgpio.types.attr.BgpPrefixAttrOpaqueData; + +import com.google.common.testing.EqualsTester; + +/** + * Test for prefix attribute opaque data Tlv. + */ +public class BgpPrefixAttrOpaqueDataTest { + private final byte[] array = new byte[] {0x01, 0x02, 0x03, 0x04}; + private final byte[] array1 = new byte[] {0x01, 0x02, 0x03, 0x01}; + + private final BgpPrefixAttrOpaqueData isisData = BgpPrefixAttrOpaqueData + .of(array); + private final BgpPrefixAttrOpaqueData sameAsIsisData = BgpPrefixAttrOpaqueData + .of(array); + private final BgpPrefixAttrOpaqueData isisDiff = BgpPrefixAttrOpaqueData + .of(array1); + + @Test + public void basics() { + new EqualsTester().addEqualityGroup(isisData, sameAsIsisData) + .addEqualityGroup(isisDiff).testEquals(); + } +}
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java new file mode 100644 index 00000000..02a06e05 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java @@ -0,0 +1,40 @@ +/* + * 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.bgpio; + +import org.junit.Test; +import org.onosproject.bgpio.types.LocalPref; + +import com.google.common.testing.EqualsTester; + +/** + * Test for LocalPref BGP Path Attribute. + */ +public class LocalPrefTest { + private final int value1 = 800; + private final int value2 = 300; + private final LocalPref attr1 = new LocalPref(value1); + private final LocalPref sameAsAttr1 = new LocalPref(value1); + private final LocalPref attr2 = new LocalPref(value2); + + @Test + public void testEquality() { + new EqualsTester() + .addEqualityGroup(attr1, sameAsAttr1) + .addEqualityGroup(attr2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java new file mode 100644 index 00000000..eafcec74 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java @@ -0,0 +1,40 @@ +/* + * 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.bgpio; + +import org.junit.Test; +import org.onosproject.bgpio.types.Med; + +import com.google.common.testing.EqualsTester; + +/** + * Test for MED BGP Path Attribute. + */ +public class MedTest { + private final int value1 = 800; + private final int value2 = 200; + private final Med attr1 = new Med(value1); + private final Med sameAsAttr1 = new Med(value1); + private final Med attr2 = new Med(value2); + + @Test + public void testEquality() { + new EqualsTester() + .addEqualityGroup(attr1, sameAsAttr1) + .addEqualityGroup(attr2) + .testEquals(); + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpHaCriterion.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpHaCriterion.java new file mode 100644 index 00000000..71269dd1 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpHaCriterion.java @@ -0,0 +1,83 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flow.criteria; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +import org.onlab.packet.MacAddress; + +/** + * Implementation of arp_eth_src address or arp_eth_dst address criterion. + */ +public final class ArpHaCriterion implements Criterion { + private final MacAddress mac; + private final Type type; + + /** + * Constructor. + * + * @param mac the MAC Address to match. + * @param type the match type. Should be one of the following: + * Type.ARP_SHA, Type.ARP_THA + */ + ArpHaCriterion(MacAddress mac, Type type) { + checkNotNull(mac, "mac cannot be null"); + checkNotNull(type, "type cannot be null"); + this.mac = mac; + this.type = type; + } + + @Override + public Type type() { + return this.type; + } + + /** + * Gets the MAC Address to match. + * + * @return the MAC Address to match + */ + public MacAddress mac() { + return this.mac; + } + + @Override + public String toString() { + return toStringHelper(type().toString()) + .add("mac", mac).toString(); + } + + @Override + public int hashCode() { + return Objects.hash(type().ordinal(), mac); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ArpHaCriterion) { + ArpHaCriterion that = (ArpHaCriterion) obj; + return Objects.equals(mac, that.mac) && + Objects.equals(type, that.type); + } + return false; + } +}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java index 778d50a5..bc1a094c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java @@ -519,6 +519,16 @@ public final class Criteria { return new ArpPaCriterion(ip, Type.ARP_TPA); } + /** + * Creates a match on MAC source field using the specified value. + * + * @param mac MAC source value + * @return match criterion + */ + public static Criterion matchArpTha(MacAddress mac) { + return new ArpHaCriterion(mac, Type.ARP_THA); + } + public static Criterion dummy() { return new DummyCriterion(); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java index caa5fbb9..4548c44d 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java @@ -42,6 +42,7 @@ public final class MplsPathIntent extends PathIntent { * ports and using the specified explicit path. * * @param appId application identifier + * @param key intent key * @param selector traffic selector * @param treatment treatment * @param path traversed links @@ -51,11 +52,11 @@ public final class MplsPathIntent extends PathIntent { * @param priority priority to use for flows generated by this intent * @throws NullPointerException {@code path} is null */ - private MplsPathIntent(ApplicationId appId, TrafficSelector selector, + private MplsPathIntent(ApplicationId appId, Key key, TrafficSelector selector, TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel, Optional<MplsLabel> egressLabel, List<Constraint> constraints, int priority) { - super(appId, selector, treatment, path, constraints, + super(appId, key, selector, treatment, path, constraints, priority); this.ingressLabel = checkNotNull(ingressLabel); @@ -149,6 +150,7 @@ public final class MplsPathIntent extends PathIntent { return new MplsPathIntent( appId, + key, selector, treatment, path, diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java index 0c831fd5..9bf137a1 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java @@ -42,6 +42,7 @@ public class PathIntent extends ConnectivityIntent { * ports and using the specified explicit path. * * @param appId application identifier + * @param key intent key * @param selector traffic selector * @param treatment treatment * @param path traversed links @@ -50,12 +51,13 @@ public class PathIntent extends ConnectivityIntent { * @throws NullPointerException {@code path} is null */ protected PathIntent(ApplicationId appId, + Key key, TrafficSelector selector, TrafficTreatment treatment, Path path, List<Constraint> constraints, int priority) { - super(appId, null, resources(path.links()), selector, treatment, constraints, + super(appId, key, resources(path.links()), selector, treatment, constraints, priority); PathIntent.validate(path.links()); this.path = path; @@ -138,6 +140,7 @@ public class PathIntent extends ConnectivityIntent { return new PathIntent( appId, + key, selector, treatment, path, @@ -184,6 +187,7 @@ public class PathIntent extends ConnectivityIntent { public String toString() { return MoreObjects.toStringHelper(getClass()) .add("id", id()) + .add("key", key()) .add("appId", appId()) .add("priority", priority()) .add("resources", resources()) diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java index e03ed850..c510b60a 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java @@ -33,6 +33,7 @@ import org.onosproject.net.flow.TrafficTreatment; public abstract class ConnectivityIntentTest extends IntentTest { public static final ApplicationId APPID = new TestApplicationId("foo"); + public static final Key KEY = Key.of(1L, APPID); public static final IntentId IID = new IntentId(123); public static final TrafficSelector MATCH = DefaultTrafficSelector.emptySelector(); diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java index 196d6ad4..7fbdf232 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java @@ -112,6 +112,5 @@ public class MplsIntentTest extends AbstractIntentTest { assertThat(intent1.selector(), equalTo(intent2.selector())); assertThat(intent1.treatment(), equalTo(intent2.treatment())); assertThat(intent1.priority(), is(PRIORITY)); - } } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java index 551f19eb..64528cb9 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java @@ -47,6 +47,7 @@ public class MplsPathIntentTest extends AbstractIntentTest { Optional<MplsLabel> label2; TrafficSelector selector; TrafficTreatment treatment; + static final Key KEY1 = Key.of(5L, APP_ID); @Before public void mplsPathIntentTestSetUp() { @@ -58,6 +59,7 @@ public class MplsPathIntentTest extends AbstractIntentTest { label2 = Optional.of(MplsLabel.mplsLabel(2)); intent1 = MplsPathIntent.builder() .appId(APP_ID) + .key(KEY1) .ingressLabel(label1) .egressLabel(label2) .path(defaultPath) @@ -105,6 +107,7 @@ public class MplsPathIntentTest extends AbstractIntentTest { assertThat(intent1.treatment(), equalTo(intent2.treatment())); assertThat(intent1.priority(), is(PRIORITY)); assertThat(intent1.path(), is(defaultPath)); + assertThat(intent1.key(), equalTo(KEY1)); } } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java index dfbc1846..9e675347 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java @@ -62,12 +62,14 @@ public class PathIntentTest extends ConnectivityIntentTest { assertEquals("incorrect match", MATCH, intent.selector()); assertEquals("incorrect action", NOP, intent.treatment()); assertEquals("incorrect path", PATH1, intent.path()); + assertEquals("incorrect key", KEY, intent.key()); } @Override protected PathIntent createOne() { return PathIntent.builder() .appId(APPID) + .key(KEY) .selector(MATCH) .treatment(NOP) .path(PATH1) diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java index 157cdc74..b6d32bed 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java @@ -63,6 +63,7 @@ public class PropertyPanelTest { private static final String KEY_C = "C"; private static final String SEP = "-"; private static final String KEY_Z = "Z"; + private static final String VALUE_A = "Hay"; private static final String VALUE_B = "Bee"; private static final String VALUE_C = "Sea"; @@ -155,8 +156,8 @@ public class PropertyPanelTest { public void props() { basic(); pp.addProp(KEY_A, VALUE_A) - .addProp(KEY_B, VALUE_B) - .addProp(KEY_C, VALUE_C); + .addProp(KEY_B, VALUE_B) + .addProp(KEY_C, VALUE_C); assertEquals("bad props", 3, pp.properties().size()); validateProps(KEY_A, KEY_B, KEY_C); } @@ -165,7 +166,7 @@ public class PropertyPanelTest { public void separator() { props(); pp.addSeparator() - .addProp(KEY_Z, VALUE_Z); + .addProp(KEY_Z, VALUE_Z); assertEquals("bad props", 5, pp.properties().size()); validateProps(KEY_A, KEY_B, KEY_C, SEP, KEY_Z); @@ -191,8 +192,8 @@ public class PropertyPanelTest { public void intValues() { basic(); pp.addProp(KEY_A, 200) - .addProp(KEY_B, 2000) - .addProp(KEY_C, 1234567); + .addProp(KEY_B, 2000) + .addProp(KEY_C, 1234567); validateProp(KEY_A, "200"); validateProp(KEY_B, "2,000"); @@ -203,9 +204,9 @@ public class PropertyPanelTest { public void longValues() { basic(); pp.addProp(KEY_A, 200L) - .addProp(KEY_B, 2000L) - .addProp(KEY_C, 1234567L) - .addProp(KEY_Z, Long.MAX_VALUE); + .addProp(KEY_B, 2000L) + .addProp(KEY_C, 1234567L) + .addProp(KEY_Z, Long.MAX_VALUE); validateProp(KEY_A, "200"); validateProp(KEY_B, "2,000"); @@ -217,7 +218,7 @@ public class PropertyPanelTest { public void objectValue() { basic(); pp.addProp(KEY_A, new FooClass("a")) - .addProp(KEY_B, new FooClass("bxyyzy"), "[xz]"); + .addProp(KEY_B, new FooClass("bxyyzy"), "[xz]"); validateProp(KEY_A, ">a<"); validateProp(KEY_B, ">byyy<"); diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java b/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java index 7cbce4d1..2f933966 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java @@ -217,7 +217,7 @@ public class IntentCodecTest extends AbstractIntentTest { * @throws IOException if processing the resource fails */ private Intent getIntent(String resourceName, JsonCodec intentCodec) throws IOException { - InputStream jsonStream = FlowRuleCodecTest.class + InputStream jsonStream = IntentCodecTest.class .getResourceAsStream(resourceName); JsonNode json = context.mapper().readTree(jsonStream); assertThat(json, notNullValue()); diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java index fa90eb65..32403421 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java @@ -51,7 +51,7 @@ public final class BasicDeviceOperator implements ConfigOperator { * @return DeviceDescription based on both sources */ public static DeviceDescription combine(BasicDeviceConfig bdc, DeviceDescription descr) { - if (bdc == null) { + if (bdc == null || descr == null) { return descr; } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java index 9215d3a0..03281bef 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java @@ -740,7 +740,7 @@ public class DeviceManager Device dev = getDevice(did); DeviceDescription desc = (dev == null) ? null : BasicDeviceOperator.descriptionOf(dev); desc = BasicDeviceOperator.combine(cfg, desc); - if (getProvider(did) != null) { + if (desc != null && getProvider(did) != null) { de = store.createOrUpdateDevice(getProvider(did).id(), did, desc); } } @@ -754,7 +754,7 @@ public class DeviceManager OpticalPortConfig opc = networkConfigService.getConfig(cpt, OpticalPortConfig.class); PortDescription desc = OpticalPortOperator.descriptionOf(dpt); desc = OpticalPortOperator.combine(opc, desc); - if (getProvider(did) != null) { + if (desc != null && getProvider(did) != null) { de = store.updatePortStatus(getProvider(did).id(), did, desc); } } diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java index 687762e0..85e67dec 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java @@ -986,6 +986,10 @@ public class GossipDeviceStore // accept removal request if given timestamp is newer than // the latest Timestamp from Primary provider DeviceDescriptions primDescs = getPrimaryDescriptions(descs); + if (primDescs == null) { + return null; + } + Timestamp lastTimestamp = primDescs.getLatestTimestamp(); if (timestamp.compareTo(lastTimestamp) <= 0) { // outdated event ignore diff --git a/framework/src/onos/core/store/persistence/pom.xml b/framework/src/onos/core/store/persistence/pom.xml index 555de11a..5692c531 100644 --- a/framework/src/onos/core/store/persistence/pom.xml +++ b/framework/src/onos/core/store/persistence/pom.xml @@ -50,7 +50,7 @@ <groupId>org.onosproject</groupId> <artifactId>onos-api</artifactId> </dependency>--> - <dependency> + <dependency> <groupId>org.onosproject</groupId> <artifactId>onos-api</artifactId> <classifier>tests</classifier> diff --git a/framework/src/onos/core/store/pom.xml b/framework/src/onos/core/store/pom.xml index 219ae5d0..94c077a4 100644 --- a/framework/src/onos/core/store/pom.xml +++ b/framework/src/onos/core/store/pom.xml @@ -34,7 +34,7 @@ <modules> <module>dist</module> <module>persistence</module> - <module>serializers</module> + <module>serializers</module> </modules> <dependencies> diff --git a/framework/src/onos/ovsdb/rfc/pom.xml b/framework/src/onos/ovsdb/rfc/pom.xml index 2868845a..d4d37587 100644 --- a/framework/src/onos/ovsdb/rfc/pom.xml +++ b/framework/src/onos/ovsdb/rfc/pom.xml @@ -15,35 +15,35 @@ ~ limitations under the License. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - <artifactId>onos-ovsdb-rfc</artifactId> - <packaging>bundle</packaging> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-ovsdb</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>onos-ovsdb-rfc</artifactId> + <packaging>bundle</packaging> - <dependencies> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + </dependency> + </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - </plugins> - </build> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + </plugins> + </build> </project> diff --git a/framework/src/onos/providers/pcep/app/features.xml b/framework/src/onos/providers/pcep/app/features.xml index ee205365..1cd92e44 100644 --- a/framework/src/onos/providers/pcep/app/features.xml +++ b/framework/src/onos/providers/pcep/app/features.xml @@ -20,8 +20,8 @@ description="${project.description}"> <feature>onos-api</feature> <bundle>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-pcepio/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-pcep-controller-api/${project.version}</bundle> + <bundle>mvn:${project.groupId}/onos-pcepio/${project.version}</bundle> + <bundle>mvn:${project.groupId}/onos-pcep-controller-api/${project.version}</bundle> <bundle>mvn:${project.groupId}/onos-pcep-controller-impl/${project.version}</bundle> <bundle>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</bundle> <bundle>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</bundle> diff --git a/framework/src/onos/providers/pcep/app/pom.xml b/framework/src/onos/providers/pcep/app/pom.xml index 96a04e88..35c1e9cf 100644 --- a/framework/src/onos/providers/pcep/app/pom.xml +++ b/framework/src/onos/providers/pcep/app/pom.xml @@ -14,49 +14,49 @@ ~ limitations under the License. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-providers</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcep-providers</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <artifactId>onos-pcep</artifactId> - <packaging>pom</packaging> + <artifactId>onos-pcep</artifactId> + <packaging>pom</packaging> <description>PCEP protocol southbound providers</description> - + <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-pcep-api</artifactId> - </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-pcep-api</artifactId> + </dependency> <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcepio</artifactId> - <version>${project.version}</version> - </dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcepio</artifactId> + <version>${project.version}</version> + </dependency> <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-controller-api</artifactId> - <version>${project.version}</version> - </dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcep-controller-api</artifactId> + <version>${project.version}</version> + </dependency> <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-controller-impl</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-provider-topology</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-provider-tunnel</artifactId> - <version>${project.version}</version> - </dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcep-controller-impl</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcep-provider-topology</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcep-provider-tunnel</artifactId> + <version>${project.version}</version> + </dependency> - </dependencies> + </dependencies> </project> diff --git a/framework/src/onos/providers/pcep/pom.xml b/framework/src/onos/providers/pcep/pom.xml index 0f885e67..b6a425bb 100644 --- a/framework/src/onos/providers/pcep/pom.xml +++ b/framework/src/onos/providers/pcep/pom.xml @@ -25,8 +25,8 @@ <packaging>pom</packaging> <description>PCEP protocol providers root</description> <modules> - <module>topology</module> - <module>tunnel</module> - <module>app</module> + <module>topology</module> + <module>tunnel</module> + <module>app</module> </modules> </project>
\ No newline at end of file diff --git a/framework/src/onos/tools/test/bin/onos-netcfg b/framework/src/onos/tools/test/bin/onos-netcfg new file mode 100755 index 00000000..23900ecb --- /dev/null +++ b/framework/src/onos/tools/test/bin/onos-netcfg @@ -0,0 +1,15 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# ONOS network configuration uploader. +# ----------------------------------------------------------------------------- + +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 +. $ONOS_ROOT/tools/build/envDefaults + +node="${1:-$OCI}" +file="${2:-$ONOS_ROOT/tools/test/topos/oe-linear-3.json}" +url="${3}" + +curl -sS --fail -L --user $ONOS_WEB_USER:$ONOS_WEB_PASS \ + -X POST -H 'Content-Type:application/json' \ + http://$node:8181/onos/v1/network/configuration/${url} -d@$file diff --git a/framework/src/onos/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java index 4fb58215..8910e733 100644 --- a/framework/src/onos/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java +++ b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java @@ -585,7 +585,7 @@ public class FlowsResourceTest extends ResourceTest { replay(mockFlowService); WebResource rs = resource(); - InputStream jsonStream = IntentsResourceTest.class + InputStream jsonStream = FlowsResourceTest.class .getResourceAsStream("post-flow.json"); ClientResponse response = rs.path("flows/of:0000000000000001") diff --git a/framework/src/onos/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java index 8c765402..5ac483d8 100644 --- a/framework/src/onos/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java +++ b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java @@ -375,7 +375,7 @@ public class HostResourceTest extends ResourceTest { replay(mockHostService); - InputStream jsonStream = IntentsResourceTest.class + InputStream jsonStream = HostResourceTest.class .getResourceAsStream("post-host.json"); WebResource rs = resource(); |