Moved BGP code and Router code into their own bundle.
The main goal of this is to allow routing code to be used by multiple applications. Changes include: * Created an onos-app-routing bundle and moved BGP code and routing code into it. * Created an onos-app-routing-api bundle as a common API bundle between onos-app-routing and onos-app-sdnip, to prevent circular dependencies. * Moved API classes into onos-app-routing-api bundle. * Made Router and BgpSessionManager into OSGi components. This is not quite clean, because there is still a chain of start() method calls from SdnIp through to BgpSessionManager to preserve startup order. This should be revisted so components can be started using activate() * Created BgpService and RoutingService APIs to glue different components together. * Many unit test changes. A lot of the previous unit tests spanned the Router and IntentSynchronizer classes, but this is not possible any more since these classes are in different bundles. I had to rewrite some of these tests so that each unit test class only tests one real class. A nice side-effect is that the tests are now simpler because each test tests less functionality. * Removed SdnIp test seeing as it doesn't run automatically, was already broken and has been largely superseded by other unit tests and the nightly functional tests. Change-Id: I70ecf5391aa353e99e7cdcf7ed38a530c87571bb
Showing
52 changed files
with
1599 additions
and
2257 deletions
... | @@ -46,6 +46,8 @@ | ... | @@ -46,6 +46,8 @@ |
46 | <module>oecfg</module> | 46 | <module>oecfg</module> |
47 | <module>demo</module> | 47 | <module>demo</module> |
48 | <module>election</module> | 48 | <module>election</module> |
49 | + <module>routing</module> | ||
50 | + <module>routing-api</module> | ||
49 | </modules> | 51 | </modules> |
50 | 52 | ||
51 | <properties> | 53 | <properties> | ... | ... |
apps/routing-api/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2015 Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
18 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
20 | + <parent> | ||
21 | + <artifactId>onos-apps</artifactId> | ||
22 | + <groupId>org.onosproject</groupId> | ||
23 | + <version>1.1.0-SNAPSHOT</version> | ||
24 | + <relativePath>../pom.xml</relativePath> | ||
25 | + </parent> | ||
26 | + <modelVersion>4.0.0</modelVersion> | ||
27 | + | ||
28 | + <artifactId>onos-app-routing-api</artifactId> | ||
29 | + | ||
30 | + <packaging>bundle</packaging> | ||
31 | + <description>API for routing applications</description> | ||
32 | + | ||
33 | + <dependencies> | ||
34 | + <dependency> | ||
35 | + <groupId>org.onosproject</groupId> | ||
36 | + <artifactId>onlab-junit</artifactId> | ||
37 | + <scope>test</scope> | ||
38 | + </dependency> | ||
39 | + </dependencies> | ||
40 | +</project> |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.routingapi; | ||
17 | + | ||
18 | +/** | ||
19 | + * Provides a way of interacting with the BGP protocol component. | ||
20 | + */ | ||
21 | +public interface BgpService { | ||
22 | + | ||
23 | + /** | ||
24 | + * Starts the BGP service. | ||
25 | + * | ||
26 | + * @param routeListener listener to send route updates to | ||
27 | + * @param bgpPort port number to listen on | ||
28 | + */ | ||
29 | + void start(RouteListener routeListener, int bgpPort); | ||
30 | + | ||
31 | + /** | ||
32 | + * Stops the BGP service. | ||
33 | + */ | ||
34 | + void stop(); | ||
35 | +} |
... | @@ -13,12 +13,15 @@ | ... | @@ -13,12 +13,15 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip; | 16 | +package org.onosproject.routingapi; |
17 | 17 | ||
18 | +import com.google.common.base.MoreObjects; | ||
18 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
19 | import org.onlab.packet.IpPrefix; | 20 | import org.onlab.packet.IpPrefix; |
20 | import org.onlab.packet.MacAddress; | 21 | import org.onlab.packet.MacAddress; |
21 | 22 | ||
23 | +import java.util.Objects; | ||
24 | + | ||
22 | /** | 25 | /** |
23 | * An entry in the Forwarding Information Base (FIB). | 26 | * An entry in the Forwarding Information Base (FIB). |
24 | */ | 27 | */ |
... | @@ -67,4 +70,31 @@ public class FibEntry { | ... | @@ -67,4 +70,31 @@ public class FibEntry { |
67 | public MacAddress nextHopMac() { | 70 | public MacAddress nextHopMac() { |
68 | return nextHopMac; | 71 | return nextHopMac; |
69 | } | 72 | } |
73 | + | ||
74 | + @Override | ||
75 | + public boolean equals(Object o) { | ||
76 | + if (!(o instanceof FibEntry)) { | ||
77 | + return false; | ||
78 | + } | ||
79 | + | ||
80 | + FibEntry that = (FibEntry) o; | ||
81 | + | ||
82 | + return Objects.equals(this.prefix, that.prefix) && | ||
83 | + Objects.equals(this.nextHopIp, that.nextHopIp) && | ||
84 | + Objects.equals(this.nextHopMac, that.nextHopMac); | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public int hashCode() { | ||
89 | + return Objects.hash(prefix, nextHopIp, nextHopMac); | ||
90 | + } | ||
91 | + | ||
92 | + @Override | ||
93 | + public String toString() { | ||
94 | + return MoreObjects.toStringHelper(getClass()) | ||
95 | + .add("prefix", prefix) | ||
96 | + .add("nextHopIp", nextHopIp) | ||
97 | + .add("nextHopMac", nextHopMac) | ||
98 | + .toString(); | ||
99 | + } | ||
70 | } | 100 | } | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip; | 16 | +package org.onosproject.routingapi; |
17 | 17 | ||
18 | import java.util.Collection; | 18 | import java.util.Collection; |
19 | 19 | ... | ... |
... | @@ -13,7 +13,11 @@ | ... | @@ -13,7 +13,11 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip; | 16 | +package org.onosproject.routingapi; |
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
20 | +import java.util.Objects; | ||
17 | 21 | ||
18 | /** | 22 | /** |
19 | * Represents a change to the Forwarding Information Base (FIB). | 23 | * Represents a change to the Forwarding Information Base (FIB). |
... | @@ -66,4 +70,29 @@ public class FibUpdate { | ... | @@ -66,4 +70,29 @@ public class FibUpdate { |
66 | public FibEntry entry() { | 70 | public FibEntry entry() { |
67 | return entry; | 71 | return entry; |
68 | } | 72 | } |
73 | + | ||
74 | + @Override | ||
75 | + public boolean equals(Object o) { | ||
76 | + if (!(o instanceof FibUpdate)) { | ||
77 | + return false; | ||
78 | + } | ||
79 | + | ||
80 | + FibUpdate that = (FibUpdate) o; | ||
81 | + | ||
82 | + return Objects.equals(this.type, that.type) && | ||
83 | + Objects.equals(this.entry, that.entry); | ||
84 | + } | ||
85 | + | ||
86 | + @Override | ||
87 | + public int hashCode() { | ||
88 | + return Objects.hash(type, entry); | ||
89 | + } | ||
90 | + | ||
91 | + @Override | ||
92 | + public String toString() { | ||
93 | + return MoreObjects.toStringHelper(getClass()) | ||
94 | + .add("type", type) | ||
95 | + .add("entry", entry) | ||
96 | + .toString(); | ||
97 | + } | ||
69 | } | 98 | } | ... | ... |
... | @@ -13,16 +13,15 @@ | ... | @@ -13,16 +13,15 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip; | 16 | +package org.onosproject.routingapi; |
17 | - | ||
18 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | - | ||
20 | -import java.util.Objects; | ||
21 | 17 | ||
18 | +import com.google.common.base.MoreObjects; | ||
22 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
23 | import org.onlab.packet.IpPrefix; | 20 | import org.onlab.packet.IpPrefix; |
24 | 21 | ||
25 | -import com.google.common.base.MoreObjects; | 22 | +import java.util.Objects; |
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
26 | 25 | ||
27 | /** | 26 | /** |
28 | * Represents a route entry for an IP prefix. | 27 | * Represents a route entry for an IP prefix. |
... | @@ -77,7 +76,7 @@ public class RouteEntry { | ... | @@ -77,7 +76,7 @@ public class RouteEntry { |
77 | * @param ipPrefix the IP prefix to use | 76 | * @param ipPrefix the IP prefix to use |
78 | * @return the binary string representation | 77 | * @return the binary string representation |
79 | */ | 78 | */ |
80 | - static String createBinaryString(IpPrefix ipPrefix) { | 79 | + public static String createBinaryString(IpPrefix ipPrefix) { |
81 | if (ipPrefix.prefixLength() == 0) { | 80 | if (ipPrefix.prefixLength() == 0) { |
82 | return ""; | 81 | return ""; |
83 | } | 82 | } | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip; | 16 | +package org.onosproject.routingapi; |
17 | 17 | ||
18 | import java.util.Collection; | 18 | import java.util.Collection; |
19 | 19 | ... | ... |
... | @@ -13,13 +13,13 @@ | ... | @@ -13,13 +13,13 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip; | 16 | +package org.onosproject.routingapi; |
17 | 17 | ||
18 | -import static com.google.common.base.Preconditions.checkNotNull; | 18 | +import com.google.common.base.MoreObjects; |
19 | 19 | ||
20 | import java.util.Objects; | 20 | import java.util.Objects; |
21 | 21 | ||
22 | -import com.google.common.base.MoreObjects; | 22 | +import static com.google.common.base.Preconditions.checkNotNull; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * Represents a change in routing information. | 25 | * Represents a change in routing information. | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.routingapi; | ||
17 | + | ||
18 | +import java.util.Collection; | ||
19 | + | ||
20 | +/** | ||
21 | + * Provides a way of interacting with the RIB management component. | ||
22 | + */ | ||
23 | +public interface RoutingService { | ||
24 | + | ||
25 | + /** | ||
26 | + * Starts the routing service. | ||
27 | + * | ||
28 | + * @param listener listener to send FIB updates to | ||
29 | + */ | ||
30 | + public void start(FibListener listener); | ||
31 | + | ||
32 | + /** | ||
33 | + * Stops the routing service. | ||
34 | + */ | ||
35 | + public void stop(); | ||
36 | + | ||
37 | + /** | ||
38 | + * Gets all IPv4 routes known to SDN-IP. | ||
39 | + * | ||
40 | + * @return the SDN-IP IPv4 routes | ||
41 | + */ | ||
42 | + public Collection<RouteEntry> getRoutes4(); | ||
43 | + | ||
44 | + /** | ||
45 | + * Gets all IPv6 routes known to SDN-IP. | ||
46 | + * | ||
47 | + * @return the SDN-IP IPv6 routes | ||
48 | + */ | ||
49 | + public Collection<RouteEntry> getRoutes6(); | ||
50 | +} |
... | @@ -13,16 +13,17 @@ | ... | @@ -13,16 +13,17 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip; | 16 | +package org.onosproject.routingapi; |
17 | - | ||
18 | -import static org.hamcrest.Matchers.is; | ||
19 | -import static org.hamcrest.Matchers.not; | ||
20 | -import static org.junit.Assert.assertThat; | ||
21 | 17 | ||
18 | +import org.hamcrest.Matchers; | ||
22 | import org.junit.Test; | 19 | import org.junit.Test; |
23 | import org.onlab.packet.Ip4Address; | 20 | import org.onlab.packet.Ip4Address; |
24 | import org.onlab.packet.Ip4Prefix; | 21 | import org.onlab.packet.Ip4Prefix; |
25 | 22 | ||
23 | +import static org.hamcrest.Matchers.is; | ||
24 | +import static org.hamcrest.Matchers.not; | ||
25 | +import static org.junit.Assert.assertThat; | ||
26 | + | ||
26 | /** | 27 | /** |
27 | * Unit tests for the RouteEntry class. | 28 | * Unit tests for the RouteEntry class. |
28 | */ | 29 | */ |
... | @@ -139,8 +140,8 @@ public class RouteEntryTest { | ... | @@ -139,8 +140,8 @@ public class RouteEntryTest { |
139 | Ip4Address nextHop3 = Ip4Address.valueOf("5.6.7.9"); // Different | 140 | Ip4Address nextHop3 = Ip4Address.valueOf("5.6.7.9"); // Different |
140 | RouteEntry routeEntry3 = new RouteEntry(prefix3, nextHop3); | 141 | RouteEntry routeEntry3 = new RouteEntry(prefix3, nextHop3); |
141 | 142 | ||
142 | - assertThat(routeEntry1, is(not(routeEntry2))); | 143 | + assertThat(routeEntry1, Matchers.is(not(routeEntry2))); |
143 | - assertThat(routeEntry1, is(not(routeEntry3))); | 144 | + assertThat(routeEntry1, Matchers.is(not(routeEntry3))); |
144 | } | 145 | } |
145 | 146 | ||
146 | /** | 147 | /** | ... | ... |
apps/routing/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2015 Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
18 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
20 | + <parent> | ||
21 | + <artifactId>onos-apps</artifactId> | ||
22 | + <groupId>org.onosproject</groupId> | ||
23 | + <version>1.1.0-SNAPSHOT</version> | ||
24 | + <relativePath>../pom.xml</relativePath> | ||
25 | + </parent> | ||
26 | + <modelVersion>4.0.0</modelVersion> | ||
27 | + | ||
28 | + <artifactId>onos-app-routing</artifactId> | ||
29 | + | ||
30 | + <packaging>bundle</packaging> | ||
31 | + <description>Libraries for routing applications</description> | ||
32 | + | ||
33 | + <dependencies> | ||
34 | + <dependency> | ||
35 | + <groupId>org.onosproject</groupId> | ||
36 | + <artifactId>onos-app-routing-api</artifactId> | ||
37 | + <version>${project.version}</version> | ||
38 | + </dependency> | ||
39 | + | ||
40 | + <dependency> | ||
41 | + <groupId>org.onosproject</groupId> | ||
42 | + <artifactId>onos-cli</artifactId> | ||
43 | + <version>${project.version}</version> | ||
44 | + </dependency> | ||
45 | + | ||
46 | + <dependency> | ||
47 | + <groupId>org.onosproject</groupId> | ||
48 | + <artifactId>onlab-thirdparty</artifactId> | ||
49 | + <version>${project.version}</version> | ||
50 | + </dependency> | ||
51 | + | ||
52 | + <dependency> | ||
53 | + <groupId>com.google.guava</groupId> | ||
54 | + <artifactId>guava</artifactId> | ||
55 | + </dependency> | ||
56 | + | ||
57 | + <dependency> | ||
58 | + <groupId>org.apache.karaf.shell</groupId> | ||
59 | + <artifactId>org.apache.karaf.shell.console</artifactId> | ||
60 | + </dependency> | ||
61 | + | ||
62 | + <dependency> | ||
63 | + <groupId>org.osgi</groupId> | ||
64 | + <artifactId>org.osgi.core</artifactId> | ||
65 | + </dependency> | ||
66 | + | ||
67 | + <dependency> | ||
68 | + <groupId>org.onosproject</groupId> | ||
69 | + <artifactId>onlab-junit</artifactId> | ||
70 | + <scope>test</scope> | ||
71 | + </dependency> | ||
72 | + | ||
73 | + <dependency> | ||
74 | + <groupId>org.easymock</groupId> | ||
75 | + <artifactId>easymock</artifactId> | ||
76 | + <scope>test</scope> | ||
77 | + </dependency> | ||
78 | + | ||
79 | + </dependencies> | ||
80 | + | ||
81 | +</project> |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip; | 16 | +package org.onosproject.routing; |
17 | 17 | ||
18 | import com.google.common.collect.HashMultimap; | 18 | import com.google.common.collect.HashMultimap; |
19 | import com.google.common.collect.Multimaps; | 19 | import com.google.common.collect.Multimaps; |
... | @@ -23,6 +23,12 @@ import com.googlecode.concurrenttrees.common.KeyValuePair; | ... | @@ -23,6 +23,12 @@ import com.googlecode.concurrenttrees.common.KeyValuePair; |
23 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; | 23 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; |
24 | import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; | 24 | import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; |
25 | import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; | 25 | import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; |
26 | +import org.apache.felix.scr.annotations.Activate; | ||
27 | +import org.apache.felix.scr.annotations.Component; | ||
28 | +import org.apache.felix.scr.annotations.Deactivate; | ||
29 | +import org.apache.felix.scr.annotations.Reference; | ||
30 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
31 | +import org.apache.felix.scr.annotations.Service; | ||
26 | import org.onlab.packet.Ip4Address; | 32 | import org.onlab.packet.Ip4Address; |
27 | import org.onlab.packet.IpAddress; | 33 | import org.onlab.packet.IpAddress; |
28 | import org.onlab.packet.IpPrefix; | 34 | import org.onlab.packet.IpPrefix; |
... | @@ -31,6 +37,14 @@ import org.onosproject.net.Host; | ... | @@ -31,6 +37,14 @@ import org.onosproject.net.Host; |
31 | import org.onosproject.net.host.HostEvent; | 37 | import org.onosproject.net.host.HostEvent; |
32 | import org.onosproject.net.host.HostListener; | 38 | import org.onosproject.net.host.HostListener; |
33 | import org.onosproject.net.host.HostService; | 39 | import org.onosproject.net.host.HostService; |
40 | +import org.onosproject.routingapi.BgpService; | ||
41 | +import org.onosproject.routingapi.FibEntry; | ||
42 | +import org.onosproject.routingapi.FibListener; | ||
43 | +import org.onosproject.routingapi.FibUpdate; | ||
44 | +import org.onosproject.routingapi.RouteEntry; | ||
45 | +import org.onosproject.routingapi.RouteListener; | ||
46 | +import org.onosproject.routingapi.RouteUpdate; | ||
47 | +import org.onosproject.routingapi.RoutingService; | ||
34 | import org.slf4j.Logger; | 48 | import org.slf4j.Logger; |
35 | import org.slf4j.LoggerFactory; | 49 | import org.slf4j.LoggerFactory; |
36 | 50 | ||
... | @@ -47,12 +61,16 @@ import java.util.concurrent.ExecutorService; | ... | @@ -47,12 +61,16 @@ import java.util.concurrent.ExecutorService; |
47 | import java.util.concurrent.Executors; | 61 | import java.util.concurrent.Executors; |
48 | import java.util.concurrent.LinkedBlockingQueue; | 62 | import java.util.concurrent.LinkedBlockingQueue; |
49 | 63 | ||
64 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
65 | + | ||
50 | /** | 66 | /** |
51 | * This class processes route updates and maintains a Routing Information Base | 67 | * This class processes route updates and maintains a Routing Information Base |
52 | * (RIB). After route updates have been processed and next hops have been | 68 | * (RIB). After route updates have been processed and next hops have been |
53 | * resolved, FIB updates are sent to any listening FIB components. | 69 | * resolved, FIB updates are sent to any listening FIB components. |
54 | */ | 70 | */ |
55 | -public class Router implements RouteListener { | 71 | +@Component(immediate = true) |
72 | +@Service | ||
73 | +public class Router implements RoutingService { | ||
56 | 74 | ||
57 | private static final Logger log = LoggerFactory.getLogger(Router.class); | 75 | private static final Logger log = LoggerFactory.getLogger(Router.class); |
58 | 76 | ||
... | @@ -62,52 +80,52 @@ public class Router implements RouteListener { | ... | @@ -62,52 +80,52 @@ public class Router implements RouteListener { |
62 | private InvertedRadixTree<RouteEntry> ribTable6; | 80 | private InvertedRadixTree<RouteEntry> ribTable6; |
63 | 81 | ||
64 | // Stores all incoming route updates in a queue. | 82 | // Stores all incoming route updates in a queue. |
65 | - private final BlockingQueue<Collection<RouteUpdate>> routeUpdatesQueue; | 83 | + private final BlockingQueue<Collection<RouteUpdate>> routeUpdatesQueue |
84 | + = new LinkedBlockingQueue<>(); | ||
66 | 85 | ||
67 | // Next-hop IP address to route entry mapping for next hops pending MAC resolution | 86 | // Next-hop IP address to route entry mapping for next hops pending MAC resolution |
68 | - private final SetMultimap<IpAddress, RouteEntry> routesWaitingOnArp; | 87 | + private SetMultimap<IpAddress, RouteEntry> routesWaitingOnArp; |
69 | 88 | ||
70 | // The IPv4 address to MAC address mapping | 89 | // The IPv4 address to MAC address mapping |
71 | - private final Map<IpAddress, MacAddress> ip2Mac; | 90 | + private final Map<IpAddress, MacAddress> ip2Mac = new ConcurrentHashMap<>(); |
72 | 91 | ||
73 | - private final FibListener fibComponent; | 92 | + private FibListener fibComponent; |
74 | - private final HostService hostService; | ||
75 | - private final ExecutorService bgpUpdatesExecutor; | ||
76 | - private final HostListener hostListener; | ||
77 | 93 | ||
78 | - /** | 94 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
79 | - * Class constructor. | 95 | + protected HostService hostService; |
80 | - * | ||
81 | - * @param fibComponent the intent synchronizer | ||
82 | - * @param hostService the host service | ||
83 | - */ | ||
84 | - public Router(FibListener fibComponent, HostService hostService) { | ||
85 | - // TODO move to a listener model for adding fib listeners | ||
86 | - this.fibComponent = fibComponent; | ||
87 | - this.hostService = hostService; | ||
88 | 96 | ||
89 | - this.hostListener = new InternalHostListener(); | 97 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
98 | + protected BgpService bgpService; | ||
90 | 99 | ||
100 | + private ExecutorService bgpUpdatesExecutor; | ||
101 | + private final HostListener hostListener = new InternalHostListener(); | ||
102 | + | ||
103 | + @Activate | ||
104 | + public void activate() { | ||
91 | ribTable4 = new ConcurrentInvertedRadixTree<>( | 105 | ribTable4 = new ConcurrentInvertedRadixTree<>( |
92 | new DefaultByteArrayNodeFactory()); | 106 | new DefaultByteArrayNodeFactory()); |
93 | ribTable6 = new ConcurrentInvertedRadixTree<>( | 107 | ribTable6 = new ConcurrentInvertedRadixTree<>( |
94 | new DefaultByteArrayNodeFactory()); | 108 | new DefaultByteArrayNodeFactory()); |
95 | - routeUpdatesQueue = new LinkedBlockingQueue<>(); | ||
96 | routesWaitingOnArp = Multimaps.synchronizedSetMultimap( | 109 | routesWaitingOnArp = Multimaps.synchronizedSetMultimap( |
97 | HashMultimap.<IpAddress, RouteEntry>create()); | 110 | HashMultimap.<IpAddress, RouteEntry>create()); |
98 | - ip2Mac = new ConcurrentHashMap<>(); | ||
99 | 111 | ||
100 | bgpUpdatesExecutor = Executors.newSingleThreadExecutor( | 112 | bgpUpdatesExecutor = Executors.newSingleThreadExecutor( |
101 | new ThreadFactoryBuilder() | 113 | new ThreadFactoryBuilder() |
102 | .setNameFormat("sdnip-bgp-updates-%d").build()); | 114 | .setNameFormat("sdnip-bgp-updates-%d").build()); |
103 | } | 115 | } |
104 | 116 | ||
105 | - /** | 117 | + @Deactivate |
106 | - * Starts the router. | 118 | + public void deactivate() { |
107 | - */ | 119 | + log.debug("Stopped"); |
108 | - public void start() { | 120 | + } |
121 | + | ||
122 | + @Override | ||
123 | + public void start(FibListener listener) { | ||
124 | + this.fibComponent = checkNotNull(listener); | ||
109 | this.hostService.addListener(hostListener); | 125 | this.hostService.addListener(hostListener); |
110 | 126 | ||
127 | + bgpService.start(new InternalRouteListener(), 2000); | ||
128 | + | ||
111 | bgpUpdatesExecutor.execute(new Runnable() { | 129 | bgpUpdatesExecutor.execute(new Runnable() { |
112 | @Override | 130 | @Override |
113 | public void run() { | 131 | public void run() { |
... | @@ -116,10 +134,10 @@ public class Router implements RouteListener { | ... | @@ -116,10 +134,10 @@ public class Router implements RouteListener { |
116 | }); | 134 | }); |
117 | } | 135 | } |
118 | 136 | ||
119 | - /** | 137 | + @Override |
120 | - * Stops the router. | ||
121 | - */ | ||
122 | public void stop() { | 138 | public void stop() { |
139 | + bgpService.stop(); | ||
140 | + | ||
123 | this.hostService.removeListener(hostListener); | 141 | this.hostService.removeListener(hostListener); |
124 | 142 | ||
125 | // Stop the thread(s) | 143 | // Stop the thread(s) |
... | @@ -137,8 +155,12 @@ public class Router implements RouteListener { | ... | @@ -137,8 +155,12 @@ public class Router implements RouteListener { |
137 | } | 155 | } |
138 | } | 156 | } |
139 | 157 | ||
140 | - @Override | 158 | + /** |
141 | - public void update(Collection<RouteUpdate> routeUpdates) { | 159 | + * Entry point for route updates. |
160 | + * | ||
161 | + * @param routeUpdates collection of route updates to process | ||
162 | + */ | ||
163 | + private void update(Collection<RouteUpdate> routeUpdates) { | ||
142 | try { | 164 | try { |
143 | routeUpdatesQueue.put(routeUpdates); | 165 | routeUpdatesQueue.put(routeUpdates); |
144 | } catch (InterruptedException e) { | 166 | } catch (InterruptedException e) { |
... | @@ -294,9 +316,11 @@ public class Router implements RouteListener { | ... | @@ -294,9 +316,11 @@ public class Router implements RouteListener { |
294 | withdrawPrefixes.forEach(p -> fibWithdraws.add(new FibUpdate( | 316 | withdrawPrefixes.forEach(p -> fibWithdraws.add(new FibUpdate( |
295 | FibUpdate.Type.DELETE, new FibEntry(p, null, null)))); | 317 | FibUpdate.Type.DELETE, new FibEntry(p, null, null)))); |
296 | 318 | ||
319 | + if (!fibUpdates.isEmpty() || !fibWithdraws.isEmpty()) { | ||
297 | fibComponent.update(fibUpdates, fibWithdraws); | 320 | fibComponent.update(fibUpdates, fibWithdraws); |
298 | } | 321 | } |
299 | } | 322 | } |
323 | + } | ||
300 | 324 | ||
301 | /** | 325 | /** |
302 | * Processes adding a route entry. | 326 | * Processes adding a route entry. |
... | @@ -486,4 +510,14 @@ public class Router implements RouteListener { | ... | @@ -486,4 +510,14 @@ public class Router implements RouteListener { |
486 | } | 510 | } |
487 | } | 511 | } |
488 | } | 512 | } |
513 | + | ||
514 | + /** | ||
515 | + * Listener for route events. | ||
516 | + */ | ||
517 | + private class InternalRouteListener implements RouteListener { | ||
518 | + @Override | ||
519 | + public void update(Collection<RouteUpdate> routeUpdates) { | ||
520 | + Router.this.update(routeUpdates); | ||
521 | + } | ||
522 | + } | ||
489 | } | 523 | } | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * BGP related constants. | 19 | * BGP related constants. | ... | ... |
... | @@ -13,14 +13,13 @@ | ... | @@ -13,14 +13,13 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | 17 | ||
18 | import org.jboss.netty.buffer.ChannelBuffer; | 18 | import org.jboss.netty.buffer.ChannelBuffer; |
19 | import org.jboss.netty.buffer.ChannelBuffers; | 19 | import org.jboss.netty.buffer.ChannelBuffers; |
20 | import org.jboss.netty.channel.Channel; | 20 | import org.jboss.netty.channel.Channel; |
21 | import org.jboss.netty.channel.ChannelHandlerContext; | 21 | import org.jboss.netty.channel.ChannelHandlerContext; |
22 | import org.jboss.netty.handler.codec.frame.FrameDecoder; | 22 | import org.jboss.netty.handler.codec.frame.FrameDecoder; |
23 | -import org.onosproject.sdnip.bgp.BgpConstants.Notifications.MessageHeaderError; | ||
24 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
25 | import org.slf4j.LoggerFactory; | 24 | import org.slf4j.LoggerFactory; |
26 | 25 | ||
... | @@ -86,9 +85,9 @@ class BgpFrameDecoder extends FrameDecoder { | ... | @@ -86,9 +85,9 @@ class BgpFrameDecoder extends FrameDecoder { |
86 | // ERROR: Connection Not Synchronized | 85 | // ERROR: Connection Not Synchronized |
87 | // | 86 | // |
88 | // Send NOTIFICATION and close the connection | 87 | // Send NOTIFICATION and close the connection |
89 | - int errorCode = MessageHeaderError.ERROR_CODE; | 88 | + int errorCode = BgpConstants.Notifications.MessageHeaderError.ERROR_CODE; |
90 | int errorSubcode = | 89 | int errorSubcode = |
91 | - MessageHeaderError.CONNECTION_NOT_SYNCHRONIZED; | 90 | + BgpConstants.Notifications.MessageHeaderError.CONNECTION_NOT_SYNCHRONIZED; |
92 | ChannelBuffer txMessage = | 91 | ChannelBuffer txMessage = |
93 | BgpNotification.prepareBgpNotification(errorCode, | 92 | BgpNotification.prepareBgpNotification(errorCode, |
94 | errorSubcode, | 93 | errorSubcode, |
... | @@ -162,8 +161,8 @@ class BgpFrameDecoder extends FrameDecoder { | ... | @@ -162,8 +161,8 @@ class BgpFrameDecoder extends FrameDecoder { |
162 | // ERROR: Bad Message Type | 161 | // ERROR: Bad Message Type |
163 | // | 162 | // |
164 | // Send NOTIFICATION and close the connection | 163 | // Send NOTIFICATION and close the connection |
165 | - int errorCode = MessageHeaderError.ERROR_CODE; | 164 | + int errorCode = BgpConstants.Notifications.MessageHeaderError.ERROR_CODE; |
166 | - int errorSubcode = MessageHeaderError.BAD_MESSAGE_TYPE; | 165 | + int errorSubcode = BgpConstants.Notifications.MessageHeaderError.BAD_MESSAGE_TYPE; |
167 | ChannelBuffer data = ChannelBuffers.buffer(1); | 166 | ChannelBuffer data = ChannelBuffers.buffer(1); |
168 | data.writeByte(type); | 167 | data.writeByte(type); |
169 | ChannelBuffer txMessage = | 168 | ChannelBuffer txMessage = | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.routing.bgp; | ||
17 | + | ||
18 | +import java.util.Collection; | ||
19 | + | ||
20 | +/** | ||
21 | + * Provides information about BGP peering and routes. | ||
22 | + */ | ||
23 | +public interface BgpInfoService { | ||
24 | + | ||
25 | + /** | ||
26 | + * Gets the BGP sessions. | ||
27 | + * | ||
28 | + * @return the BGP sessions | ||
29 | + */ | ||
30 | + public Collection<BgpSession> getBgpSessions(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Gets the selected IPv4 BGP routes among all BGP sessions. | ||
34 | + * | ||
35 | + * @return the selected IPv4 BGP routes among all BGP sessions | ||
36 | + */ | ||
37 | + public Collection<BgpRouteEntry> getBgpRoutes4(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Gets the selected IPv6 BGP routes among all BGP sessions. | ||
41 | + * | ||
42 | + * @return the selected IPv6 BGP routes among all BGP sessions | ||
43 | + */ | ||
44 | + public Collection<BgpRouteEntry> getBgpRoutes6(); | ||
45 | +} |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | 17 | ||
18 | import org.jboss.netty.buffer.ChannelBuffer; | 18 | import org.jboss.netty.buffer.ChannelBuffer; |
19 | import org.jboss.netty.buffer.ChannelBuffers; | 19 | import org.jboss.netty.buffer.ChannelBuffers; | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | 17 | ||
18 | import org.jboss.netty.buffer.ChannelBuffer; | 18 | import org.jboss.netty.buffer.ChannelBuffer; |
19 | import org.jboss.netty.buffer.ChannelBuffers; | 19 | import org.jboss.netty.buffer.ChannelBuffers; | ... | ... |
... | @@ -13,12 +13,11 @@ | ... | @@ -13,12 +13,11 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | 17 | ||
18 | import org.jboss.netty.buffer.ChannelBuffer; | 18 | import org.jboss.netty.buffer.ChannelBuffer; |
19 | import org.jboss.netty.buffer.ChannelBuffers; | 19 | import org.jboss.netty.buffer.ChannelBuffers; |
20 | import org.jboss.netty.channel.ChannelHandlerContext; | 20 | import org.jboss.netty.channel.ChannelHandlerContext; |
21 | -import org.onosproject.sdnip.bgp.BgpConstants.Notifications.MessageHeaderError; | ||
22 | import org.slf4j.Logger; | 21 | import org.slf4j.Logger; |
23 | import org.slf4j.LoggerFactory; | 22 | import org.slf4j.LoggerFactory; |
24 | 23 | ||
... | @@ -117,8 +116,8 @@ final class BgpNotification { | ... | @@ -117,8 +116,8 @@ final class BgpNotification { |
117 | * @return the message to transmit (BGP header included) | 116 | * @return the message to transmit (BGP header included) |
118 | */ | 117 | */ |
119 | static ChannelBuffer prepareBgpNotificationBadMessageLength(int length) { | 118 | static ChannelBuffer prepareBgpNotificationBadMessageLength(int length) { |
120 | - int errorCode = MessageHeaderError.ERROR_CODE; | 119 | + int errorCode = BgpConstants.Notifications.MessageHeaderError.ERROR_CODE; |
121 | - int errorSubcode = MessageHeaderError.BAD_MESSAGE_LENGTH; | 120 | + int errorSubcode = BgpConstants.Notifications.MessageHeaderError.BAD_MESSAGE_LENGTH; |
122 | ChannelBuffer data = ChannelBuffers.buffer(2); | 121 | ChannelBuffer data = ChannelBuffers.buffer(2); |
123 | data.writeShort(length); | 122 | data.writeShort(length); |
124 | 123 | ... | ... |
... | @@ -13,18 +13,12 @@ | ... | @@ -13,18 +13,12 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | 17 | ||
18 | import org.jboss.netty.buffer.ChannelBuffer; | 18 | import org.jboss.netty.buffer.ChannelBuffer; |
19 | import org.jboss.netty.buffer.ChannelBuffers; | 19 | import org.jboss.netty.buffer.ChannelBuffers; |
20 | import org.jboss.netty.channel.ChannelHandlerContext; | 20 | import org.jboss.netty.channel.ChannelHandlerContext; |
21 | import org.onlab.packet.Ip4Address; | 21 | import org.onlab.packet.Ip4Address; |
22 | -import org.onosproject.sdnip.bgp.BgpConstants.Notifications; | ||
23 | -import org.onosproject.sdnip.bgp.BgpConstants.Notifications.OpenMessageError; | ||
24 | -import org.onosproject.sdnip.bgp.BgpConstants.Open.Capabilities; | ||
25 | -import org.onosproject.sdnip.bgp.BgpConstants.Open.Capabilities.MultiprotocolExtensions; | ||
26 | -import org.onosproject.sdnip.bgp.BgpConstants.Open.Capabilities.As4Octet; | ||
27 | -import org.onosproject.sdnip.bgp.BgpMessage.BgpParseException; | ||
28 | import org.slf4j.Logger; | 22 | import org.slf4j.Logger; |
29 | import org.slf4j.LoggerFactory; | 23 | import org.slf4j.LoggerFactory; |
30 | 24 | ||
... | @@ -86,8 +80,8 @@ final class BgpOpen { | ... | @@ -86,8 +80,8 @@ final class BgpOpen { |
86 | // ERROR: Unsupported Version Number | 80 | // ERROR: Unsupported Version Number |
87 | // | 81 | // |
88 | // Send NOTIFICATION and close the connection | 82 | // Send NOTIFICATION and close the connection |
89 | - int errorCode = OpenMessageError.ERROR_CODE; | 83 | + int errorCode = BgpConstants.Notifications.OpenMessageError.ERROR_CODE; |
90 | - int errorSubcode = OpenMessageError.UNSUPPORTED_VERSION_NUMBER; | 84 | + int errorSubcode = BgpConstants.Notifications.OpenMessageError.UNSUPPORTED_VERSION_NUMBER; |
91 | ChannelBuffer data = ChannelBuffers.buffer(2); | 85 | ChannelBuffer data = ChannelBuffers.buffer(2); |
92 | data.writeShort(BgpConstants.BGP_VERSION); | 86 | data.writeShort(BgpConstants.BGP_VERSION); |
93 | ChannelBuffer txMessage = | 87 | ChannelBuffer txMessage = |
... | @@ -123,8 +117,8 @@ final class BgpOpen { | ... | @@ -123,8 +117,8 @@ final class BgpOpen { |
123 | // ERROR: Unacceptable Hold Time | 117 | // ERROR: Unacceptable Hold Time |
124 | // | 118 | // |
125 | // Send NOTIFICATION and close the connection | 119 | // Send NOTIFICATION and close the connection |
126 | - int errorCode = OpenMessageError.ERROR_CODE; | 120 | + int errorCode = BgpConstants.Notifications.OpenMessageError.ERROR_CODE; |
127 | - int errorSubcode = OpenMessageError.UNACCEPTABLE_HOLD_TIME; | 121 | + int errorSubcode = BgpConstants.Notifications.OpenMessageError.UNACCEPTABLE_HOLD_TIME; |
128 | ChannelBuffer txMessage = | 122 | ChannelBuffer txMessage = |
129 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, | 123 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, |
130 | null); | 124 | null); |
... | @@ -149,7 +143,7 @@ final class BgpOpen { | ... | @@ -149,7 +143,7 @@ final class BgpOpen { |
149 | // Parse the Optional Parameters | 143 | // Parse the Optional Parameters |
150 | try { | 144 | try { |
151 | parseOptionalParameters(bgpSession, ctx, message); | 145 | parseOptionalParameters(bgpSession, ctx, message); |
152 | - } catch (BgpParseException e) { | 146 | + } catch (BgpMessage.BgpParseException e) { |
153 | // ERROR: Error parsing optional parameters | 147 | // ERROR: Error parsing optional parameters |
154 | log.debug("BGP RX OPEN Error from {}: " + | 148 | log.debug("BGP RX OPEN Error from {}: " + |
155 | "Exception parsing Optional Parameters: {}", | 149 | "Exception parsing Optional Parameters: {}", |
... | @@ -158,8 +152,8 @@ final class BgpOpen { | ... | @@ -158,8 +152,8 @@ final class BgpOpen { |
158 | // ERROR: Invalid Optional Parameters: Unspecific | 152 | // ERROR: Invalid Optional Parameters: Unspecific |
159 | // | 153 | // |
160 | // Send NOTIFICATION and close the connection | 154 | // Send NOTIFICATION and close the connection |
161 | - int errorCode = OpenMessageError.ERROR_CODE; | 155 | + int errorCode = BgpConstants.Notifications.OpenMessageError.ERROR_CODE; |
162 | - int errorSubcode = Notifications.ERROR_SUBCODE_UNSPECIFIC; | 156 | + int errorSubcode = BgpConstants.Notifications.ERROR_SUBCODE_UNSPECIFIC; |
163 | ChannelBuffer txMessage = | 157 | ChannelBuffer txMessage = |
164 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, | 158 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, |
165 | null); | 159 | null); |
... | @@ -202,8 +196,8 @@ final class BgpOpen { | ... | @@ -202,8 +196,8 @@ final class BgpOpen { |
202 | // ERROR: Bad Peer AS | 196 | // ERROR: Bad Peer AS |
203 | // | 197 | // |
204 | // Send NOTIFICATION and close the connection | 198 | // Send NOTIFICATION and close the connection |
205 | - int errorCode = OpenMessageError.ERROR_CODE; | 199 | + int errorCode = BgpConstants.Notifications.OpenMessageError.ERROR_CODE; |
206 | - int errorSubcode = OpenMessageError.BAD_PEER_AS; | 200 | + int errorSubcode = BgpConstants.Notifications.OpenMessageError.BAD_PEER_AS; |
207 | ChannelBuffer txMessage = | 201 | ChannelBuffer txMessage = |
208 | BgpNotification.prepareBgpNotification(errorCode, | 202 | BgpNotification.prepareBgpNotification(errorCode, |
209 | errorSubcode, null); | 203 | errorSubcode, null); |
... | @@ -268,12 +262,12 @@ final class BgpOpen { | ... | @@ -268,12 +262,12 @@ final class BgpOpen { |
268 | * @param bgpSession the BGP Session to use | 262 | * @param bgpSession the BGP Session to use |
269 | * @param ctx the Channel Handler Context | 263 | * @param ctx the Channel Handler Context |
270 | * @param message the message to process | 264 | * @param message the message to process |
271 | - * @throws BgpParseException | 265 | + * @throws BgpMessage.BgpParseException |
272 | */ | 266 | */ |
273 | private static void parseOptionalParameters(BgpSession bgpSession, | 267 | private static void parseOptionalParameters(BgpSession bgpSession, |
274 | ChannelHandlerContext ctx, | 268 | ChannelHandlerContext ctx, |
275 | ChannelBuffer message) | 269 | ChannelBuffer message) |
276 | - throws BgpParseException { | 270 | + throws BgpMessage.BgpParseException { |
277 | 271 | ||
278 | // | 272 | // |
279 | // Get and verify the Optional Parameters Length | 273 | // Get and verify the Optional Parameters Length |
... | @@ -284,7 +278,7 @@ final class BgpOpen { | ... | @@ -284,7 +278,7 @@ final class BgpOpen { |
284 | String errorMsg = "Invalid Optional Parameter Length field " + | 278 | String errorMsg = "Invalid Optional Parameter Length field " + |
285 | optParamLength + ". Remaining Optional Parameters " + | 279 | optParamLength + ". Remaining Optional Parameters " + |
286 | message.readableBytes(); | 280 | message.readableBytes(); |
287 | - throw new BgpParseException(errorMsg); | 281 | + throw new BgpMessage.BgpParseException(errorMsg); |
288 | } | 282 | } |
289 | if (optParamLength == 0) { | 283 | if (optParamLength == 0) { |
290 | return; // No Optional Parameters | 284 | return; // No Optional Parameters |
... | @@ -299,25 +293,25 @@ final class BgpOpen { | ... | @@ -299,25 +293,25 @@ final class BgpOpen { |
299 | if (message.readerIndex() >= optParamEnd) { | 293 | if (message.readerIndex() >= optParamEnd) { |
300 | // ERROR: Malformed Optional Parameters | 294 | // ERROR: Malformed Optional Parameters |
301 | String errorMsg = "Malformed Optional Parameters"; | 295 | String errorMsg = "Malformed Optional Parameters"; |
302 | - throw new BgpParseException(errorMsg); | 296 | + throw new BgpMessage.BgpParseException(errorMsg); |
303 | } | 297 | } |
304 | int paramLen = message.readUnsignedByte(); | 298 | int paramLen = message.readUnsignedByte(); |
305 | if (message.readerIndex() + paramLen > optParamEnd) { | 299 | if (message.readerIndex() + paramLen > optParamEnd) { |
306 | // ERROR: Malformed Optional Parameters | 300 | // ERROR: Malformed Optional Parameters |
307 | String errorMsg = "Malformed Optional Parameters"; | 301 | String errorMsg = "Malformed Optional Parameters"; |
308 | - throw new BgpParseException(errorMsg); | 302 | + throw new BgpMessage.BgpParseException(errorMsg); |
309 | } | 303 | } |
310 | 304 | ||
311 | // | 305 | // |
312 | // Extract the Optional Parameter Value based on the Parameter Type | 306 | // Extract the Optional Parameter Value based on the Parameter Type |
313 | // | 307 | // |
314 | switch (paramType) { | 308 | switch (paramType) { |
315 | - case Capabilities.TYPE: | 309 | + case BgpConstants.Open.Capabilities.TYPE: |
316 | // Optional Parameter Type: Capabilities | 310 | // Optional Parameter Type: Capabilities |
317 | - if (paramLen < Capabilities.MIN_LENGTH) { | 311 | + if (paramLen < BgpConstants.Open.Capabilities.MIN_LENGTH) { |
318 | // ERROR: Malformed Capability | 312 | // ERROR: Malformed Capability |
319 | String errorMsg = "Malformed Capability Type " + paramType; | 313 | String errorMsg = "Malformed Capability Type " + paramType; |
320 | - throw new BgpParseException(errorMsg); | 314 | + throw new BgpMessage.BgpParseException(errorMsg); |
321 | } | 315 | } |
322 | int capabEnd = message.readerIndex() + paramLen; | 316 | int capabEnd = message.readerIndex() + paramLen; |
323 | int capabCode = message.readUnsignedByte(); | 317 | int capabCode = message.readUnsignedByte(); |
... | @@ -325,16 +319,16 @@ final class BgpOpen { | ... | @@ -325,16 +319,16 @@ final class BgpOpen { |
325 | if (message.readerIndex() + capabLen > capabEnd) { | 319 | if (message.readerIndex() + capabLen > capabEnd) { |
326 | // ERROR: Malformed Capability | 320 | // ERROR: Malformed Capability |
327 | String errorMsg = "Malformed Capability Type " + paramType; | 321 | String errorMsg = "Malformed Capability Type " + paramType; |
328 | - throw new BgpParseException(errorMsg); | 322 | + throw new BgpMessage.BgpParseException(errorMsg); |
329 | } | 323 | } |
330 | 324 | ||
331 | switch (capabCode) { | 325 | switch (capabCode) { |
332 | - case MultiprotocolExtensions.CODE: | 326 | + case BgpConstants.Open.Capabilities.MultiprotocolExtensions.CODE: |
333 | // Multiprotocol Extensions Capabilities (RFC 4760) | 327 | // Multiprotocol Extensions Capabilities (RFC 4760) |
334 | - if (capabLen != MultiprotocolExtensions.LENGTH) { | 328 | + if (capabLen != BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH) { |
335 | // ERROR: Multiprotocol Extension Length Error | 329 | // ERROR: Multiprotocol Extension Length Error |
336 | String errorMsg = "Multiprotocol Extension Length Error"; | 330 | String errorMsg = "Multiprotocol Extension Length Error"; |
337 | - throw new BgpParseException(errorMsg); | 331 | + throw new BgpMessage.BgpParseException(errorMsg); |
338 | } | 332 | } |
339 | // Decode the AFI (2 octets) and SAFI (1 octet) | 333 | // Decode the AFI (2 octets) and SAFI (1 octet) |
340 | int afi = message.readUnsignedShort(); | 334 | int afi = message.readUnsignedShort(); |
... | @@ -348,20 +342,20 @@ final class BgpOpen { | ... | @@ -348,20 +342,20 @@ final class BgpOpen { |
348 | // NOTE: For now we just copy the remote AFI/SAFI setting | 342 | // NOTE: For now we just copy the remote AFI/SAFI setting |
349 | // to the local configuration. | 343 | // to the local configuration. |
350 | // | 344 | // |
351 | - if (afi == MultiprotocolExtensions.AFI_IPV4 && | 345 | + if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4 && |
352 | - safi == MultiprotocolExtensions.SAFI_UNICAST) { | 346 | + safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST) { |
353 | bgpSession.remoteInfo().setIpv4Unicast(); | 347 | bgpSession.remoteInfo().setIpv4Unicast(); |
354 | bgpSession.localInfo().setIpv4Unicast(); | 348 | bgpSession.localInfo().setIpv4Unicast(); |
355 | - } else if (afi == MultiprotocolExtensions.AFI_IPV4 && | 349 | + } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4 && |
356 | - safi == MultiprotocolExtensions.SAFI_MULTICAST) { | 350 | + safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST) { |
357 | bgpSession.remoteInfo().setIpv4Multicast(); | 351 | bgpSession.remoteInfo().setIpv4Multicast(); |
358 | bgpSession.localInfo().setIpv4Multicast(); | 352 | bgpSession.localInfo().setIpv4Multicast(); |
359 | - } else if (afi == MultiprotocolExtensions.AFI_IPV6 && | 353 | + } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6 && |
360 | - safi == MultiprotocolExtensions.SAFI_UNICAST) { | 354 | + safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST) { |
361 | bgpSession.remoteInfo().setIpv6Unicast(); | 355 | bgpSession.remoteInfo().setIpv6Unicast(); |
362 | bgpSession.localInfo().setIpv6Unicast(); | 356 | bgpSession.localInfo().setIpv6Unicast(); |
363 | - } else if (afi == MultiprotocolExtensions.AFI_IPV6 && | 357 | + } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6 && |
364 | - safi == MultiprotocolExtensions.SAFI_MULTICAST) { | 358 | + safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST) { |
365 | bgpSession.remoteInfo().setIpv6Multicast(); | 359 | bgpSession.remoteInfo().setIpv6Multicast(); |
366 | bgpSession.localInfo().setIpv6Multicast(); | 360 | bgpSession.localInfo().setIpv6Multicast(); |
367 | } else { | 361 | } else { |
... | @@ -370,12 +364,12 @@ final class BgpOpen { | ... | @@ -370,12 +364,12 @@ final class BgpOpen { |
370 | } | 364 | } |
371 | break; | 365 | break; |
372 | 366 | ||
373 | - case Capabilities.As4Octet.CODE: | 367 | + case BgpConstants.Open.Capabilities.As4Octet.CODE: |
374 | // Support for 4-octet AS Number Capabilities (RFC 6793) | 368 | // Support for 4-octet AS Number Capabilities (RFC 6793) |
375 | - if (capabLen != Capabilities.As4Octet.LENGTH) { | 369 | + if (capabLen != BgpConstants.Open.Capabilities.As4Octet.LENGTH) { |
376 | // ERROR: 4-octet AS Number Capability Length Error | 370 | // ERROR: 4-octet AS Number Capability Length Error |
377 | String errorMsg = "4-octet AS Number Capability Length Error"; | 371 | String errorMsg = "4-octet AS Number Capability Length Error"; |
378 | - throw new BgpParseException(errorMsg); | 372 | + throw new BgpMessage.BgpParseException(errorMsg); |
379 | } | 373 | } |
380 | long as4Number = message.readUnsignedInt(); | 374 | long as4Number = message.readUnsignedInt(); |
381 | 375 | ||
... | @@ -430,56 +424,72 @@ final class BgpOpen { | ... | @@ -430,56 +424,72 @@ final class BgpOpen { |
430 | 424 | ||
431 | // IPv4 unicast | 425 | // IPv4 unicast |
432 | if (localInfo.ipv4Unicast()) { | 426 | if (localInfo.ipv4Unicast()) { |
433 | - message.writeByte(Capabilities.TYPE); // Param type | 427 | + message.writeByte(BgpConstants.Open.Capabilities.TYPE); // Param type |
434 | - message.writeByte(Capabilities.MIN_LENGTH + | 428 | + message.writeByte(BgpConstants.Open.Capabilities.MIN_LENGTH + |
435 | - MultiprotocolExtensions.LENGTH); // Param len | 429 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH); // Param len |
436 | - message.writeByte(MultiprotocolExtensions.CODE); // Capab. code | 430 | + message.writeByte( |
437 | - message.writeByte(MultiprotocolExtensions.LENGTH); // Capab. len | 431 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.CODE); // Capab. code |
438 | - message.writeShort(MultiprotocolExtensions.AFI_IPV4); | 432 | + message.writeByte( |
433 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH); // Capab. len | ||
434 | + message.writeShort( | ||
435 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4); | ||
439 | message.writeByte(0); // Reserved field | 436 | message.writeByte(0); // Reserved field |
440 | - message.writeByte(MultiprotocolExtensions.SAFI_UNICAST); | 437 | + message.writeByte( |
438 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST); | ||
441 | } | 439 | } |
442 | // IPv4 multicast | 440 | // IPv4 multicast |
443 | if (localInfo.ipv4Multicast()) { | 441 | if (localInfo.ipv4Multicast()) { |
444 | - message.writeByte(Capabilities.TYPE); // Param type | 442 | + message.writeByte(BgpConstants.Open.Capabilities.TYPE); // Param type |
445 | - message.writeByte(Capabilities.MIN_LENGTH + | 443 | + message.writeByte(BgpConstants.Open.Capabilities.MIN_LENGTH + |
446 | - MultiprotocolExtensions.LENGTH); // Param len | 444 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH); // Param len |
447 | - message.writeByte(MultiprotocolExtensions.CODE); // Capab. code | 445 | + message.writeByte( |
448 | - message.writeByte(MultiprotocolExtensions.LENGTH); // Capab. len | 446 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.CODE); // Capab. code |
449 | - message.writeShort(MultiprotocolExtensions.AFI_IPV4); | 447 | + message.writeByte( |
448 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH); // Capab. len | ||
449 | + message.writeShort( | ||
450 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4); | ||
450 | message.writeByte(0); // Reserved field | 451 | message.writeByte(0); // Reserved field |
451 | - message.writeByte(MultiprotocolExtensions.SAFI_MULTICAST); | 452 | + message.writeByte( |
453 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST); | ||
452 | } | 454 | } |
453 | // IPv6 unicast | 455 | // IPv6 unicast |
454 | if (localInfo.ipv6Unicast()) { | 456 | if (localInfo.ipv6Unicast()) { |
455 | - message.writeByte(Capabilities.TYPE); // Param type | 457 | + message.writeByte(BgpConstants.Open.Capabilities.TYPE); // Param type |
456 | - message.writeByte(Capabilities.MIN_LENGTH + | 458 | + message.writeByte(BgpConstants.Open.Capabilities.MIN_LENGTH + |
457 | - MultiprotocolExtensions.LENGTH); // Param len | 459 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH); // Param len |
458 | - message.writeByte(MultiprotocolExtensions.CODE); // Capab. code | 460 | + message.writeByte( |
459 | - message.writeByte(MultiprotocolExtensions.LENGTH); // Capab. len | 461 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.CODE); // Capab. code |
460 | - message.writeShort(MultiprotocolExtensions.AFI_IPV6); | 462 | + message.writeByte( |
463 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH); // Capab. len | ||
464 | + message.writeShort( | ||
465 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6); | ||
461 | message.writeByte(0); // Reserved field | 466 | message.writeByte(0); // Reserved field |
462 | - message.writeByte(MultiprotocolExtensions.SAFI_UNICAST); | 467 | + message.writeByte( |
468 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST); | ||
463 | } | 469 | } |
464 | // IPv6 multicast | 470 | // IPv6 multicast |
465 | if (localInfo.ipv6Multicast()) { | 471 | if (localInfo.ipv6Multicast()) { |
466 | - message.writeByte(Capabilities.TYPE); // Param type | 472 | + message.writeByte(BgpConstants.Open.Capabilities.TYPE); // Param type |
467 | - message.writeByte(Capabilities.MIN_LENGTH + | 473 | + message.writeByte(BgpConstants.Open.Capabilities.MIN_LENGTH + |
468 | - MultiprotocolExtensions.LENGTH); // Param len | 474 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH); // Param len |
469 | - message.writeByte(MultiprotocolExtensions.CODE); // Capab. code | 475 | + message.writeByte( |
470 | - message.writeByte(MultiprotocolExtensions.LENGTH); // Capab. len | 476 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.CODE); // Capab. code |
471 | - message.writeShort(MultiprotocolExtensions.AFI_IPV6); | 477 | + message.writeByte( |
478 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH); // Capab. len | ||
479 | + message.writeShort( | ||
480 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6); | ||
472 | message.writeByte(0); // Reserved field | 481 | message.writeByte(0); // Reserved field |
473 | - message.writeByte(MultiprotocolExtensions.SAFI_MULTICAST); | 482 | + message.writeByte( |
483 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST); | ||
474 | } | 484 | } |
475 | 485 | ||
476 | // 4 octet AS path capability | 486 | // 4 octet AS path capability |
477 | if (localInfo.as4OctetCapability()) { | 487 | if (localInfo.as4OctetCapability()) { |
478 | - message.writeByte(Capabilities.TYPE); // Param type | 488 | + message.writeByte(BgpConstants.Open.Capabilities.TYPE); // Param type |
479 | - message.writeByte(Capabilities.MIN_LENGTH + | 489 | + message.writeByte(BgpConstants.Open.Capabilities.MIN_LENGTH + |
480 | - As4Octet.LENGTH); // Param len | 490 | + BgpConstants.Open.Capabilities.As4Octet.LENGTH); // Param len |
481 | - message.writeByte(As4Octet.CODE); // Capab. code | 491 | + message.writeByte(BgpConstants.Open.Capabilities.As4Octet.CODE); // Capab. code |
482 | - message.writeByte(As4Octet.LENGTH); // Capab. len | 492 | + message.writeByte(BgpConstants.Open.Capabilities.As4Octet.LENGTH); // Capab. len |
483 | message.writeInt((int) localInfo.as4Number()); | 493 | message.writeInt((int) localInfo.as4Number()); |
484 | } | 494 | } |
485 | return message; | 495 | return message; | ... | ... |
... | @@ -13,20 +13,18 @@ | ... | @@ -13,20 +13,18 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | 17 | ||
18 | -import static com.google.common.base.Preconditions.checkNotNull; | 18 | +import com.google.common.base.MoreObjects; |
19 | +import org.onlab.packet.Ip4Address; | ||
20 | +import org.onlab.packet.IpAddress; | ||
21 | +import org.onlab.packet.IpPrefix; | ||
22 | +import org.onosproject.routingapi.RouteEntry; | ||
19 | 23 | ||
20 | import java.util.ArrayList; | 24 | import java.util.ArrayList; |
21 | import java.util.Objects; | 25 | import java.util.Objects; |
22 | 26 | ||
23 | -import org.onlab.packet.IpAddress; | 27 | +import static com.google.common.base.Preconditions.checkNotNull; |
24 | -import org.onlab.packet.IpPrefix; | ||
25 | -import org.onlab.packet.Ip4Address; | ||
26 | -import org.onosproject.sdnip.RouteEntry; | ||
27 | -import org.onosproject.sdnip.bgp.BgpConstants.Update; | ||
28 | - | ||
29 | -import com.google.common.base.MoreObjects; | ||
30 | 28 | ||
31 | /** | 29 | /** |
32 | * Represents a route in BGP. | 30 | * Represents a route in BGP. |
... | @@ -37,7 +35,7 @@ public class BgpRouteEntry extends RouteEntry { | ... | @@ -37,7 +35,7 @@ public class BgpRouteEntry extends RouteEntry { |
37 | private final byte origin; // Route ORIGIN: IGP, EGP, INCOMPLETE | 35 | private final byte origin; // Route ORIGIN: IGP, EGP, INCOMPLETE |
38 | private final AsPath asPath; // The AS Path | 36 | private final AsPath asPath; // The AS Path |
39 | private final long localPref; // The local preference for the route | 37 | private final long localPref; // The local preference for the route |
40 | - private long multiExitDisc = Update.MultiExitDisc.LOWEST_MULTI_EXIT_DISC; | 38 | + private long multiExitDisc = BgpConstants.Update.MultiExitDisc.LOWEST_MULTI_EXIT_DISC; |
41 | 39 | ||
42 | /** | 40 | /** |
43 | * Class constructor. | 41 | * Class constructor. |
... | @@ -129,8 +127,8 @@ public class BgpRouteEntry extends RouteEntry { | ... | @@ -129,8 +127,8 @@ public class BgpRouteEntry extends RouteEntry { |
129 | 127 | ||
130 | // Find the first Path Segment by ignoring the AS_CONFED_* segments | 128 | // Find the first Path Segment by ignoring the AS_CONFED_* segments |
131 | for (PathSegment pathSegment : asPath.getPathSegments()) { | 129 | for (PathSegment pathSegment : asPath.getPathSegments()) { |
132 | - if ((pathSegment.getType() == Update.AsPath.AS_SET) || | 130 | + if ((pathSegment.getType() == BgpConstants.Update.AsPath.AS_SET) || |
133 | - (pathSegment.getType() == Update.AsPath.AS_SEQUENCE)) { | 131 | + (pathSegment.getType() == BgpConstants.Update.AsPath.AS_SEQUENCE)) { |
134 | firstPathSegment = pathSegment; | 132 | firstPathSegment = pathSegment; |
135 | break; | 133 | break; |
136 | } | 134 | } |
... | @@ -139,7 +137,7 @@ public class BgpRouteEntry extends RouteEntry { | ... | @@ -139,7 +137,7 @@ public class BgpRouteEntry extends RouteEntry { |
139 | return true; // Local route: no path segments | 137 | return true; // Local route: no path segments |
140 | } | 138 | } |
141 | // If the first path segment is AS_SET, the route is considered local | 139 | // If the first path segment is AS_SET, the route is considered local |
142 | - if (firstPathSegment.getType() == Update.AsPath.AS_SET) { | 140 | + if (firstPathSegment.getType() == BgpConstants.Update.AsPath.AS_SET) { |
143 | return true; | 141 | return true; |
144 | } | 142 | } |
145 | 143 | ||
... | @@ -164,8 +162,8 @@ public class BgpRouteEntry extends RouteEntry { | ... | @@ -164,8 +162,8 @@ public class BgpRouteEntry extends RouteEntry { |
164 | 162 | ||
165 | // Find the first Path Segment by ignoring the AS_CONFED_* segments | 163 | // Find the first Path Segment by ignoring the AS_CONFED_* segments |
166 | for (PathSegment pathSegment : asPath.getPathSegments()) { | 164 | for (PathSegment pathSegment : asPath.getPathSegments()) { |
167 | - if ((pathSegment.getType() == Update.AsPath.AS_SET) || | 165 | + if ((pathSegment.getType() == BgpConstants.Update.AsPath.AS_SET) || |
168 | - (pathSegment.getType() == Update.AsPath.AS_SEQUENCE)) { | 166 | + (pathSegment.getType() == BgpConstants.Update.AsPath.AS_SEQUENCE)) { |
169 | firstPathSegment = pathSegment; | 167 | firstPathSegment = pathSegment; |
170 | break; | 168 | break; |
171 | } | 169 | } |
... | @@ -340,7 +338,7 @@ public class BgpRouteEntry extends RouteEntry { | ... | @@ -340,7 +338,7 @@ public class BgpRouteEntry extends RouteEntry { |
340 | @Override | 338 | @Override |
341 | public String toString() { | 339 | public String toString() { |
342 | return MoreObjects.toStringHelper(getClass()) | 340 | return MoreObjects.toStringHelper(getClass()) |
343 | - .add("type", Update.AsPath.typeToString(type)) | 341 | + .add("type", BgpConstants.Update.AsPath.typeToString(type)) |
344 | .add("segmentAsNumbers", this.segmentAsNumbers) | 342 | .add("segmentAsNumbers", this.segmentAsNumbers) |
345 | .toString(); | 343 | .toString(); |
346 | } | 344 | } |
... | @@ -370,16 +368,16 @@ public class BgpRouteEntry extends RouteEntry { | ... | @@ -370,16 +368,16 @@ public class BgpRouteEntry extends RouteEntry { |
370 | int pl = 0; | 368 | int pl = 0; |
371 | for (PathSegment pathSegment : pathSegments) { | 369 | for (PathSegment pathSegment : pathSegments) { |
372 | switch (pathSegment.getType()) { | 370 | switch (pathSegment.getType()) { |
373 | - case Update.AsPath.AS_SET: | 371 | + case BgpConstants.Update.AsPath.AS_SET: |
374 | pl++; // AS_SET counts as 1 | 372 | pl++; // AS_SET counts as 1 |
375 | break; | 373 | break; |
376 | - case Update.AsPath.AS_SEQUENCE: | 374 | + case BgpConstants.Update.AsPath.AS_SEQUENCE: |
377 | // Count each AS number | 375 | // Count each AS number |
378 | pl += pathSegment.getSegmentAsNumbers().size(); | 376 | pl += pathSegment.getSegmentAsNumbers().size(); |
379 | break; | 377 | break; |
380 | - case Update.AsPath.AS_CONFED_SEQUENCE: | 378 | + case BgpConstants.Update.AsPath.AS_CONFED_SEQUENCE: |
381 | break; // Ignore | 379 | break; // Ignore |
382 | - case Update.AsPath.AS_CONFED_SET: | 380 | + case BgpConstants.Update.AsPath.AS_CONFED_SET: |
383 | break; // Ignore | 381 | break; // Ignore |
384 | default: | 382 | default: |
385 | // NOTE: What to do if the Path Segment type is unknown? | 383 | // NOTE: What to do if the Path Segment type is unknown? |
... | @@ -487,7 +485,7 @@ public class BgpRouteEntry extends RouteEntry { | ... | @@ -487,7 +485,7 @@ public class BgpRouteEntry extends RouteEntry { |
487 | .add("prefix", prefix()) | 485 | .add("prefix", prefix()) |
488 | .add("nextHop", nextHop()) | 486 | .add("nextHop", nextHop()) |
489 | .add("bgpId", bgpSession.remoteInfo().bgpId()) | 487 | .add("bgpId", bgpSession.remoteInfo().bgpId()) |
490 | - .add("origin", Update.Origin.typeToString(origin)) | 488 | + .add("origin", BgpConstants.Update.Origin.typeToString(origin)) |
491 | .add("asPath", asPath) | 489 | .add("asPath", asPath) |
492 | .add("localPref", localPref) | 490 | .add("localPref", localPref) |
493 | .add("multiExitDisc", multiExitDisc) | 491 | .add("multiExitDisc", multiExitDisc) | ... | ... |
... | @@ -13,16 +13,16 @@ | ... | @@ -13,16 +13,16 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | - | ||
18 | -import java.util.Collection; | ||
19 | -import java.util.LinkedList; | ||
20 | 17 | ||
21 | import org.onlab.packet.IpPrefix; | 18 | import org.onlab.packet.IpPrefix; |
22 | -import org.onosproject.sdnip.RouteUpdate; | 19 | +import org.onosproject.routingapi.RouteUpdate; |
23 | import org.slf4j.Logger; | 20 | import org.slf4j.Logger; |
24 | import org.slf4j.LoggerFactory; | 21 | import org.slf4j.LoggerFactory; |
25 | 22 | ||
23 | +import java.util.Collection; | ||
24 | +import java.util.LinkedList; | ||
25 | + | ||
26 | /** | 26 | /** |
27 | * Class to receive and process the BGP routes from each BGP Session/Peer. | 27 | * Class to receive and process the BGP routes from each BGP Session/Peer. |
28 | */ | 28 | */ | ... | ... |
... | @@ -13,15 +13,7 @@ | ... | @@ -13,15 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | - | ||
18 | -import java.net.InetAddress; | ||
19 | -import java.net.InetSocketAddress; | ||
20 | -import java.util.Collection; | ||
21 | -import java.util.Collections; | ||
22 | -import java.util.concurrent.ConcurrentHashMap; | ||
23 | -import java.util.concurrent.ConcurrentMap; | ||
24 | -import java.util.concurrent.TimeUnit; | ||
25 | 17 | ||
26 | import org.jboss.netty.buffer.ChannelBuffer; | 18 | import org.jboss.netty.buffer.ChannelBuffer; |
27 | import org.jboss.netty.channel.ChannelHandlerContext; | 19 | import org.jboss.netty.channel.ChannelHandlerContext; |
... | @@ -32,15 +24,21 @@ import org.jboss.netty.util.HashedWheelTimer; | ... | @@ -32,15 +24,21 @@ import org.jboss.netty.util.HashedWheelTimer; |
32 | import org.jboss.netty.util.Timeout; | 24 | import org.jboss.netty.util.Timeout; |
33 | import org.jboss.netty.util.Timer; | 25 | import org.jboss.netty.util.Timer; |
34 | import org.jboss.netty.util.TimerTask; | 26 | import org.jboss.netty.util.TimerTask; |
35 | -import org.onlab.packet.IpPrefix; | ||
36 | import org.onlab.packet.Ip4Address; | 27 | import org.onlab.packet.Ip4Address; |
37 | import org.onlab.packet.Ip4Prefix; | 28 | import org.onlab.packet.Ip4Prefix; |
38 | import org.onlab.packet.Ip6Prefix; | 29 | import org.onlab.packet.Ip6Prefix; |
39 | -import org.onosproject.sdnip.bgp.BgpConstants.Notifications; | 30 | +import org.onlab.packet.IpPrefix; |
40 | -import org.onosproject.sdnip.bgp.BgpConstants.Notifications.HoldTimerExpired; | ||
41 | import org.slf4j.Logger; | 31 | import org.slf4j.Logger; |
42 | import org.slf4j.LoggerFactory; | 32 | import org.slf4j.LoggerFactory; |
43 | 33 | ||
34 | +import java.net.InetAddress; | ||
35 | +import java.net.InetSocketAddress; | ||
36 | +import java.util.Collection; | ||
37 | +import java.util.Collections; | ||
38 | +import java.util.concurrent.ConcurrentHashMap; | ||
39 | +import java.util.concurrent.ConcurrentMap; | ||
40 | +import java.util.concurrent.TimeUnit; | ||
41 | + | ||
44 | /** | 42 | /** |
45 | * Class for handling the BGP peer sessions. | 43 | * Class for handling the BGP peer sessions. |
46 | * There is one instance per each BGP peer session. | 44 | * There is one instance per each BGP peer session. |
... | @@ -463,8 +461,8 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -463,8 +461,8 @@ public class BgpSession extends SimpleChannelHandler { |
463 | // ERROR: Invalid Optional Parameter Length field: Unspecific | 461 | // ERROR: Invalid Optional Parameter Length field: Unspecific |
464 | // | 462 | // |
465 | // Send NOTIFICATION and close the connection | 463 | // Send NOTIFICATION and close the connection |
466 | - int errorCode = HoldTimerExpired.ERROR_CODE; | 464 | + int errorCode = BgpConstants.Notifications.HoldTimerExpired.ERROR_CODE; |
467 | - int errorSubcode = Notifications.ERROR_SUBCODE_UNSPECIFIC; | 465 | + int errorSubcode = BgpConstants.Notifications.ERROR_SUBCODE_UNSPECIFIC; |
468 | ChannelBuffer txMessage = | 466 | ChannelBuffer txMessage = |
469 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, | 467 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, |
470 | null); | 468 | null); | ... | ... |
... | @@ -13,11 +13,12 @@ | ... | @@ -13,11 +13,12 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | 17 | ||
18 | -import java.net.SocketAddress; | ||
19 | import org.onlab.packet.Ip4Address; | 18 | import org.onlab.packet.Ip4Address; |
20 | 19 | ||
20 | +import java.net.SocketAddress; | ||
21 | + | ||
21 | /** | 22 | /** |
22 | * Class for keeping information about a BGP session. | 23 | * Class for keeping information about a BGP session. |
23 | * | 24 | * | ... | ... |
... | @@ -13,8 +13,10 @@ | ... | @@ -13,8 +13,10 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | 17 | ||
18 | +import org.apache.felix.scr.annotations.Component; | ||
19 | +import org.apache.felix.scr.annotations.Service; | ||
18 | import org.jboss.netty.bootstrap.ServerBootstrap; | 20 | import org.jboss.netty.bootstrap.ServerBootstrap; |
19 | import org.jboss.netty.channel.Channel; | 21 | import org.jboss.netty.channel.Channel; |
20 | import org.jboss.netty.channel.ChannelException; | 22 | import org.jboss.netty.channel.ChannelException; |
... | @@ -29,7 +31,8 @@ import org.onlab.packet.Ip4Address; | ... | @@ -29,7 +31,8 @@ import org.onlab.packet.Ip4Address; |
29 | import org.onlab.packet.Ip4Prefix; | 31 | import org.onlab.packet.Ip4Prefix; |
30 | import org.onlab.packet.Ip6Prefix; | 32 | import org.onlab.packet.Ip6Prefix; |
31 | import org.onlab.packet.IpPrefix; | 33 | import org.onlab.packet.IpPrefix; |
32 | -import org.onosproject.sdnip.RouteListener; | 34 | +import org.onosproject.routingapi.BgpService; |
35 | +import org.onosproject.routingapi.RouteListener; | ||
33 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
34 | import org.slf4j.LoggerFactory; | 37 | import org.slf4j.LoggerFactory; |
35 | 38 | ||
... | @@ -47,7 +50,9 @@ import static org.onlab.util.Tools.namedThreads; | ... | @@ -47,7 +50,9 @@ import static org.onlab.util.Tools.namedThreads; |
47 | /** | 50 | /** |
48 | * BGP Session Manager class. | 51 | * BGP Session Manager class. |
49 | */ | 52 | */ |
50 | -public class BgpSessionManager { | 53 | +@Component(immediate = true) |
54 | +@Service | ||
55 | +public class BgpSessionManager implements BgpInfoService, BgpService { | ||
51 | private static final Logger log = | 56 | private static final Logger log = |
52 | LoggerFactory.getLogger(BgpSessionManager.class); | 57 | LoggerFactory.getLogger(BgpSessionManager.class); |
53 | 58 | ||
... | @@ -65,16 +70,7 @@ public class BgpSessionManager { | ... | @@ -65,16 +70,7 @@ public class BgpSessionManager { |
65 | private ConcurrentMap<Ip6Prefix, BgpRouteEntry> bgpRoutes6 = | 70 | private ConcurrentMap<Ip6Prefix, BgpRouteEntry> bgpRoutes6 = |
66 | new ConcurrentHashMap<>(); | 71 | new ConcurrentHashMap<>(); |
67 | 72 | ||
68 | - private final RouteListener routeListener; | 73 | + private RouteListener routeListener; |
69 | - | ||
70 | - /** | ||
71 | - * Constructor for given route listener. | ||
72 | - * | ||
73 | - * @param routeListener the route listener to use | ||
74 | - */ | ||
75 | - public BgpSessionManager(RouteListener routeListener) { | ||
76 | - this.routeListener = checkNotNull(routeListener); | ||
77 | - } | ||
78 | 74 | ||
79 | /** | 75 | /** |
80 | * Checks whether the BGP Session Manager is shutdown. | 76 | * Checks whether the BGP Session Manager is shutdown. |
... | @@ -248,16 +244,13 @@ public class BgpSessionManager { | ... | @@ -248,16 +244,13 @@ public class BgpSessionManager { |
248 | return bgpRouteSelector; | 244 | return bgpRouteSelector; |
249 | } | 245 | } |
250 | 246 | ||
251 | - /** | 247 | + @Override |
252 | - * Starts up BGP Session Manager operation. | 248 | + public void start(RouteListener routeListener, int listenPortNumber) { |
253 | - * | ||
254 | - * @param listenPortNumber the port number to listen on. By default | ||
255 | - * it should be BgpConstants.BGP_PORT (179) | ||
256 | - */ | ||
257 | - public void start(int listenPortNumber) { | ||
258 | log.debug("BGP Session Manager start."); | 249 | log.debug("BGP Session Manager start."); |
259 | isShutdown = false; | 250 | isShutdown = false; |
260 | 251 | ||
252 | + this.routeListener = checkNotNull(routeListener); | ||
253 | + | ||
261 | ChannelFactory channelFactory = new NioServerSocketChannelFactory( | 254 | ChannelFactory channelFactory = new NioServerSocketChannelFactory( |
262 | newCachedThreadPool(namedThreads("onos-bgp-sm-boss-%d")), | 255 | newCachedThreadPool(namedThreads("onos-bgp-sm-boss-%d")), |
263 | newCachedThreadPool(namedThreads("onos-bgp-sm-worker-%d"))); | 256 | newCachedThreadPool(namedThreads("onos-bgp-sm-worker-%d"))); |
... | @@ -294,9 +287,7 @@ public class BgpSessionManager { | ... | @@ -294,9 +287,7 @@ public class BgpSessionManager { |
294 | } | 287 | } |
295 | } | 288 | } |
296 | 289 | ||
297 | - /** | 290 | + @Override |
298 | - * Stops the BGP Session Manager operation. | ||
299 | - */ | ||
300 | public void stop() { | 291 | public void stop() { |
301 | isShutdown = true; | 292 | isShutdown = true; |
302 | allChannels.close().awaitUninterruptibly(); | 293 | allChannels.close().awaitUninterruptibly(); | ... | ... |
... | @@ -13,12 +13,7 @@ | ... | @@ -13,12 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | - | ||
18 | -import java.util.ArrayList; | ||
19 | -import java.util.Collection; | ||
20 | -import java.util.HashMap; | ||
21 | -import java.util.Map; | ||
22 | 17 | ||
23 | import org.apache.commons.lang3.tuple.Pair; | 18 | import org.apache.commons.lang3.tuple.Pair; |
24 | import org.jboss.netty.buffer.ChannelBuffer; | 19 | import org.jboss.netty.buffer.ChannelBuffer; |
... | @@ -28,14 +23,14 @@ import org.onlab.packet.Ip4Address; | ... | @@ -28,14 +23,14 @@ import org.onlab.packet.Ip4Address; |
28 | import org.onlab.packet.Ip4Prefix; | 23 | import org.onlab.packet.Ip4Prefix; |
29 | import org.onlab.packet.Ip6Address; | 24 | import org.onlab.packet.Ip6Address; |
30 | import org.onlab.packet.Ip6Prefix; | 25 | import org.onlab.packet.Ip6Prefix; |
31 | -import org.onosproject.sdnip.bgp.BgpConstants.Notifications.UpdateMessageError; | ||
32 | -import org.onosproject.sdnip.bgp.BgpConstants.Open.Capabilities.MultiprotocolExtensions; | ||
33 | -import org.onosproject.sdnip.bgp.BgpConstants.Update; | ||
34 | -import org.onosproject.sdnip.bgp.BgpConstants.Update.AsPath; | ||
35 | -import org.onosproject.sdnip.bgp.BgpMessage.BgpParseException; | ||
36 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
37 | import org.slf4j.LoggerFactory; | 27 | import org.slf4j.LoggerFactory; |
38 | 28 | ||
29 | +import java.util.ArrayList; | ||
30 | +import java.util.Collection; | ||
31 | +import java.util.HashMap; | ||
32 | +import java.util.Map; | ||
33 | + | ||
39 | /** | 34 | /** |
40 | * A class for handling BGP UPDATE messages. | 35 | * A class for handling BGP UPDATE messages. |
41 | */ | 36 | */ |
... | @@ -102,7 +97,7 @@ final class BgpUpdate { | ... | @@ -102,7 +97,7 @@ final class BgpUpdate { |
102 | try { | 97 | try { |
103 | withdrawnPrefixes = parsePackedIp4Prefixes(withdrawnRoutesLength, | 98 | withdrawnPrefixes = parsePackedIp4Prefixes(withdrawnRoutesLength, |
104 | message); | 99 | message); |
105 | - } catch (BgpParseException e) { | 100 | + } catch (BgpMessage.BgpParseException e) { |
106 | // ERROR: Invalid Network Field | 101 | // ERROR: Invalid Network Field |
107 | log.debug("Exception parsing Withdrawn Prefixes from BGP peer {}: ", | 102 | log.debug("Exception parsing Withdrawn Prefixes from BGP peer {}: ", |
108 | bgpSession.remoteInfo().bgpId(), e); | 103 | bgpSession.remoteInfo().bgpId(), e); |
... | @@ -124,7 +119,7 @@ final class BgpUpdate { | ... | @@ -124,7 +119,7 @@ final class BgpUpdate { |
124 | // | 119 | // |
125 | try { | 120 | try { |
126 | parsePathAttributes(bgpSession, ctx, message, decodedBgpRoutes); | 121 | parsePathAttributes(bgpSession, ctx, message, decodedBgpRoutes); |
127 | - } catch (BgpParseException e) { | 122 | + } catch (BgpMessage.BgpParseException e) { |
128 | log.debug("Exception parsing Path Attributes from BGP peer {}: ", | 123 | log.debug("Exception parsing Path Attributes from BGP peer {}: ", |
129 | bgpSession.remoteInfo().bgpId(), e); | 124 | bgpSession.remoteInfo().bgpId(), e); |
130 | // NOTE: The session was already closed, so nothing else to do | 125 | // NOTE: The session was already closed, so nothing else to do |
... | @@ -179,7 +174,7 @@ final class BgpUpdate { | ... | @@ -179,7 +174,7 @@ final class BgpUpdate { |
179 | * @param decodedBgpRoutes the container to store the decoded BGP Route | 174 | * @param decodedBgpRoutes the container to store the decoded BGP Route |
180 | * Entries. It might already contain some route entries such as withdrawn | 175 | * Entries. It might already contain some route entries such as withdrawn |
181 | * IPv4 prefixes | 176 | * IPv4 prefixes |
182 | - * @throws BgpParseException | 177 | + * @throws BgpMessage.BgpParseException |
183 | */ | 178 | */ |
184 | // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES | 179 | // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES |
185 | private static void parsePathAttributes( | 180 | private static void parsePathAttributes( |
... | @@ -187,7 +182,7 @@ final class BgpUpdate { | ... | @@ -187,7 +182,7 @@ final class BgpUpdate { |
187 | ChannelHandlerContext ctx, | 182 | ChannelHandlerContext ctx, |
188 | ChannelBuffer message, | 183 | ChannelBuffer message, |
189 | DecodedBgpRoutes decodedBgpRoutes) | 184 | DecodedBgpRoutes decodedBgpRoutes) |
190 | - throws BgpParseException { | 185 | + throws BgpMessage.BgpParseException { |
191 | 186 | ||
192 | // | 187 | // |
193 | // Parsed values | 188 | // Parsed values |
... | @@ -195,10 +190,11 @@ final class BgpUpdate { | ... | @@ -195,10 +190,11 @@ final class BgpUpdate { |
195 | Short origin = -1; // Mandatory | 190 | Short origin = -1; // Mandatory |
196 | BgpRouteEntry.AsPath asPath = null; // Mandatory | 191 | BgpRouteEntry.AsPath asPath = null; // Mandatory |
197 | // Legacy NLRI (RFC 4271). Mandatory NEXT_HOP if legacy NLRI is used | 192 | // Legacy NLRI (RFC 4271). Mandatory NEXT_HOP if legacy NLRI is used |
198 | - MpNlri legacyNlri = new MpNlri(MultiprotocolExtensions.AFI_IPV4, | 193 | + MpNlri legacyNlri = new MpNlri( |
199 | - MultiprotocolExtensions.SAFI_UNICAST); | 194 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4, |
195 | + BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST); | ||
200 | long multiExitDisc = // Optional | 196 | long multiExitDisc = // Optional |
201 | - Update.MultiExitDisc.LOWEST_MULTI_EXIT_DISC; | 197 | + BgpConstants.Update.MultiExitDisc.LOWEST_MULTI_EXIT_DISC; |
202 | Long localPref = null; // Mandatory | 198 | Long localPref = null; // Mandatory |
203 | Long aggregatorAsNumber = null; // Optional: unused | 199 | Long aggregatorAsNumber = null; // Optional: unused |
204 | Ip4Address aggregatorIpAddress = null; // Optional: unused | 200 | Ip4Address aggregatorIpAddress = null; // Optional: unused |
... | @@ -213,7 +209,7 @@ final class BgpUpdate { | ... | @@ -213,7 +209,7 @@ final class BgpUpdate { |
213 | // ERROR: Malformed Attribute List | 209 | // ERROR: Malformed Attribute List |
214 | actionsBgpUpdateMalformedAttributeList(bgpSession, ctx); | 210 | actionsBgpUpdateMalformedAttributeList(bgpSession, ctx); |
215 | String errorMsg = "Malformed Attribute List"; | 211 | String errorMsg = "Malformed Attribute List"; |
216 | - throw new BgpParseException(errorMsg); | 212 | + throw new BgpMessage.BgpParseException(errorMsg); |
217 | } | 213 | } |
218 | if (pathAttributeLength == 0) { | 214 | if (pathAttributeLength == 0) { |
219 | return; | 215 | return; |
... | @@ -229,7 +225,7 @@ final class BgpUpdate { | ... | @@ -229,7 +225,7 @@ final class BgpUpdate { |
229 | // ERROR: Malformed Attribute List | 225 | // ERROR: Malformed Attribute List |
230 | actionsBgpUpdateMalformedAttributeList(bgpSession, ctx); | 226 | actionsBgpUpdateMalformedAttributeList(bgpSession, ctx); |
231 | String errorMsg = "Malformed Attribute List"; | 227 | String errorMsg = "Malformed Attribute List"; |
232 | - throw new BgpParseException(errorMsg); | 228 | + throw new BgpMessage.BgpParseException(errorMsg); |
233 | } | 229 | } |
234 | int attrTypeCode = message.readUnsignedByte(); | 230 | int attrTypeCode = message.readUnsignedByte(); |
235 | 231 | ||
... | @@ -249,7 +245,7 @@ final class BgpUpdate { | ... | @@ -249,7 +245,7 @@ final class BgpUpdate { |
249 | // ERROR: Malformed Attribute List | 245 | // ERROR: Malformed Attribute List |
250 | actionsBgpUpdateMalformedAttributeList(bgpSession, ctx); | 246 | actionsBgpUpdateMalformedAttributeList(bgpSession, ctx); |
251 | String errorMsg = "Malformed Attribute List"; | 247 | String errorMsg = "Malformed Attribute List"; |
252 | - throw new BgpParseException(errorMsg); | 248 | + throw new BgpMessage.BgpParseException(errorMsg); |
253 | } | 249 | } |
254 | if (extendedLengthBit) { | 250 | if (extendedLengthBit) { |
255 | attrLen = message.readUnsignedShort(); | 251 | attrLen = message.readUnsignedShort(); |
... | @@ -260,7 +256,7 @@ final class BgpUpdate { | ... | @@ -260,7 +256,7 @@ final class BgpUpdate { |
260 | // ERROR: Malformed Attribute List | 256 | // ERROR: Malformed Attribute List |
261 | actionsBgpUpdateMalformedAttributeList(bgpSession, ctx); | 257 | actionsBgpUpdateMalformedAttributeList(bgpSession, ctx); |
262 | String errorMsg = "Malformed Attribute List"; | 258 | String errorMsg = "Malformed Attribute List"; |
263 | - throw new BgpParseException(errorMsg); | 259 | + throw new BgpMessage.BgpParseException(errorMsg); |
264 | } | 260 | } |
265 | 261 | ||
266 | // Verify the Attribute Flags | 262 | // Verify the Attribute Flags |
... | @@ -272,21 +268,21 @@ final class BgpUpdate { | ... | @@ -272,21 +268,21 @@ final class BgpUpdate { |
272 | // | 268 | // |
273 | switch (attrTypeCode) { | 269 | switch (attrTypeCode) { |
274 | 270 | ||
275 | - case Update.Origin.TYPE: | 271 | + case BgpConstants.Update.Origin.TYPE: |
276 | // Attribute Type Code ORIGIN | 272 | // Attribute Type Code ORIGIN |
277 | origin = parseAttributeTypeOrigin(bgpSession, ctx, | 273 | origin = parseAttributeTypeOrigin(bgpSession, ctx, |
278 | attrTypeCode, attrLen, | 274 | attrTypeCode, attrLen, |
279 | attrFlags, message); | 275 | attrFlags, message); |
280 | break; | 276 | break; |
281 | 277 | ||
282 | - case Update.AsPath.TYPE: | 278 | + case BgpConstants.Update.AsPath.TYPE: |
283 | // Attribute Type Code AS_PATH | 279 | // Attribute Type Code AS_PATH |
284 | asPath = parseAttributeTypeAsPath(bgpSession, ctx, | 280 | asPath = parseAttributeTypeAsPath(bgpSession, ctx, |
285 | attrTypeCode, attrLen, | 281 | attrTypeCode, attrLen, |
286 | attrFlags, message); | 282 | attrFlags, message); |
287 | break; | 283 | break; |
288 | 284 | ||
289 | - case Update.NextHop.TYPE: | 285 | + case BgpConstants.Update.NextHop.TYPE: |
290 | // Attribute Type Code NEXT_HOP | 286 | // Attribute Type Code NEXT_HOP |
291 | legacyNlri.nextHop4 = | 287 | legacyNlri.nextHop4 = |
292 | parseAttributeTypeNextHop(bgpSession, ctx, | 288 | parseAttributeTypeNextHop(bgpSession, ctx, |
... | @@ -294,7 +290,7 @@ final class BgpUpdate { | ... | @@ -294,7 +290,7 @@ final class BgpUpdate { |
294 | attrFlags, message); | 290 | attrFlags, message); |
295 | break; | 291 | break; |
296 | 292 | ||
297 | - case Update.MultiExitDisc.TYPE: | 293 | + case BgpConstants.Update.MultiExitDisc.TYPE: |
298 | // Attribute Type Code MULTI_EXIT_DISC | 294 | // Attribute Type Code MULTI_EXIT_DISC |
299 | multiExitDisc = | 295 | multiExitDisc = |
300 | parseAttributeTypeMultiExitDisc(bgpSession, ctx, | 296 | parseAttributeTypeMultiExitDisc(bgpSession, ctx, |
... | @@ -302,7 +298,7 @@ final class BgpUpdate { | ... | @@ -302,7 +298,7 @@ final class BgpUpdate { |
302 | attrFlags, message); | 298 | attrFlags, message); |
303 | break; | 299 | break; |
304 | 300 | ||
305 | - case Update.LocalPref.TYPE: | 301 | + case BgpConstants.Update.LocalPref.TYPE: |
306 | // Attribute Type Code LOCAL_PREF | 302 | // Attribute Type Code LOCAL_PREF |
307 | localPref = | 303 | localPref = |
308 | parseAttributeTypeLocalPref(bgpSession, ctx, | 304 | parseAttributeTypeLocalPref(bgpSession, ctx, |
... | @@ -310,7 +306,7 @@ final class BgpUpdate { | ... | @@ -310,7 +306,7 @@ final class BgpUpdate { |
310 | attrFlags, message); | 306 | attrFlags, message); |
311 | break; | 307 | break; |
312 | 308 | ||
313 | - case Update.AtomicAggregate.TYPE: | 309 | + case BgpConstants.Update.AtomicAggregate.TYPE: |
314 | // Attribute Type Code ATOMIC_AGGREGATE | 310 | // Attribute Type Code ATOMIC_AGGREGATE |
315 | parseAttributeTypeAtomicAggregate(bgpSession, ctx, | 311 | parseAttributeTypeAtomicAggregate(bgpSession, ctx, |
316 | attrTypeCode, attrLen, | 312 | attrTypeCode, attrLen, |
... | @@ -318,7 +314,7 @@ final class BgpUpdate { | ... | @@ -318,7 +314,7 @@ final class BgpUpdate { |
318 | // Nothing to do: this attribute is primarily informational | 314 | // Nothing to do: this attribute is primarily informational |
319 | break; | 315 | break; |
320 | 316 | ||
321 | - case Update.Aggregator.TYPE: | 317 | + case BgpConstants.Update.Aggregator.TYPE: |
322 | // Attribute Type Code AGGREGATOR | 318 | // Attribute Type Code AGGREGATOR |
323 | Pair<Long, Ip4Address> aggregator = | 319 | Pair<Long, Ip4Address> aggregator = |
324 | parseAttributeTypeAggregator(bgpSession, ctx, | 320 | parseAttributeTypeAggregator(bgpSession, ctx, |
... | @@ -328,7 +324,7 @@ final class BgpUpdate { | ... | @@ -328,7 +324,7 @@ final class BgpUpdate { |
328 | aggregatorIpAddress = aggregator.getRight(); | 324 | aggregatorIpAddress = aggregator.getRight(); |
329 | break; | 325 | break; |
330 | 326 | ||
331 | - case Update.MpReachNlri.TYPE: | 327 | + case BgpConstants.Update.MpReachNlri.TYPE: |
332 | // Attribute Type Code MP_REACH_NLRI | 328 | // Attribute Type Code MP_REACH_NLRI |
333 | MpNlri mpNlriReach = | 329 | MpNlri mpNlriReach = |
334 | parseAttributeTypeMpReachNlri(bgpSession, ctx, | 330 | parseAttributeTypeMpReachNlri(bgpSession, ctx, |
... | @@ -340,7 +336,7 @@ final class BgpUpdate { | ... | @@ -340,7 +336,7 @@ final class BgpUpdate { |
340 | } | 336 | } |
341 | break; | 337 | break; |
342 | 338 | ||
343 | - case Update.MpUnreachNlri.TYPE: | 339 | + case BgpConstants.Update.MpUnreachNlri.TYPE: |
344 | // Attribute Type Code MP_UNREACH_NLRI | 340 | // Attribute Type Code MP_UNREACH_NLRI |
345 | MpNlri mpNlriUnreach = | 341 | MpNlri mpNlriUnreach = |
346 | parseAttributeTypeMpUnreachNlri(bgpSession, ctx, | 342 | parseAttributeTypeMpUnreachNlri(bgpSession, ctx, |
... | @@ -360,7 +356,7 @@ final class BgpUpdate { | ... | @@ -360,7 +356,7 @@ final class BgpUpdate { |
360 | message); | 356 | message); |
361 | String errorMsg = "Unrecognized Well-known Attribute: " + | 357 | String errorMsg = "Unrecognized Well-known Attribute: " + |
362 | attrTypeCode; | 358 | attrTypeCode; |
363 | - throw new BgpParseException(errorMsg); | 359 | + throw new BgpMessage.BgpParseException(errorMsg); |
364 | } | 360 | } |
365 | 361 | ||
366 | // Skip the data from the unrecognized attribute | 362 | // Skip the data from the unrecognized attribute |
... | @@ -381,7 +377,7 @@ final class BgpUpdate { | ... | @@ -381,7 +377,7 @@ final class BgpUpdate { |
381 | parsePackedIp4Prefixes(nlriLength, message); | 377 | parsePackedIp4Prefixes(nlriLength, message); |
382 | // Store it inside the legacy NLRI wrapper | 378 | // Store it inside the legacy NLRI wrapper |
383 | legacyNlri.nlri4 = addedPrefixes4; | 379 | legacyNlri.nlri4 = addedPrefixes4; |
384 | - } catch (BgpParseException e) { | 380 | + } catch (BgpMessage.BgpParseException e) { |
385 | // ERROR: Invalid Network Field | 381 | // ERROR: Invalid Network Field |
386 | log.debug("Exception parsing NLRI from BGP peer {}: ", | 382 | log.debug("Exception parsing NLRI from BGP peer {}: ", |
387 | bgpSession.remoteInfo().bgpId(), e); | 383 | bgpSession.remoteInfo().bgpId(), e); |
... | @@ -486,7 +482,7 @@ final class BgpUpdate { | ... | @@ -486,7 +482,7 @@ final class BgpUpdate { |
486 | * @param legacyNlri the legacy NLRI. Encapsulates the NEXT_HOP well-known | 482 | * @param legacyNlri the legacy NLRI. Encapsulates the NEXT_HOP well-known |
487 | * mandatory attribute (mandatory if legacy NLRI is used). | 483 | * mandatory attribute (mandatory if legacy NLRI is used). |
488 | * @param mpNlriReachList the Multiprotocol NLRI attributes | 484 | * @param mpNlriReachList the Multiprotocol NLRI attributes |
489 | - * @throws BgpParseException | 485 | + * @throws BgpMessage.BgpParseException |
490 | */ | 486 | */ |
491 | private static void verifyBgpUpdateWellKnownAttributes( | 487 | private static void verifyBgpUpdateWellKnownAttributes( |
492 | BgpSession bgpSession, | 488 | BgpSession bgpSession, |
... | @@ -496,7 +492,7 @@ final class BgpUpdate { | ... | @@ -496,7 +492,7 @@ final class BgpUpdate { |
496 | Long localPref, | 492 | Long localPref, |
497 | MpNlri legacyNlri, | 493 | MpNlri legacyNlri, |
498 | Collection<MpNlri> mpNlriReachList) | 494 | Collection<MpNlri> mpNlriReachList) |
499 | - throws BgpParseException { | 495 | + throws BgpMessage.BgpParseException { |
500 | boolean hasNlri = false; | 496 | boolean hasNlri = false; |
501 | boolean hasLegacyNlri = false; | 497 | boolean hasLegacyNlri = false; |
502 | 498 | ||
... | @@ -525,32 +521,32 @@ final class BgpUpdate { | ... | @@ -525,32 +521,32 @@ final class BgpUpdate { |
525 | // | 521 | // |
526 | if (hasNlri && ((origin == null) || (origin == -1))) { | 522 | if (hasNlri && ((origin == null) || (origin == -1))) { |
527 | // Missing Attribute Type Code ORIGIN | 523 | // Missing Attribute Type Code ORIGIN |
528 | - int type = Update.Origin.TYPE; | 524 | + int type = BgpConstants.Update.Origin.TYPE; |
529 | actionsBgpUpdateMissingWellKnownAttribute(bgpSession, ctx, type); | 525 | actionsBgpUpdateMissingWellKnownAttribute(bgpSession, ctx, type); |
530 | String errorMsg = "Missing Well-known Attribute: ORIGIN"; | 526 | String errorMsg = "Missing Well-known Attribute: ORIGIN"; |
531 | - throw new BgpParseException(errorMsg); | 527 | + throw new BgpMessage.BgpParseException(errorMsg); |
532 | } | 528 | } |
533 | if (hasNlri && (asPath == null)) { | 529 | if (hasNlri && (asPath == null)) { |
534 | // Missing Attribute Type Code AS_PATH | 530 | // Missing Attribute Type Code AS_PATH |
535 | - int type = Update.AsPath.TYPE; | 531 | + int type = BgpConstants.Update.AsPath.TYPE; |
536 | actionsBgpUpdateMissingWellKnownAttribute(bgpSession, ctx, type); | 532 | actionsBgpUpdateMissingWellKnownAttribute(bgpSession, ctx, type); |
537 | String errorMsg = "Missing Well-known Attribute: AS_PATH"; | 533 | String errorMsg = "Missing Well-known Attribute: AS_PATH"; |
538 | - throw new BgpParseException(errorMsg); | 534 | + throw new BgpMessage.BgpParseException(errorMsg); |
539 | } | 535 | } |
540 | if (hasNlri && (localPref == null)) { | 536 | if (hasNlri && (localPref == null)) { |
541 | // Missing Attribute Type Code LOCAL_PREF | 537 | // Missing Attribute Type Code LOCAL_PREF |
542 | // NOTE: Required for iBGP | 538 | // NOTE: Required for iBGP |
543 | - int type = Update.LocalPref.TYPE; | 539 | + int type = BgpConstants.Update.LocalPref.TYPE; |
544 | actionsBgpUpdateMissingWellKnownAttribute(bgpSession, ctx, type); | 540 | actionsBgpUpdateMissingWellKnownAttribute(bgpSession, ctx, type); |
545 | String errorMsg = "Missing Well-known Attribute: LOCAL_PREF"; | 541 | String errorMsg = "Missing Well-known Attribute: LOCAL_PREF"; |
546 | - throw new BgpParseException(errorMsg); | 542 | + throw new BgpMessage.BgpParseException(errorMsg); |
547 | } | 543 | } |
548 | if (hasLegacyNlri && (legacyNlri.nextHop4 == null)) { | 544 | if (hasLegacyNlri && (legacyNlri.nextHop4 == null)) { |
549 | // Missing Attribute Type Code NEXT_HOP | 545 | // Missing Attribute Type Code NEXT_HOP |
550 | - int type = Update.NextHop.TYPE; | 546 | + int type = BgpConstants.Update.NextHop.TYPE; |
551 | actionsBgpUpdateMissingWellKnownAttribute(bgpSession, ctx, type); | 547 | actionsBgpUpdateMissingWellKnownAttribute(bgpSession, ctx, type); |
552 | String errorMsg = "Missing Well-known Attribute: NEXT_HOP"; | 548 | String errorMsg = "Missing Well-known Attribute: NEXT_HOP"; |
553 | - throw new BgpParseException(errorMsg); | 549 | + throw new BgpMessage.BgpParseException(errorMsg); |
554 | } | 550 | } |
555 | } | 551 | } |
556 | 552 | ||
... | @@ -563,7 +559,7 @@ final class BgpUpdate { | ... | @@ -563,7 +559,7 @@ final class BgpUpdate { |
563 | * @param attrLen the attribute length (in octets) | 559 | * @param attrLen the attribute length (in octets) |
564 | * @param attrFlags the attribute flags | 560 | * @param attrFlags the attribute flags |
565 | * @param message the message to parse | 561 | * @param message the message to parse |
566 | - * @throws BgpParseException | 562 | + * @throws BgpMessage.BgpParseException |
567 | */ | 563 | */ |
568 | private static void verifyBgpUpdateAttributeFlags( | 564 | private static void verifyBgpUpdateAttributeFlags( |
569 | BgpSession bgpSession, | 565 | BgpSession bgpSession, |
... | @@ -572,7 +568,7 @@ final class BgpUpdate { | ... | @@ -572,7 +568,7 @@ final class BgpUpdate { |
572 | int attrLen, | 568 | int attrLen, |
573 | int attrFlags, | 569 | int attrFlags, |
574 | ChannelBuffer message) | 570 | ChannelBuffer message) |
575 | - throws BgpParseException { | 571 | + throws BgpMessage.BgpParseException { |
576 | 572 | ||
577 | // | 573 | // |
578 | // Assign the Attribute Type Name and the Well-known flag | 574 | // Assign the Attribute Type Name and the Well-known flag |
... | @@ -580,39 +576,39 @@ final class BgpUpdate { | ... | @@ -580,39 +576,39 @@ final class BgpUpdate { |
580 | String typeName = "UNKNOWN"; | 576 | String typeName = "UNKNOWN"; |
581 | boolean isWellKnown = false; | 577 | boolean isWellKnown = false; |
582 | switch (attrTypeCode) { | 578 | switch (attrTypeCode) { |
583 | - case Update.Origin.TYPE: | 579 | + case BgpConstants.Update.Origin.TYPE: |
584 | isWellKnown = true; | 580 | isWellKnown = true; |
585 | typeName = "ORIGIN"; | 581 | typeName = "ORIGIN"; |
586 | break; | 582 | break; |
587 | - case Update.AsPath.TYPE: | 583 | + case BgpConstants.Update.AsPath.TYPE: |
588 | isWellKnown = true; | 584 | isWellKnown = true; |
589 | typeName = "AS_PATH"; | 585 | typeName = "AS_PATH"; |
590 | break; | 586 | break; |
591 | - case Update.NextHop.TYPE: | 587 | + case BgpConstants.Update.NextHop.TYPE: |
592 | isWellKnown = true; | 588 | isWellKnown = true; |
593 | typeName = "NEXT_HOP"; | 589 | typeName = "NEXT_HOP"; |
594 | break; | 590 | break; |
595 | - case Update.MultiExitDisc.TYPE: | 591 | + case BgpConstants.Update.MultiExitDisc.TYPE: |
596 | isWellKnown = false; | 592 | isWellKnown = false; |
597 | typeName = "MULTI_EXIT_DISC"; | 593 | typeName = "MULTI_EXIT_DISC"; |
598 | break; | 594 | break; |
599 | - case Update.LocalPref.TYPE: | 595 | + case BgpConstants.Update.LocalPref.TYPE: |
600 | isWellKnown = true; | 596 | isWellKnown = true; |
601 | typeName = "LOCAL_PREF"; | 597 | typeName = "LOCAL_PREF"; |
602 | break; | 598 | break; |
603 | - case Update.AtomicAggregate.TYPE: | 599 | + case BgpConstants.Update.AtomicAggregate.TYPE: |
604 | isWellKnown = true; | 600 | isWellKnown = true; |
605 | typeName = "ATOMIC_AGGREGATE"; | 601 | typeName = "ATOMIC_AGGREGATE"; |
606 | break; | 602 | break; |
607 | - case Update.Aggregator.TYPE: | 603 | + case BgpConstants.Update.Aggregator.TYPE: |
608 | isWellKnown = false; | 604 | isWellKnown = false; |
609 | typeName = "AGGREGATOR"; | 605 | typeName = "AGGREGATOR"; |
610 | break; | 606 | break; |
611 | - case Update.MpReachNlri.TYPE: | 607 | + case BgpConstants.Update.MpReachNlri.TYPE: |
612 | isWellKnown = false; | 608 | isWellKnown = false; |
613 | typeName = "MP_REACH_NLRI"; | 609 | typeName = "MP_REACH_NLRI"; |
614 | break; | 610 | break; |
615 | - case Update.MpUnreachNlri.TYPE: | 611 | + case BgpConstants.Update.MpUnreachNlri.TYPE: |
616 | isWellKnown = false; | 612 | isWellKnown = false; |
617 | typeName = "MP_UNREACH_NLRI"; | 613 | typeName = "MP_UNREACH_NLRI"; |
618 | break; | 614 | break; |
... | @@ -643,7 +639,7 @@ final class BgpUpdate { | ... | @@ -643,7 +639,7 @@ final class BgpUpdate { |
643 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 639 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
644 | String errorMsg = "Attribute Flags Error for " + typeName + ": " + | 640 | String errorMsg = "Attribute Flags Error for " + typeName + ": " + |
645 | attrFlags; | 641 | attrFlags; |
646 | - throw new BgpParseException(errorMsg); | 642 | + throw new BgpMessage.BgpParseException(errorMsg); |
647 | } | 643 | } |
648 | } | 644 | } |
649 | 645 | ||
... | @@ -657,7 +653,7 @@ final class BgpUpdate { | ... | @@ -657,7 +653,7 @@ final class BgpUpdate { |
657 | * @param attrFlags the attribute flags | 653 | * @param attrFlags the attribute flags |
658 | * @param message the message to parse | 654 | * @param message the message to parse |
659 | * @return the parsed ORIGIN value | 655 | * @return the parsed ORIGIN value |
660 | - * @throws BgpParseException | 656 | + * @throws BgpMessage.BgpParseException |
661 | */ | 657 | */ |
662 | private static short parseAttributeTypeOrigin( | 658 | private static short parseAttributeTypeOrigin( |
663 | BgpSession bgpSession, | 659 | BgpSession bgpSession, |
... | @@ -666,25 +662,25 @@ final class BgpUpdate { | ... | @@ -666,25 +662,25 @@ final class BgpUpdate { |
666 | int attrLen, | 662 | int attrLen, |
667 | int attrFlags, | 663 | int attrFlags, |
668 | ChannelBuffer message) | 664 | ChannelBuffer message) |
669 | - throws BgpParseException { | 665 | + throws BgpMessage.BgpParseException { |
670 | 666 | ||
671 | // Check the Attribute Length | 667 | // Check the Attribute Length |
672 | - if (attrLen != Update.Origin.LENGTH) { | 668 | + if (attrLen != BgpConstants.Update.Origin.LENGTH) { |
673 | // ERROR: Attribute Length Error | 669 | // ERROR: Attribute Length Error |
674 | actionsBgpUpdateAttributeLengthError( | 670 | actionsBgpUpdateAttributeLengthError( |
675 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 671 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
676 | String errorMsg = "Attribute Length Error"; | 672 | String errorMsg = "Attribute Length Error"; |
677 | - throw new BgpParseException(errorMsg); | 673 | + throw new BgpMessage.BgpParseException(errorMsg); |
678 | } | 674 | } |
679 | 675 | ||
680 | message.markReaderIndex(); | 676 | message.markReaderIndex(); |
681 | short origin = message.readUnsignedByte(); | 677 | short origin = message.readUnsignedByte(); |
682 | switch (origin) { | 678 | switch (origin) { |
683 | - case Update.Origin.IGP: | 679 | + case BgpConstants.Update.Origin.IGP: |
684 | // FALLTHROUGH | 680 | // FALLTHROUGH |
685 | - case Update.Origin.EGP: | 681 | + case BgpConstants.Update.Origin.EGP: |
686 | // FALLTHROUGH | 682 | // FALLTHROUGH |
687 | - case Update.Origin.INCOMPLETE: | 683 | + case BgpConstants.Update.Origin.INCOMPLETE: |
688 | break; | 684 | break; |
689 | default: | 685 | default: |
690 | // ERROR: Invalid ORIGIN Attribute | 686 | // ERROR: Invalid ORIGIN Attribute |
... | @@ -693,7 +689,7 @@ final class BgpUpdate { | ... | @@ -693,7 +689,7 @@ final class BgpUpdate { |
693 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message, | 689 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message, |
694 | origin); | 690 | origin); |
695 | String errorMsg = "Invalid ORIGIN Attribute: " + origin; | 691 | String errorMsg = "Invalid ORIGIN Attribute: " + origin; |
696 | - throw new BgpParseException(errorMsg); | 692 | + throw new BgpMessage.BgpParseException(errorMsg); |
697 | } | 693 | } |
698 | 694 | ||
699 | return origin; | 695 | return origin; |
... | @@ -709,7 +705,7 @@ final class BgpUpdate { | ... | @@ -709,7 +705,7 @@ final class BgpUpdate { |
709 | * @param attrFlags the attribute flags | 705 | * @param attrFlags the attribute flags |
710 | * @param message the message to parse | 706 | * @param message the message to parse |
711 | * @return the parsed AS Path | 707 | * @return the parsed AS Path |
712 | - * @throws BgpParseException | 708 | + * @throws BgpMessage.BgpParseException |
713 | */ | 709 | */ |
714 | private static BgpRouteEntry.AsPath parseAttributeTypeAsPath( | 710 | private static BgpRouteEntry.AsPath parseAttributeTypeAsPath( |
715 | BgpSession bgpSession, | 711 | BgpSession bgpSession, |
... | @@ -718,7 +714,7 @@ final class BgpUpdate { | ... | @@ -718,7 +714,7 @@ final class BgpUpdate { |
718 | int attrLen, | 714 | int attrLen, |
719 | int attrFlags, | 715 | int attrFlags, |
720 | ChannelBuffer message) | 716 | ChannelBuffer message) |
721 | - throws BgpParseException { | 717 | + throws BgpMessage.BgpParseException { |
722 | ArrayList<BgpRouteEntry.PathSegment> pathSegments = new ArrayList<>(); | 718 | ArrayList<BgpRouteEntry.PathSegment> pathSegments = new ArrayList<>(); |
723 | 719 | ||
724 | // | 720 | // |
... | @@ -729,7 +725,7 @@ final class BgpUpdate { | ... | @@ -729,7 +725,7 @@ final class BgpUpdate { |
729 | // ERROR: Malformed AS_PATH | 725 | // ERROR: Malformed AS_PATH |
730 | actionsBgpUpdateMalformedAsPath(bgpSession, ctx); | 726 | actionsBgpUpdateMalformedAsPath(bgpSession, ctx); |
731 | String errorMsg = "Malformed AS Path"; | 727 | String errorMsg = "Malformed AS Path"; |
732 | - throw new BgpParseException(errorMsg); | 728 | + throw new BgpMessage.BgpParseException(errorMsg); |
733 | } | 729 | } |
734 | // Get the Path Segment Type and Length (in number of ASes) | 730 | // Get the Path Segment Type and Length (in number of ASes) |
735 | short pathSegmentType = message.readUnsignedByte(); | 731 | short pathSegmentType = message.readUnsignedByte(); |
... | @@ -738,13 +734,13 @@ final class BgpUpdate { | ... | @@ -738,13 +734,13 @@ final class BgpUpdate { |
738 | 734 | ||
739 | // Verify the Path Segment Type | 735 | // Verify the Path Segment Type |
740 | switch (pathSegmentType) { | 736 | switch (pathSegmentType) { |
741 | - case Update.AsPath.AS_SET: | 737 | + case BgpConstants.Update.AsPath.AS_SET: |
742 | // FALLTHROUGH | 738 | // FALLTHROUGH |
743 | - case Update.AsPath.AS_SEQUENCE: | 739 | + case BgpConstants.Update.AsPath.AS_SEQUENCE: |
744 | // FALLTHROUGH | 740 | // FALLTHROUGH |
745 | - case Update.AsPath.AS_CONFED_SEQUENCE: | 741 | + case BgpConstants.Update.AsPath.AS_CONFED_SEQUENCE: |
746 | // FALLTHROUGH | 742 | // FALLTHROUGH |
747 | - case Update.AsPath.AS_CONFED_SET: | 743 | + case BgpConstants.Update.AsPath.AS_CONFED_SET: |
748 | break; | 744 | break; |
749 | default: | 745 | default: |
750 | // ERROR: Invalid Path Segment Type | 746 | // ERROR: Invalid Path Segment Type |
... | @@ -756,15 +752,15 @@ final class BgpUpdate { | ... | @@ -756,15 +752,15 @@ final class BgpUpdate { |
756 | actionsBgpUpdateMalformedAsPath(bgpSession, ctx); | 752 | actionsBgpUpdateMalformedAsPath(bgpSession, ctx); |
757 | String errorMsg = | 753 | String errorMsg = |
758 | "Invalid AS Path Segment Type: " + pathSegmentType; | 754 | "Invalid AS Path Segment Type: " + pathSegmentType; |
759 | - throw new BgpParseException(errorMsg); | 755 | + throw new BgpMessage.BgpParseException(errorMsg); |
760 | } | 756 | } |
761 | 757 | ||
762 | // 4-octet AS number handling. | 758 | // 4-octet AS number handling. |
763 | int asPathLen; | 759 | int asPathLen; |
764 | if (bgpSession.isAs4OctetCapable()) { | 760 | if (bgpSession.isAs4OctetCapable()) { |
765 | - asPathLen = AsPath.AS_4OCTET_LENGTH; | 761 | + asPathLen = BgpConstants.Update.AsPath.AS_4OCTET_LENGTH; |
766 | } else { | 762 | } else { |
767 | - asPathLen = AsPath.AS_LENGTH; | 763 | + asPathLen = BgpConstants.Update.AsPath.AS_LENGTH; |
768 | } | 764 | } |
769 | 765 | ||
770 | // Parse the AS numbers | 766 | // Parse the AS numbers |
... | @@ -772,13 +768,13 @@ final class BgpUpdate { | ... | @@ -772,13 +768,13 @@ final class BgpUpdate { |
772 | // ERROR: Malformed AS_PATH | 768 | // ERROR: Malformed AS_PATH |
773 | actionsBgpUpdateMalformedAsPath(bgpSession, ctx); | 769 | actionsBgpUpdateMalformedAsPath(bgpSession, ctx); |
774 | String errorMsg = "Malformed AS Path"; | 770 | String errorMsg = "Malformed AS Path"; |
775 | - throw new BgpParseException(errorMsg); | 771 | + throw new BgpMessage.BgpParseException(errorMsg); |
776 | } | 772 | } |
777 | attrLen -= (asPathLen * pathSegmentLength); | 773 | attrLen -= (asPathLen * pathSegmentLength); |
778 | ArrayList<Long> segmentAsNumbers = new ArrayList<>(); | 774 | ArrayList<Long> segmentAsNumbers = new ArrayList<>(); |
779 | while (pathSegmentLength-- > 0) { | 775 | while (pathSegmentLength-- > 0) { |
780 | long asNumber; | 776 | long asNumber; |
781 | - if (asPathLen == AsPath.AS_4OCTET_LENGTH) { | 777 | + if (asPathLen == BgpConstants.Update.AsPath.AS_4OCTET_LENGTH) { |
782 | asNumber = message.readUnsignedInt(); | 778 | asNumber = message.readUnsignedInt(); |
783 | } else { | 779 | } else { |
784 | asNumber = message.readUnsignedShort(); | 780 | asNumber = message.readUnsignedShort(); |
... | @@ -805,7 +801,7 @@ final class BgpUpdate { | ... | @@ -805,7 +801,7 @@ final class BgpUpdate { |
805 | * @param attrFlags the attribute flags | 801 | * @param attrFlags the attribute flags |
806 | * @param message the message to parse | 802 | * @param message the message to parse |
807 | * @return the parsed NEXT_HOP value | 803 | * @return the parsed NEXT_HOP value |
808 | - * @throws BgpParseException | 804 | + * @throws BgpMessage.BgpParseException |
809 | */ | 805 | */ |
810 | private static Ip4Address parseAttributeTypeNextHop( | 806 | private static Ip4Address parseAttributeTypeNextHop( |
811 | BgpSession bgpSession, | 807 | BgpSession bgpSession, |
... | @@ -814,15 +810,15 @@ final class BgpUpdate { | ... | @@ -814,15 +810,15 @@ final class BgpUpdate { |
814 | int attrLen, | 810 | int attrLen, |
815 | int attrFlags, | 811 | int attrFlags, |
816 | ChannelBuffer message) | 812 | ChannelBuffer message) |
817 | - throws BgpParseException { | 813 | + throws BgpMessage.BgpParseException { |
818 | 814 | ||
819 | // Check the Attribute Length | 815 | // Check the Attribute Length |
820 | - if (attrLen != Update.NextHop.LENGTH) { | 816 | + if (attrLen != BgpConstants.Update.NextHop.LENGTH) { |
821 | // ERROR: Attribute Length Error | 817 | // ERROR: Attribute Length Error |
822 | actionsBgpUpdateAttributeLengthError( | 818 | actionsBgpUpdateAttributeLengthError( |
823 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 819 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
824 | String errorMsg = "Attribute Length Error"; | 820 | String errorMsg = "Attribute Length Error"; |
825 | - throw new BgpParseException(errorMsg); | 821 | + throw new BgpMessage.BgpParseException(errorMsg); |
826 | } | 822 | } |
827 | 823 | ||
828 | message.markReaderIndex(); | 824 | message.markReaderIndex(); |
... | @@ -845,7 +841,7 @@ final class BgpUpdate { | ... | @@ -845,7 +841,7 @@ final class BgpUpdate { |
845 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message, | 841 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message, |
846 | nextHopAddress); | 842 | nextHopAddress); |
847 | String errorMsg = "Invalid NEXT_HOP Attribute: " + nextHopAddress; | 843 | String errorMsg = "Invalid NEXT_HOP Attribute: " + nextHopAddress; |
848 | - throw new BgpParseException(errorMsg); | 844 | + throw new BgpMessage.BgpParseException(errorMsg); |
849 | } | 845 | } |
850 | 846 | ||
851 | return nextHopAddress; | 847 | return nextHopAddress; |
... | @@ -861,7 +857,7 @@ final class BgpUpdate { | ... | @@ -861,7 +857,7 @@ final class BgpUpdate { |
861 | * @param attrFlags the attribute flags | 857 | * @param attrFlags the attribute flags |
862 | * @param message the message to parse | 858 | * @param message the message to parse |
863 | * @return the parsed MULTI_EXIT_DISC value | 859 | * @return the parsed MULTI_EXIT_DISC value |
864 | - * @throws BgpParseException | 860 | + * @throws BgpMessage.BgpParseException |
865 | */ | 861 | */ |
866 | private static long parseAttributeTypeMultiExitDisc( | 862 | private static long parseAttributeTypeMultiExitDisc( |
867 | BgpSession bgpSession, | 863 | BgpSession bgpSession, |
... | @@ -870,15 +866,15 @@ final class BgpUpdate { | ... | @@ -870,15 +866,15 @@ final class BgpUpdate { |
870 | int attrLen, | 866 | int attrLen, |
871 | int attrFlags, | 867 | int attrFlags, |
872 | ChannelBuffer message) | 868 | ChannelBuffer message) |
873 | - throws BgpParseException { | 869 | + throws BgpMessage.BgpParseException { |
874 | 870 | ||
875 | // Check the Attribute Length | 871 | // Check the Attribute Length |
876 | - if (attrLen != Update.MultiExitDisc.LENGTH) { | 872 | + if (attrLen != BgpConstants.Update.MultiExitDisc.LENGTH) { |
877 | // ERROR: Attribute Length Error | 873 | // ERROR: Attribute Length Error |
878 | actionsBgpUpdateAttributeLengthError( | 874 | actionsBgpUpdateAttributeLengthError( |
879 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 875 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
880 | String errorMsg = "Attribute Length Error"; | 876 | String errorMsg = "Attribute Length Error"; |
881 | - throw new BgpParseException(errorMsg); | 877 | + throw new BgpMessage.BgpParseException(errorMsg); |
882 | } | 878 | } |
883 | 879 | ||
884 | long multiExitDisc = message.readUnsignedInt(); | 880 | long multiExitDisc = message.readUnsignedInt(); |
... | @@ -895,7 +891,7 @@ final class BgpUpdate { | ... | @@ -895,7 +891,7 @@ final class BgpUpdate { |
895 | * @param attrFlags the attribute flags | 891 | * @param attrFlags the attribute flags |
896 | * @param message the message to parse | 892 | * @param message the message to parse |
897 | * @return the parsed LOCAL_PREF value | 893 | * @return the parsed LOCAL_PREF value |
898 | - * @throws BgpParseException | 894 | + * @throws BgpMessage.BgpParseException |
899 | */ | 895 | */ |
900 | private static long parseAttributeTypeLocalPref( | 896 | private static long parseAttributeTypeLocalPref( |
901 | BgpSession bgpSession, | 897 | BgpSession bgpSession, |
... | @@ -904,15 +900,15 @@ final class BgpUpdate { | ... | @@ -904,15 +900,15 @@ final class BgpUpdate { |
904 | int attrLen, | 900 | int attrLen, |
905 | int attrFlags, | 901 | int attrFlags, |
906 | ChannelBuffer message) | 902 | ChannelBuffer message) |
907 | - throws BgpParseException { | 903 | + throws BgpMessage.BgpParseException { |
908 | 904 | ||
909 | // Check the Attribute Length | 905 | // Check the Attribute Length |
910 | - if (attrLen != Update.LocalPref.LENGTH) { | 906 | + if (attrLen != BgpConstants.Update.LocalPref.LENGTH) { |
911 | // ERROR: Attribute Length Error | 907 | // ERROR: Attribute Length Error |
912 | actionsBgpUpdateAttributeLengthError( | 908 | actionsBgpUpdateAttributeLengthError( |
913 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 909 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
914 | String errorMsg = "Attribute Length Error"; | 910 | String errorMsg = "Attribute Length Error"; |
915 | - throw new BgpParseException(errorMsg); | 911 | + throw new BgpMessage.BgpParseException(errorMsg); |
916 | } | 912 | } |
917 | 913 | ||
918 | long localPref = message.readUnsignedInt(); | 914 | long localPref = message.readUnsignedInt(); |
... | @@ -928,7 +924,7 @@ final class BgpUpdate { | ... | @@ -928,7 +924,7 @@ final class BgpUpdate { |
928 | * @param attrLen the attribute length (in octets) | 924 | * @param attrLen the attribute length (in octets) |
929 | * @param attrFlags the attribute flags | 925 | * @param attrFlags the attribute flags |
930 | * @param message the message to parse | 926 | * @param message the message to parse |
931 | - * @throws BgpParseException | 927 | + * @throws BgpMessage.BgpParseException |
932 | */ | 928 | */ |
933 | private static void parseAttributeTypeAtomicAggregate( | 929 | private static void parseAttributeTypeAtomicAggregate( |
934 | BgpSession bgpSession, | 930 | BgpSession bgpSession, |
... | @@ -937,15 +933,15 @@ final class BgpUpdate { | ... | @@ -937,15 +933,15 @@ final class BgpUpdate { |
937 | int attrLen, | 933 | int attrLen, |
938 | int attrFlags, | 934 | int attrFlags, |
939 | ChannelBuffer message) | 935 | ChannelBuffer message) |
940 | - throws BgpParseException { | 936 | + throws BgpMessage.BgpParseException { |
941 | 937 | ||
942 | // Check the Attribute Length | 938 | // Check the Attribute Length |
943 | - if (attrLen != Update.AtomicAggregate.LENGTH) { | 939 | + if (attrLen != BgpConstants.Update.AtomicAggregate.LENGTH) { |
944 | // ERROR: Attribute Length Error | 940 | // ERROR: Attribute Length Error |
945 | actionsBgpUpdateAttributeLengthError( | 941 | actionsBgpUpdateAttributeLengthError( |
946 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 942 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
947 | String errorMsg = "Attribute Length Error"; | 943 | String errorMsg = "Attribute Length Error"; |
948 | - throw new BgpParseException(errorMsg); | 944 | + throw new BgpMessage.BgpParseException(errorMsg); |
949 | } | 945 | } |
950 | 946 | ||
951 | // Nothing to do: this attribute is primarily informational | 947 | // Nothing to do: this attribute is primarily informational |
... | @@ -961,7 +957,7 @@ final class BgpUpdate { | ... | @@ -961,7 +957,7 @@ final class BgpUpdate { |
961 | * @param attrFlags the attribute flags | 957 | * @param attrFlags the attribute flags |
962 | * @param message the message to parse | 958 | * @param message the message to parse |
963 | * @return the parsed AGGREGATOR value: a tuple of <AS-Number, IP-Address> | 959 | * @return the parsed AGGREGATOR value: a tuple of <AS-Number, IP-Address> |
964 | - * @throws BgpParseException | 960 | + * @throws BgpMessage.BgpParseException |
965 | */ | 961 | */ |
966 | private static Pair<Long, Ip4Address> parseAttributeTypeAggregator( | 962 | private static Pair<Long, Ip4Address> parseAttributeTypeAggregator( |
967 | BgpSession bgpSession, | 963 | BgpSession bgpSession, |
... | @@ -970,15 +966,15 @@ final class BgpUpdate { | ... | @@ -970,15 +966,15 @@ final class BgpUpdate { |
970 | int attrLen, | 966 | int attrLen, |
971 | int attrFlags, | 967 | int attrFlags, |
972 | ChannelBuffer message) | 968 | ChannelBuffer message) |
973 | - throws BgpParseException { | 969 | + throws BgpMessage.BgpParseException { |
974 | 970 | ||
975 | // Check the Attribute Length | 971 | // Check the Attribute Length |
976 | - if (attrLen != Update.Aggregator.LENGTH) { | 972 | + if (attrLen != BgpConstants.Update.Aggregator.LENGTH) { |
977 | // ERROR: Attribute Length Error | 973 | // ERROR: Attribute Length Error |
978 | actionsBgpUpdateAttributeLengthError( | 974 | actionsBgpUpdateAttributeLengthError( |
979 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 975 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
980 | String errorMsg = "Attribute Length Error"; | 976 | String errorMsg = "Attribute Length Error"; |
981 | - throw new BgpParseException(errorMsg); | 977 | + throw new BgpMessage.BgpParseException(errorMsg); |
982 | } | 978 | } |
983 | 979 | ||
984 | // The AGGREGATOR AS number | 980 | // The AGGREGATOR AS number |
... | @@ -1003,7 +999,7 @@ final class BgpUpdate { | ... | @@ -1003,7 +999,7 @@ final class BgpUpdate { |
1003 | * @param message the message to parse | 999 | * @param message the message to parse |
1004 | * @return the parsed MP_REACH_NLRI information if recognized, otherwise | 1000 | * @return the parsed MP_REACH_NLRI information if recognized, otherwise |
1005 | * null | 1001 | * null |
1006 | - * @throws BgpParseException | 1002 | + * @throws BgpMessage.BgpParseException |
1007 | */ | 1003 | */ |
1008 | private static MpNlri parseAttributeTypeMpReachNlri( | 1004 | private static MpNlri parseAttributeTypeMpReachNlri( |
1009 | BgpSession bgpSession, | 1005 | BgpSession bgpSession, |
... | @@ -1012,16 +1008,16 @@ final class BgpUpdate { | ... | @@ -1012,16 +1008,16 @@ final class BgpUpdate { |
1012 | int attrLen, | 1008 | int attrLen, |
1013 | int attrFlags, | 1009 | int attrFlags, |
1014 | ChannelBuffer message) | 1010 | ChannelBuffer message) |
1015 | - throws BgpParseException { | 1011 | + throws BgpMessage.BgpParseException { |
1016 | int attributeEnd = message.readerIndex() + attrLen; | 1012 | int attributeEnd = message.readerIndex() + attrLen; |
1017 | 1013 | ||
1018 | // Check the Attribute Length | 1014 | // Check the Attribute Length |
1019 | - if (attrLen < Update.MpReachNlri.MIN_LENGTH) { | 1015 | + if (attrLen < BgpConstants.Update.MpReachNlri.MIN_LENGTH) { |
1020 | // ERROR: Attribute Length Error | 1016 | // ERROR: Attribute Length Error |
1021 | actionsBgpUpdateAttributeLengthError( | 1017 | actionsBgpUpdateAttributeLengthError( |
1022 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 1018 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
1023 | String errorMsg = "Attribute Length Error"; | 1019 | String errorMsg = "Attribute Length Error"; |
1024 | - throw new BgpParseException(errorMsg); | 1020 | + throw new BgpMessage.BgpParseException(errorMsg); |
1025 | } | 1021 | } |
1026 | 1022 | ||
1027 | message.markReaderIndex(); | 1023 | message.markReaderIndex(); |
... | @@ -1033,9 +1029,9 @@ final class BgpUpdate { | ... | @@ -1033,9 +1029,9 @@ final class BgpUpdate { |
1033 | // Verify the AFI/SAFI, and skip the attribute if not recognized. | 1029 | // Verify the AFI/SAFI, and skip the attribute if not recognized. |
1034 | // NOTE: Currently, we support only IPv4/IPv6 UNICAST | 1030 | // NOTE: Currently, we support only IPv4/IPv6 UNICAST |
1035 | // | 1031 | // |
1036 | - if (((afi != MultiprotocolExtensions.AFI_IPV4) && | 1032 | + if (((afi != BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4) && |
1037 | - (afi != MultiprotocolExtensions.AFI_IPV6)) || | 1033 | + (afi != BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6)) || |
1038 | - (safi != MultiprotocolExtensions.SAFI_UNICAST)) { | 1034 | + (safi != BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST)) { |
1039 | // Skip the attribute | 1035 | // Skip the attribute |
1040 | message.resetReaderIndex(); | 1036 | message.resetReaderIndex(); |
1041 | message.skipBytes(attrLen); | 1037 | message.skipBytes(attrLen); |
... | @@ -1047,10 +1043,10 @@ final class BgpUpdate { | ... | @@ -1047,10 +1043,10 @@ final class BgpUpdate { |
1047 | // | 1043 | // |
1048 | int expectedNextHopLen = 0; | 1044 | int expectedNextHopLen = 0; |
1049 | switch (afi) { | 1045 | switch (afi) { |
1050 | - case MultiprotocolExtensions.AFI_IPV4: | 1046 | + case BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4: |
1051 | expectedNextHopLen = Ip4Address.BYTE_LENGTH; | 1047 | expectedNextHopLen = Ip4Address.BYTE_LENGTH; |
1052 | break; | 1048 | break; |
1053 | - case MultiprotocolExtensions.AFI_IPV6: | 1049 | + case BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6: |
1054 | expectedNextHopLen = Ip6Address.BYTE_LENGTH; | 1050 | expectedNextHopLen = Ip6Address.BYTE_LENGTH; |
1055 | break; | 1051 | break; |
1056 | default: | 1052 | default: |
... | @@ -1064,7 +1060,7 @@ final class BgpUpdate { | ... | @@ -1064,7 +1060,7 @@ final class BgpUpdate { |
1064 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 1060 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
1065 | String errorMsg = "Invalid next-hop network address length. " + | 1061 | String errorMsg = "Invalid next-hop network address length. " + |
1066 | "Received " + nextHopLen + " expected " + expectedNextHopLen; | 1062 | "Received " + nextHopLen + " expected " + expectedNextHopLen; |
1067 | - throw new BgpParseException(errorMsg); | 1063 | + throw new BgpMessage.BgpParseException(errorMsg); |
1068 | } | 1064 | } |
1069 | // NOTE: We use "+ 1" to take into account the Reserved field (1 octet) | 1065 | // NOTE: We use "+ 1" to take into account the Reserved field (1 octet) |
1070 | if (message.readerIndex() + nextHopLen + 1 >= attributeEnd) { | 1066 | if (message.readerIndex() + nextHopLen + 1 >= attributeEnd) { |
... | @@ -1073,7 +1069,7 @@ final class BgpUpdate { | ... | @@ -1073,7 +1069,7 @@ final class BgpUpdate { |
1073 | actionsBgpUpdateOptionalAttributeError( | 1069 | actionsBgpUpdateOptionalAttributeError( |
1074 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 1070 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
1075 | String errorMsg = "Malformed next-hop network address"; | 1071 | String errorMsg = "Malformed next-hop network address"; |
1076 | - throw new BgpParseException(errorMsg); | 1072 | + throw new BgpMessage.BgpParseException(errorMsg); |
1077 | } | 1073 | } |
1078 | 1074 | ||
1079 | // | 1075 | // |
... | @@ -1085,7 +1081,7 @@ final class BgpUpdate { | ... | @@ -1085,7 +1081,7 @@ final class BgpUpdate { |
1085 | MpNlri mpNlri = new MpNlri(afi, safi); | 1081 | MpNlri mpNlri = new MpNlri(afi, safi); |
1086 | try { | 1082 | try { |
1087 | switch (afi) { | 1083 | switch (afi) { |
1088 | - case MultiprotocolExtensions.AFI_IPV4: | 1084 | + case BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4: |
1089 | // The next-hop address | 1085 | // The next-hop address |
1090 | mpNlri.nextHop4 = Ip4Address.valueOf(nextHopBuffer); | 1086 | mpNlri.nextHop4 = Ip4Address.valueOf(nextHopBuffer); |
1091 | // The NLRI | 1087 | // The NLRI |
... | @@ -1093,7 +1089,7 @@ final class BgpUpdate { | ... | @@ -1093,7 +1089,7 @@ final class BgpUpdate { |
1093 | attributeEnd - message.readerIndex(), | 1089 | attributeEnd - message.readerIndex(), |
1094 | message); | 1090 | message); |
1095 | break; | 1091 | break; |
1096 | - case MultiprotocolExtensions.AFI_IPV6: | 1092 | + case BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6: |
1097 | // The next-hop address | 1093 | // The next-hop address |
1098 | mpNlri.nextHop6 = Ip6Address.valueOf(nextHopBuffer); | 1094 | mpNlri.nextHop6 = Ip6Address.valueOf(nextHopBuffer); |
1099 | // The NLRI | 1095 | // The NLRI |
... | @@ -1105,13 +1101,13 @@ final class BgpUpdate { | ... | @@ -1105,13 +1101,13 @@ final class BgpUpdate { |
1105 | // UNREACHABLE | 1101 | // UNREACHABLE |
1106 | break; | 1102 | break; |
1107 | } | 1103 | } |
1108 | - } catch (BgpParseException e) { | 1104 | + } catch (BgpMessage.BgpParseException e) { |
1109 | // ERROR: Optional Attribute Error | 1105 | // ERROR: Optional Attribute Error |
1110 | message.resetReaderIndex(); | 1106 | message.resetReaderIndex(); |
1111 | actionsBgpUpdateOptionalAttributeError( | 1107 | actionsBgpUpdateOptionalAttributeError( |
1112 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 1108 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
1113 | String errorMsg = "Malformed network layer reachability information"; | 1109 | String errorMsg = "Malformed network layer reachability information"; |
1114 | - throw new BgpParseException(errorMsg); | 1110 | + throw new BgpMessage.BgpParseException(errorMsg); |
1115 | } | 1111 | } |
1116 | 1112 | ||
1117 | return mpNlri; | 1113 | return mpNlri; |
... | @@ -1128,7 +1124,7 @@ final class BgpUpdate { | ... | @@ -1128,7 +1124,7 @@ final class BgpUpdate { |
1128 | * @param message the message to parse | 1124 | * @param message the message to parse |
1129 | * @return the parsed MP_UNREACH_NLRI information if recognized, otherwise | 1125 | * @return the parsed MP_UNREACH_NLRI information if recognized, otherwise |
1130 | * null | 1126 | * null |
1131 | - * @throws BgpParseException | 1127 | + * @throws BgpMessage.BgpParseException |
1132 | */ | 1128 | */ |
1133 | private static MpNlri parseAttributeTypeMpUnreachNlri( | 1129 | private static MpNlri parseAttributeTypeMpUnreachNlri( |
1134 | BgpSession bgpSession, | 1130 | BgpSession bgpSession, |
... | @@ -1137,16 +1133,16 @@ final class BgpUpdate { | ... | @@ -1137,16 +1133,16 @@ final class BgpUpdate { |
1137 | int attrLen, | 1133 | int attrLen, |
1138 | int attrFlags, | 1134 | int attrFlags, |
1139 | ChannelBuffer message) | 1135 | ChannelBuffer message) |
1140 | - throws BgpParseException { | 1136 | + throws BgpMessage.BgpParseException { |
1141 | int attributeEnd = message.readerIndex() + attrLen; | 1137 | int attributeEnd = message.readerIndex() + attrLen; |
1142 | 1138 | ||
1143 | // Check the Attribute Length | 1139 | // Check the Attribute Length |
1144 | - if (attrLen < Update.MpUnreachNlri.MIN_LENGTH) { | 1140 | + if (attrLen < BgpConstants.Update.MpUnreachNlri.MIN_LENGTH) { |
1145 | // ERROR: Attribute Length Error | 1141 | // ERROR: Attribute Length Error |
1146 | actionsBgpUpdateAttributeLengthError( | 1142 | actionsBgpUpdateAttributeLengthError( |
1147 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 1143 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
1148 | String errorMsg = "Attribute Length Error"; | 1144 | String errorMsg = "Attribute Length Error"; |
1149 | - throw new BgpParseException(errorMsg); | 1145 | + throw new BgpMessage.BgpParseException(errorMsg); |
1150 | } | 1146 | } |
1151 | 1147 | ||
1152 | message.markReaderIndex(); | 1148 | message.markReaderIndex(); |
... | @@ -1157,9 +1153,9 @@ final class BgpUpdate { | ... | @@ -1157,9 +1153,9 @@ final class BgpUpdate { |
1157 | // Verify the AFI/SAFI, and skip the attribute if not recognized. | 1153 | // Verify the AFI/SAFI, and skip the attribute if not recognized. |
1158 | // NOTE: Currently, we support only IPv4/IPv6 UNICAST | 1154 | // NOTE: Currently, we support only IPv4/IPv6 UNICAST |
1159 | // | 1155 | // |
1160 | - if (((afi != MultiprotocolExtensions.AFI_IPV4) && | 1156 | + if (((afi != BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4) && |
1161 | - (afi != MultiprotocolExtensions.AFI_IPV6)) || | 1157 | + (afi != BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6)) || |
1162 | - (safi != MultiprotocolExtensions.SAFI_UNICAST)) { | 1158 | + (safi != BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST)) { |
1163 | // Skip the attribute | 1159 | // Skip the attribute |
1164 | message.resetReaderIndex(); | 1160 | message.resetReaderIndex(); |
1165 | message.skipBytes(attrLen); | 1161 | message.skipBytes(attrLen); |
... | @@ -1172,13 +1168,13 @@ final class BgpUpdate { | ... | @@ -1172,13 +1168,13 @@ final class BgpUpdate { |
1172 | MpNlri mpNlri = new MpNlri(afi, safi); | 1168 | MpNlri mpNlri = new MpNlri(afi, safi); |
1173 | try { | 1169 | try { |
1174 | switch (afi) { | 1170 | switch (afi) { |
1175 | - case MultiprotocolExtensions.AFI_IPV4: | 1171 | + case BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4: |
1176 | // The Withdrawn Routes | 1172 | // The Withdrawn Routes |
1177 | mpNlri.nlri4 = parsePackedIp4Prefixes( | 1173 | mpNlri.nlri4 = parsePackedIp4Prefixes( |
1178 | attributeEnd - message.readerIndex(), | 1174 | attributeEnd - message.readerIndex(), |
1179 | message); | 1175 | message); |
1180 | break; | 1176 | break; |
1181 | - case MultiprotocolExtensions.AFI_IPV6: | 1177 | + case BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6: |
1182 | // The Withdrawn Routes | 1178 | // The Withdrawn Routes |
1183 | mpNlri.nlri6 = parsePackedIp6Prefixes( | 1179 | mpNlri.nlri6 = parsePackedIp6Prefixes( |
1184 | attributeEnd - message.readerIndex(), | 1180 | attributeEnd - message.readerIndex(), |
... | @@ -1188,13 +1184,13 @@ final class BgpUpdate { | ... | @@ -1188,13 +1184,13 @@ final class BgpUpdate { |
1188 | // UNREACHABLE | 1184 | // UNREACHABLE |
1189 | break; | 1185 | break; |
1190 | } | 1186 | } |
1191 | - } catch (BgpParseException e) { | 1187 | + } catch (BgpMessage.BgpParseException e) { |
1192 | // ERROR: Optional Attribute Error | 1188 | // ERROR: Optional Attribute Error |
1193 | message.resetReaderIndex(); | 1189 | message.resetReaderIndex(); |
1194 | actionsBgpUpdateOptionalAttributeError( | 1190 | actionsBgpUpdateOptionalAttributeError( |
1195 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 1191 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
1196 | String errorMsg = "Malformed withdrawn routes"; | 1192 | String errorMsg = "Malformed withdrawn routes"; |
1197 | - throw new BgpParseException(errorMsg); | 1193 | + throw new BgpMessage.BgpParseException(errorMsg); |
1198 | } | 1194 | } |
1199 | 1195 | ||
1200 | return mpNlri; | 1196 | return mpNlri; |
... | @@ -1211,12 +1207,12 @@ final class BgpUpdate { | ... | @@ -1211,12 +1207,12 @@ final class BgpUpdate { |
1211 | * @param totalLength the total length of the data to parse | 1207 | * @param totalLength the total length of the data to parse |
1212 | * @param message the message with data to parse | 1208 | * @param message the message with data to parse |
1213 | * @return a collection of parsed IPv4 network prefixes | 1209 | * @return a collection of parsed IPv4 network prefixes |
1214 | - * @throws BgpParseException | 1210 | + * @throws BgpMessage.BgpParseException |
1215 | */ | 1211 | */ |
1216 | private static Collection<Ip4Prefix> parsePackedIp4Prefixes( | 1212 | private static Collection<Ip4Prefix> parsePackedIp4Prefixes( |
1217 | int totalLength, | 1213 | int totalLength, |
1218 | ChannelBuffer message) | 1214 | ChannelBuffer message) |
1219 | - throws BgpParseException { | 1215 | + throws BgpMessage.BgpParseException { |
1220 | Collection<Ip4Prefix> result = new ArrayList<>(); | 1216 | Collection<Ip4Prefix> result = new ArrayList<>(); |
1221 | 1217 | ||
1222 | if (totalLength == 0) { | 1218 | if (totalLength == 0) { |
... | @@ -1231,7 +1227,7 @@ final class BgpUpdate { | ... | @@ -1231,7 +1227,7 @@ final class BgpUpdate { |
1231 | int prefixBytelen = (prefixBitlen + 7) / 8; // Round-up | 1227 | int prefixBytelen = (prefixBitlen + 7) / 8; // Round-up |
1232 | if (message.readerIndex() + prefixBytelen > dataEnd) { | 1228 | if (message.readerIndex() + prefixBytelen > dataEnd) { |
1233 | String errorMsg = "Malformed Network Prefixes"; | 1229 | String errorMsg = "Malformed Network Prefixes"; |
1234 | - throw new BgpParseException(errorMsg); | 1230 | + throw new BgpMessage.BgpParseException(errorMsg); |
1235 | } | 1231 | } |
1236 | 1232 | ||
1237 | message.readBytes(buffer, 0, prefixBytelen); | 1233 | message.readBytes(buffer, 0, prefixBytelen); |
... | @@ -1254,12 +1250,12 @@ final class BgpUpdate { | ... | @@ -1254,12 +1250,12 @@ final class BgpUpdate { |
1254 | * @param totalLength the total length of the data to parse | 1250 | * @param totalLength the total length of the data to parse |
1255 | * @param message the message with data to parse | 1251 | * @param message the message with data to parse |
1256 | * @return a collection of parsed IPv6 network prefixes | 1252 | * @return a collection of parsed IPv6 network prefixes |
1257 | - * @throws BgpParseException | 1253 | + * @throws BgpMessage.BgpParseException |
1258 | */ | 1254 | */ |
1259 | private static Collection<Ip6Prefix> parsePackedIp6Prefixes( | 1255 | private static Collection<Ip6Prefix> parsePackedIp6Prefixes( |
1260 | int totalLength, | 1256 | int totalLength, |
1261 | ChannelBuffer message) | 1257 | ChannelBuffer message) |
1262 | - throws BgpParseException { | 1258 | + throws BgpMessage.BgpParseException { |
1263 | Collection<Ip6Prefix> result = new ArrayList<>(); | 1259 | Collection<Ip6Prefix> result = new ArrayList<>(); |
1264 | 1260 | ||
1265 | if (totalLength == 0) { | 1261 | if (totalLength == 0) { |
... | @@ -1274,7 +1270,7 @@ final class BgpUpdate { | ... | @@ -1274,7 +1270,7 @@ final class BgpUpdate { |
1274 | int prefixBytelen = (prefixBitlen + 7) / 8; // Round-up | 1270 | int prefixBytelen = (prefixBitlen + 7) / 8; // Round-up |
1275 | if (message.readerIndex() + prefixBytelen > dataEnd) { | 1271 | if (message.readerIndex() + prefixBytelen > dataEnd) { |
1276 | String errorMsg = "Malformed Network Prefixes"; | 1272 | String errorMsg = "Malformed Network Prefixes"; |
1277 | - throw new BgpParseException(errorMsg); | 1273 | + throw new BgpMessage.BgpParseException(errorMsg); |
1278 | } | 1274 | } |
1279 | 1275 | ||
1280 | message.readBytes(buffer, 0, prefixBytelen); | 1276 | message.readBytes(buffer, 0, prefixBytelen); |
... | @@ -1303,8 +1299,8 @@ final class BgpUpdate { | ... | @@ -1303,8 +1299,8 @@ final class BgpUpdate { |
1303 | // ERROR: Invalid Network Field | 1299 | // ERROR: Invalid Network Field |
1304 | // | 1300 | // |
1305 | // Send NOTIFICATION and close the connection | 1301 | // Send NOTIFICATION and close the connection |
1306 | - int errorCode = UpdateMessageError.ERROR_CODE; | 1302 | + int errorCode = BgpConstants.Notifications.UpdateMessageError.ERROR_CODE; |
1307 | - int errorSubcode = UpdateMessageError.INVALID_NETWORK_FIELD; | 1303 | + int errorSubcode = BgpConstants.Notifications.UpdateMessageError.INVALID_NETWORK_FIELD; |
1308 | ChannelBuffer txMessage = | 1304 | ChannelBuffer txMessage = |
1309 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, | 1305 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, |
1310 | null); | 1306 | null); |
... | @@ -1329,8 +1325,8 @@ final class BgpUpdate { | ... | @@ -1329,8 +1325,8 @@ final class BgpUpdate { |
1329 | // ERROR: Malformed Attribute List | 1325 | // ERROR: Malformed Attribute List |
1330 | // | 1326 | // |
1331 | // Send NOTIFICATION and close the connection | 1327 | // Send NOTIFICATION and close the connection |
1332 | - int errorCode = UpdateMessageError.ERROR_CODE; | 1328 | + int errorCode = BgpConstants.Notifications.UpdateMessageError.ERROR_CODE; |
1333 | - int errorSubcode = UpdateMessageError.MALFORMED_ATTRIBUTE_LIST; | 1329 | + int errorSubcode = BgpConstants.Notifications.UpdateMessageError.MALFORMED_ATTRIBUTE_LIST; |
1334 | ChannelBuffer txMessage = | 1330 | ChannelBuffer txMessage = |
1335 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, | 1331 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, |
1336 | null); | 1332 | null); |
... | @@ -1358,8 +1354,8 @@ final class BgpUpdate { | ... | @@ -1358,8 +1354,8 @@ final class BgpUpdate { |
1358 | // ERROR: Missing Well-known Attribute | 1354 | // ERROR: Missing Well-known Attribute |
1359 | // | 1355 | // |
1360 | // Send NOTIFICATION and close the connection | 1356 | // Send NOTIFICATION and close the connection |
1361 | - int errorCode = UpdateMessageError.ERROR_CODE; | 1357 | + int errorCode = BgpConstants.Notifications.UpdateMessageError.ERROR_CODE; |
1362 | - int errorSubcode = UpdateMessageError.MISSING_WELL_KNOWN_ATTRIBUTE; | 1358 | + int errorSubcode = BgpConstants.Notifications.UpdateMessageError.MISSING_WELL_KNOWN_ATTRIBUTE; |
1363 | ChannelBuffer data = ChannelBuffers.buffer(1); | 1359 | ChannelBuffer data = ChannelBuffers.buffer(1); |
1364 | data.writeByte(missingAttrTypeCode); | 1360 | data.writeByte(missingAttrTypeCode); |
1365 | ChannelBuffer txMessage = | 1361 | ChannelBuffer txMessage = |
... | @@ -1396,8 +1392,8 @@ final class BgpUpdate { | ... | @@ -1396,8 +1392,8 @@ final class BgpUpdate { |
1396 | // ERROR: Invalid ORIGIN Attribute | 1392 | // ERROR: Invalid ORIGIN Attribute |
1397 | // | 1393 | // |
1398 | // Send NOTIFICATION and close the connection | 1394 | // Send NOTIFICATION and close the connection |
1399 | - int errorCode = UpdateMessageError.ERROR_CODE; | 1395 | + int errorCode = BgpConstants.Notifications.UpdateMessageError.ERROR_CODE; |
1400 | - int errorSubcode = UpdateMessageError.INVALID_ORIGIN_ATTRIBUTE; | 1396 | + int errorSubcode = BgpConstants.Notifications.UpdateMessageError.INVALID_ORIGIN_ATTRIBUTE; |
1401 | ChannelBuffer data = | 1397 | ChannelBuffer data = |
1402 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, | 1398 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, |
1403 | attrFlags, message); | 1399 | attrFlags, message); |
... | @@ -1433,8 +1429,8 @@ final class BgpUpdate { | ... | @@ -1433,8 +1429,8 @@ final class BgpUpdate { |
1433 | // ERROR: Attribute Flags Error | 1429 | // ERROR: Attribute Flags Error |
1434 | // | 1430 | // |
1435 | // Send NOTIFICATION and close the connection | 1431 | // Send NOTIFICATION and close the connection |
1436 | - int errorCode = UpdateMessageError.ERROR_CODE; | 1432 | + int errorCode = BgpConstants.Notifications.UpdateMessageError.ERROR_CODE; |
1437 | - int errorSubcode = UpdateMessageError.ATTRIBUTE_FLAGS_ERROR; | 1433 | + int errorSubcode = BgpConstants.Notifications.UpdateMessageError.ATTRIBUTE_FLAGS_ERROR; |
1438 | ChannelBuffer data = | 1434 | ChannelBuffer data = |
1439 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, | 1435 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, |
1440 | attrFlags, message); | 1436 | attrFlags, message); |
... | @@ -1473,8 +1469,8 @@ final class BgpUpdate { | ... | @@ -1473,8 +1469,8 @@ final class BgpUpdate { |
1473 | // ERROR: Invalid NEXT_HOP Attribute | 1469 | // ERROR: Invalid NEXT_HOP Attribute |
1474 | // | 1470 | // |
1475 | // Send NOTIFICATION and close the connection | 1471 | // Send NOTIFICATION and close the connection |
1476 | - int errorCode = UpdateMessageError.ERROR_CODE; | 1472 | + int errorCode = BgpConstants.Notifications.UpdateMessageError.ERROR_CODE; |
1477 | - int errorSubcode = UpdateMessageError.INVALID_NEXT_HOP_ATTRIBUTE; | 1473 | + int errorSubcode = BgpConstants.Notifications.UpdateMessageError.INVALID_NEXT_HOP_ATTRIBUTE; |
1478 | ChannelBuffer data = | 1474 | ChannelBuffer data = |
1479 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, | 1475 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, |
1480 | attrFlags, message); | 1476 | attrFlags, message); |
... | @@ -1512,9 +1508,9 @@ final class BgpUpdate { | ... | @@ -1512,9 +1508,9 @@ final class BgpUpdate { |
1512 | // ERROR: Unrecognized Well-known Attribute | 1508 | // ERROR: Unrecognized Well-known Attribute |
1513 | // | 1509 | // |
1514 | // Send NOTIFICATION and close the connection | 1510 | // Send NOTIFICATION and close the connection |
1515 | - int errorCode = UpdateMessageError.ERROR_CODE; | 1511 | + int errorCode = BgpConstants.Notifications.UpdateMessageError.ERROR_CODE; |
1516 | int errorSubcode = | 1512 | int errorSubcode = |
1517 | - UpdateMessageError.UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE; | 1513 | + BgpConstants.Notifications.UpdateMessageError.UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE; |
1518 | ChannelBuffer data = | 1514 | ChannelBuffer data = |
1519 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, | 1515 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, |
1520 | attrFlags, message); | 1516 | attrFlags, message); |
... | @@ -1551,9 +1547,9 @@ final class BgpUpdate { | ... | @@ -1551,9 +1547,9 @@ final class BgpUpdate { |
1551 | // ERROR: Optional Attribute Error | 1547 | // ERROR: Optional Attribute Error |
1552 | // | 1548 | // |
1553 | // Send NOTIFICATION and close the connection | 1549 | // Send NOTIFICATION and close the connection |
1554 | - int errorCode = UpdateMessageError.ERROR_CODE; | 1550 | + int errorCode = BgpConstants.Notifications.UpdateMessageError.ERROR_CODE; |
1555 | int errorSubcode = | 1551 | int errorSubcode = |
1556 | - UpdateMessageError.OPTIONAL_ATTRIBUTE_ERROR; | 1552 | + BgpConstants.Notifications.UpdateMessageError.OPTIONAL_ATTRIBUTE_ERROR; |
1557 | ChannelBuffer data = | 1553 | ChannelBuffer data = |
1558 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, | 1554 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, |
1559 | attrFlags, message); | 1555 | attrFlags, message); |
... | @@ -1589,8 +1585,8 @@ final class BgpUpdate { | ... | @@ -1589,8 +1585,8 @@ final class BgpUpdate { |
1589 | // ERROR: Attribute Length Error | 1585 | // ERROR: Attribute Length Error |
1590 | // | 1586 | // |
1591 | // Send NOTIFICATION and close the connection | 1587 | // Send NOTIFICATION and close the connection |
1592 | - int errorCode = UpdateMessageError.ERROR_CODE; | 1588 | + int errorCode = BgpConstants.Notifications.UpdateMessageError.ERROR_CODE; |
1593 | - int errorSubcode = UpdateMessageError.ATTRIBUTE_LENGTH_ERROR; | 1589 | + int errorSubcode = BgpConstants.Notifications.UpdateMessageError.ATTRIBUTE_LENGTH_ERROR; |
1594 | ChannelBuffer data = | 1590 | ChannelBuffer data = |
1595 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, | 1591 | prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, |
1596 | attrFlags, message); | 1592 | attrFlags, message); |
... | @@ -1618,8 +1614,8 @@ final class BgpUpdate { | ... | @@ -1618,8 +1614,8 @@ final class BgpUpdate { |
1618 | // ERROR: Malformed AS_PATH | 1614 | // ERROR: Malformed AS_PATH |
1619 | // | 1615 | // |
1620 | // Send NOTIFICATION and close the connection | 1616 | // Send NOTIFICATION and close the connection |
1621 | - int errorCode = UpdateMessageError.ERROR_CODE; | 1617 | + int errorCode = BgpConstants.Notifications.UpdateMessageError.ERROR_CODE; |
1622 | - int errorSubcode = UpdateMessageError.MALFORMED_AS_PATH; | 1618 | + int errorSubcode = BgpConstants.Notifications.UpdateMessageError.MALFORMED_AS_PATH; |
1623 | ChannelBuffer txMessage = | 1619 | ChannelBuffer txMessage = |
1624 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, | 1620 | BgpNotification.prepareBgpNotification(errorCode, errorSubcode, |
1625 | null); | 1621 | null); | ... | ... |
... | @@ -13,9 +13,7 @@ | ... | @@ -13,9 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.cli; | 16 | +package org.onosproject.routing.cli; |
17 | - | ||
18 | -import java.util.Collection; | ||
19 | 17 | ||
20 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
21 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
... | @@ -24,8 +22,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode; | ... | @@ -24,8 +22,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode; |
24 | import org.apache.karaf.shell.commands.Command; | 22 | import org.apache.karaf.shell.commands.Command; |
25 | import org.apache.karaf.shell.commands.Option; | 23 | import org.apache.karaf.shell.commands.Option; |
26 | import org.onosproject.cli.AbstractShellCommand; | 24 | import org.onosproject.cli.AbstractShellCommand; |
27 | -import org.onosproject.sdnip.SdnIpService; | 25 | +import org.onosproject.routing.bgp.BgpInfoService; |
28 | -import org.onosproject.sdnip.bgp.BgpSession; | 26 | +import org.onosproject.routing.bgp.BgpSession; |
27 | + | ||
28 | +import java.util.Collection; | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Command to show the BGP neighbors. | 31 | * Command to show the BGP neighbors. |
... | @@ -53,7 +53,7 @@ public class BgpNeighborsListCommand extends AbstractShellCommand { | ... | @@ -53,7 +53,7 @@ public class BgpNeighborsListCommand extends AbstractShellCommand { |
53 | 53 | ||
54 | @Override | 54 | @Override |
55 | protected void execute() { | 55 | protected void execute() { |
56 | - SdnIpService service = get(SdnIpService.class); | 56 | + BgpInfoService service = AbstractShellCommand.get(BgpInfoService.class); |
57 | Collection<BgpSession> bgpSessions = service.getBgpSessions(); | 57 | Collection<BgpSession> bgpSessions = service.getBgpSessions(); |
58 | 58 | ||
59 | if (bgpNeighbor != null) { | 59 | if (bgpNeighbor != null) { | ... | ... |
... | @@ -13,10 +13,7 @@ | ... | @@ -13,10 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.cli; | 16 | +package org.onosproject.routing.cli; |
17 | - | ||
18 | -import java.util.ArrayList; | ||
19 | -import java.util.Collection; | ||
20 | 17 | ||
21 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
22 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
... | @@ -25,10 +22,13 @@ import com.fasterxml.jackson.databind.node.ObjectNode; | ... | @@ -25,10 +22,13 @@ import com.fasterxml.jackson.databind.node.ObjectNode; |
25 | import org.apache.karaf.shell.commands.Command; | 22 | import org.apache.karaf.shell.commands.Command; |
26 | import org.apache.karaf.shell.commands.Option; | 23 | import org.apache.karaf.shell.commands.Option; |
27 | import org.onosproject.cli.AbstractShellCommand; | 24 | import org.onosproject.cli.AbstractShellCommand; |
28 | -import org.onosproject.sdnip.SdnIpService; | 25 | +import org.onosproject.routing.bgp.BgpConstants.Update; |
29 | -import org.onosproject.sdnip.bgp.BgpConstants.Update; | 26 | +import org.onosproject.routing.bgp.BgpInfoService; |
30 | -import org.onosproject.sdnip.bgp.BgpRouteEntry; | 27 | +import org.onosproject.routing.bgp.BgpRouteEntry; |
31 | -import org.onosproject.sdnip.bgp.BgpSession; | 28 | +import org.onosproject.routing.bgp.BgpSession; |
29 | + | ||
30 | +import java.util.ArrayList; | ||
31 | +import java.util.Collection; | ||
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Command to show the routes learned through BGP. | 34 | * Command to show the routes learned through BGP. |
... | @@ -59,7 +59,7 @@ public class BgpRoutesListCommand extends AbstractShellCommand { | ... | @@ -59,7 +59,7 @@ public class BgpRoutesListCommand extends AbstractShellCommand { |
59 | 59 | ||
60 | @Override | 60 | @Override |
61 | protected void execute() { | 61 | protected void execute() { |
62 | - SdnIpService service = get(SdnIpService.class); | 62 | + BgpInfoService service = AbstractShellCommand.get(BgpInfoService.class); |
63 | 63 | ||
64 | // Print summary of the routes | 64 | // Print summary of the routes |
65 | if (routesSummary) { | 65 | if (routesSummary) { | ... | ... |
... | @@ -13,9 +13,7 @@ | ... | @@ -13,9 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.cli; | 16 | +package org.onosproject.routing.cli; |
17 | - | ||
18 | -import java.util.Collection; | ||
19 | 17 | ||
20 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
21 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
... | @@ -24,8 +22,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode; | ... | @@ -24,8 +22,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode; |
24 | import org.apache.karaf.shell.commands.Command; | 22 | import org.apache.karaf.shell.commands.Command; |
25 | import org.apache.karaf.shell.commands.Option; | 23 | import org.apache.karaf.shell.commands.Option; |
26 | import org.onosproject.cli.AbstractShellCommand; | 24 | import org.onosproject.cli.AbstractShellCommand; |
27 | -import org.onosproject.sdnip.RouteEntry; | 25 | +import org.onosproject.routingapi.RouteEntry; |
28 | -import org.onosproject.sdnip.SdnIpService; | 26 | +import org.onosproject.routingapi.RoutingService; |
27 | + | ||
28 | +import java.util.Collection; | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Command to show the list of routes in SDN-IP's routing table. | 31 | * Command to show the list of routes in SDN-IP's routing table. |
... | @@ -49,7 +49,7 @@ public class RoutesListCommand extends AbstractShellCommand { | ... | @@ -49,7 +49,7 @@ public class RoutesListCommand extends AbstractShellCommand { |
49 | 49 | ||
50 | @Override | 50 | @Override |
51 | protected void execute() { | 51 | protected void execute() { |
52 | - SdnIpService service = get(SdnIpService.class); | 52 | + RoutingService service = AbstractShellCommand.get(RoutingService.class); |
53 | 53 | ||
54 | // Print summary of the routes | 54 | // Print summary of the routes |
55 | if (routesSummary) { | 55 | if (routesSummary) { | ... | ... |
1 | +<!-- | ||
2 | + ~ Copyright 2015 Open Networking Laboratory | ||
3 | + ~ | ||
4 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + ~ you may not use this file except in compliance with the License. | ||
6 | + ~ You may obtain a copy of the License at | ||
7 | + ~ | ||
8 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + ~ | ||
10 | + ~ Unless required by applicable law or agreed to in writing, software | ||
11 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + ~ See the License for the specific language governing permissions and | ||
14 | + ~ limitations under the License. | ||
15 | + --> | ||
16 | +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> | ||
17 | + | ||
18 | + <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> | ||
19 | + <command> | ||
20 | + <action class="org.onosproject.routing.cli.BgpNeighborsListCommand"/> | ||
21 | + </command> | ||
22 | + <command> | ||
23 | + <action class="org.onosproject.routing.cli.BgpRoutesListCommand"/> | ||
24 | + </command> | ||
25 | + <command> | ||
26 | + <action class="org.onosproject.routing.cli.RoutesListCommand"/> | ||
27 | + </command> | ||
28 | + </command-bundle> | ||
29 | +</blueprint> |
1 | +/* | ||
2 | + * Copyright 2014 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.routing; | ||
17 | + | ||
18 | +import com.google.common.collect.Sets; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onlab.packet.Ip4Address; | ||
23 | +import org.onlab.packet.Ip4Prefix; | ||
24 | +import org.onlab.packet.IpAddress; | ||
25 | +import org.onlab.packet.IpPrefix; | ||
26 | +import org.onlab.packet.MacAddress; | ||
27 | +import org.onlab.packet.VlanId; | ||
28 | +import org.onosproject.net.ConnectPoint; | ||
29 | +import org.onosproject.net.DefaultHost; | ||
30 | +import org.onosproject.net.DeviceId; | ||
31 | +import org.onosproject.net.Host; | ||
32 | +import org.onosproject.net.HostId; | ||
33 | +import org.onosproject.net.HostLocation; | ||
34 | +import org.onosproject.net.PortNumber; | ||
35 | +import org.onosproject.net.host.HostEvent; | ||
36 | +import org.onosproject.net.host.HostListener; | ||
37 | +import org.onosproject.net.host.HostService; | ||
38 | +import org.onosproject.net.provider.ProviderId; | ||
39 | +import org.onosproject.routing.Router.InternalHostListener; | ||
40 | +import org.onosproject.routingapi.BgpService; | ||
41 | +import org.onosproject.routingapi.FibEntry; | ||
42 | +import org.onosproject.routingapi.FibListener; | ||
43 | +import org.onosproject.routingapi.FibUpdate; | ||
44 | +import org.onosproject.routingapi.RouteEntry; | ||
45 | +import org.onosproject.routingapi.RouteListener; | ||
46 | +import org.onosproject.routingapi.RouteUpdate; | ||
47 | + | ||
48 | +import java.util.Collections; | ||
49 | + | ||
50 | +import static org.easymock.EasyMock.*; | ||
51 | + | ||
52 | +/** | ||
53 | +* This class tests adding a route and updating a route. | ||
54 | +* The HostService module answers the MAC address asynchronously. | ||
55 | +*/ | ||
56 | +public class RouterAsyncArpTest { | ||
57 | + | ||
58 | + private HostService hostService; | ||
59 | + private FibListener fibListener; | ||
60 | + | ||
61 | + private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
62 | + DeviceId.deviceId("of:0000000000000001"), | ||
63 | + PortNumber.portNumber(1)); | ||
64 | + | ||
65 | + private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
66 | + DeviceId.deviceId("of:0000000000000002"), | ||
67 | + PortNumber.portNumber(1)); | ||
68 | + | ||
69 | + private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
70 | + DeviceId.deviceId("of:0000000000000003"), | ||
71 | + PortNumber.portNumber(1)); | ||
72 | + | ||
73 | + private Router router; | ||
74 | + private InternalHostListener internalHostListener; | ||
75 | + | ||
76 | + @Before | ||
77 | + public void setUp() throws Exception { | ||
78 | + hostService = createMock(HostService.class); | ||
79 | + | ||
80 | + BgpService bgpService = createMock(BgpService.class); | ||
81 | + bgpService.start(anyObject(RouteListener.class), anyInt()); | ||
82 | + bgpService.stop(); | ||
83 | + replay(bgpService); | ||
84 | + | ||
85 | + fibListener = createMock(FibListener.class); | ||
86 | + | ||
87 | + router = new Router(); | ||
88 | + router.hostService = hostService; | ||
89 | + router.bgpService = bgpService; | ||
90 | + router.activate(); | ||
91 | + | ||
92 | + router.start(fibListener); | ||
93 | + | ||
94 | + internalHostListener = router.new InternalHostListener(); | ||
95 | + } | ||
96 | + | ||
97 | + @After | ||
98 | + public void tearDown() { | ||
99 | + // Called during shutdown | ||
100 | + reset(hostService); | ||
101 | + hostService.removeListener(anyObject(HostListener.class)); | ||
102 | + | ||
103 | + router.stop(); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Tests adding a route entry with asynchronous HostService replies. | ||
108 | + */ | ||
109 | + @Test | ||
110 | + public void testRouteAdd() { | ||
111 | + // Construct a route entry | ||
112 | + IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
113 | + IpAddress nextHopIp = Ip4Address.valueOf("192.168.10.1"); | ||
114 | + | ||
115 | + RouteEntry routeEntry = new RouteEntry(prefix, nextHopIp); | ||
116 | + | ||
117 | + // Host service will reply with no hosts when asked | ||
118 | + reset(hostService); | ||
119 | + expect(hostService.getHostsByIp(anyObject(IpAddress.class))).andReturn( | ||
120 | + Collections.emptySet()).anyTimes(); | ||
121 | + hostService.startMonitoringIp(IpAddress.valueOf("192.168.10.1")); | ||
122 | + replay(hostService); | ||
123 | + | ||
124 | + | ||
125 | + // Initially when we add the route, no FIB update will be sent | ||
126 | + replay(fibListener); | ||
127 | + | ||
128 | + router.processRouteUpdates(Collections.singletonList( | ||
129 | + new RouteUpdate(RouteUpdate.Type.UPDATE, routeEntry))); | ||
130 | + | ||
131 | + verify(fibListener); | ||
132 | + | ||
133 | + | ||
134 | + // Now when we send the event, we expect the FIB update to be sent | ||
135 | + reset(fibListener); | ||
136 | + FibEntry fibEntry = new FibEntry(prefix, nextHopIp, | ||
137 | + MacAddress.valueOf("00:00:00:00:00:01")); | ||
138 | + | ||
139 | + fibListener.update(Collections.singletonList(new FibUpdate( | ||
140 | + FibUpdate.Type.UPDATE, fibEntry)), Collections.emptyList()); | ||
141 | + replay(fibListener); | ||
142 | + | ||
143 | + Host host = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
144 | + MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE, | ||
145 | + new HostLocation( | ||
146 | + SW1_ETH1.deviceId(), | ||
147 | + SW1_ETH1.port(), 1), | ||
148 | + Sets.newHashSet(IpAddress.valueOf("192.168.10.1"))); | ||
149 | + | ||
150 | + // Send in the host event | ||
151 | + internalHostListener.event( | ||
152 | + new HostEvent(HostEvent.Type.HOST_ADDED, host)); | ||
153 | + | ||
154 | + verify(fibListener); | ||
155 | + } | ||
156 | + | ||
157 | + /** | ||
158 | + * Tests updating a route entry with asynchronous HostService replies. | ||
159 | + */ | ||
160 | + @Test | ||
161 | + public void testRouteUpdate() { | ||
162 | + // Add a route | ||
163 | + testRouteAdd(); | ||
164 | + | ||
165 | + // Construct a route entry | ||
166 | + IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
167 | + IpAddress nextHopIp = Ip4Address.valueOf("192.168.20.1"); | ||
168 | + | ||
169 | + RouteEntry routeEntry = new RouteEntry(prefix, nextHopIp); | ||
170 | + | ||
171 | + // Host service will reply with no hosts when asked | ||
172 | + reset(hostService); | ||
173 | + expect(hostService.getHostsByIp(anyObject(IpAddress.class))).andReturn( | ||
174 | + Collections.emptySet()).anyTimes(); | ||
175 | + hostService.startMonitoringIp(IpAddress.valueOf("192.168.20.1")); | ||
176 | + replay(hostService); | ||
177 | + | ||
178 | + | ||
179 | + // Initially when we add the route, the DELETE FIB update will be sent | ||
180 | + // but the UPDATE FIB update will come later when the MAC is resolved | ||
181 | + reset(fibListener); | ||
182 | + | ||
183 | + fibListener.update(Collections.emptyList(), Collections.singletonList(new FibUpdate( | ||
184 | + FibUpdate.Type.DELETE, new FibEntry(prefix, null, null)))); | ||
185 | + replay(fibListener); | ||
186 | + | ||
187 | + router.processRouteUpdates(Collections.singletonList( | ||
188 | + new RouteUpdate(RouteUpdate.Type.UPDATE, routeEntry))); | ||
189 | + | ||
190 | + verify(fibListener); | ||
191 | + | ||
192 | + | ||
193 | + // Now when we send the event, we expect the FIB update to be sent | ||
194 | + reset(fibListener); | ||
195 | + FibEntry fibEntry = new FibEntry(prefix, nextHopIp, | ||
196 | + MacAddress.valueOf("00:00:00:00:00:02")); | ||
197 | + | ||
198 | + fibListener.update(Collections.singletonList(new FibUpdate( | ||
199 | + FibUpdate.Type.UPDATE, fibEntry)), Collections.emptyList()); | ||
200 | + replay(fibListener); | ||
201 | + | ||
202 | + Host host = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
203 | + MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE, | ||
204 | + new HostLocation( | ||
205 | + SW1_ETH1.deviceId(), | ||
206 | + SW1_ETH1.port(), 1), | ||
207 | + Sets.newHashSet(IpAddress.valueOf("192.168.20.1"))); | ||
208 | + | ||
209 | + // Send in the host event | ||
210 | + internalHostListener.event( | ||
211 | + new HostEvent(HostEvent.Type.HOST_ADDED, host)); | ||
212 | + | ||
213 | + verify(fibListener); | ||
214 | + } | ||
215 | +} |
1 | +/* | ||
2 | + * Copyright 2014 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.routing; | ||
17 | + | ||
18 | +import com.google.common.collect.Sets; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onlab.packet.Ip4Address; | ||
23 | +import org.onlab.packet.Ip4Prefix; | ||
24 | +import org.onlab.packet.IpAddress; | ||
25 | +import org.onlab.packet.IpPrefix; | ||
26 | +import org.onlab.packet.MacAddress; | ||
27 | +import org.onlab.packet.VlanId; | ||
28 | +import org.onosproject.net.ConnectPoint; | ||
29 | +import org.onosproject.net.DefaultHost; | ||
30 | +import org.onosproject.net.DeviceId; | ||
31 | +import org.onosproject.net.Host; | ||
32 | +import org.onosproject.net.HostId; | ||
33 | +import org.onosproject.net.HostLocation; | ||
34 | +import org.onosproject.net.PortNumber; | ||
35 | +import org.onosproject.net.host.HostListener; | ||
36 | +import org.onosproject.net.host.HostService; | ||
37 | +import org.onosproject.net.provider.ProviderId; | ||
38 | +import org.onosproject.routingapi.BgpService; | ||
39 | +import org.onosproject.routingapi.FibEntry; | ||
40 | +import org.onosproject.routingapi.FibListener; | ||
41 | +import org.onosproject.routingapi.FibUpdate; | ||
42 | +import org.onosproject.routingapi.RouteEntry; | ||
43 | +import org.onosproject.routingapi.RouteListener; | ||
44 | +import org.onosproject.routingapi.RouteUpdate; | ||
45 | + | ||
46 | +import java.util.Collections; | ||
47 | + | ||
48 | +import static org.easymock.EasyMock.*; | ||
49 | +import static org.junit.Assert.assertEquals; | ||
50 | +import static org.junit.Assert.assertTrue; | ||
51 | + | ||
52 | +/** | ||
53 | + * This class tests adding a route, updating a route, deleting a route, | ||
54 | + * and adding a route whose next hop is the local BGP speaker. | ||
55 | + * <p/> | ||
56 | + * The HostService answers requests synchronously. | ||
57 | + */ | ||
58 | +public class RouterTest { | ||
59 | + | ||
60 | + private HostService hostService; | ||
61 | + | ||
62 | + private FibListener fibListener; | ||
63 | + | ||
64 | + private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
65 | + DeviceId.deviceId("of:0000000000000001"), | ||
66 | + PortNumber.portNumber(1)); | ||
67 | + | ||
68 | + private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
69 | + DeviceId.deviceId("of:0000000000000002"), | ||
70 | + PortNumber.portNumber(1)); | ||
71 | + | ||
72 | + private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
73 | + DeviceId.deviceId("of:0000000000000003"), | ||
74 | + PortNumber.portNumber(1)); | ||
75 | + | ||
76 | + private static final ConnectPoint SW4_ETH1 = new ConnectPoint( | ||
77 | + DeviceId.deviceId("of:0000000000000004"), | ||
78 | + PortNumber.portNumber(1)); | ||
79 | + | ||
80 | + private Router router; | ||
81 | + | ||
82 | + @Before | ||
83 | + public void setUp() throws Exception { | ||
84 | + setUpHostService(); | ||
85 | + | ||
86 | + BgpService bgpService = createMock(BgpService.class); | ||
87 | + bgpService.start(anyObject(RouteListener.class), anyInt()); | ||
88 | + bgpService.stop(); | ||
89 | + replay(bgpService); | ||
90 | + | ||
91 | + fibListener = createMock(FibListener.class); | ||
92 | + | ||
93 | + router = new Router(); | ||
94 | + router.hostService = hostService; | ||
95 | + router.bgpService = bgpService; | ||
96 | + router.activate(); | ||
97 | + | ||
98 | + router.start(fibListener); | ||
99 | + } | ||
100 | + | ||
101 | + @After | ||
102 | + public void tearDown() { | ||
103 | + router.stop(); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Sets up the host service with details of some hosts. | ||
108 | + */ | ||
109 | + private void setUpHostService() { | ||
110 | + hostService = createMock(HostService.class); | ||
111 | + | ||
112 | + hostService.addListener(anyObject(HostListener.class)); | ||
113 | + expectLastCall().anyTimes(); | ||
114 | + | ||
115 | + IpAddress host1Address = IpAddress.valueOf("192.168.10.1"); | ||
116 | + Host host1 = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
117 | + MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE, | ||
118 | + new HostLocation(SW1_ETH1, 1), | ||
119 | + Sets.newHashSet(host1Address)); | ||
120 | + | ||
121 | + expect(hostService.getHostsByIp(host1Address)) | ||
122 | + .andReturn(Sets.newHashSet(host1)).anyTimes(); | ||
123 | + hostService.startMonitoringIp(host1Address); | ||
124 | + expectLastCall().anyTimes(); | ||
125 | + | ||
126 | + | ||
127 | + IpAddress host2Address = IpAddress.valueOf("192.168.20.1"); | ||
128 | + Host host2 = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
129 | + MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE, | ||
130 | + new HostLocation(SW2_ETH1, 1), | ||
131 | + Sets.newHashSet(host2Address)); | ||
132 | + | ||
133 | + expect(hostService.getHostsByIp(host2Address)) | ||
134 | + .andReturn(Sets.newHashSet(host2)).anyTimes(); | ||
135 | + hostService.startMonitoringIp(host2Address); | ||
136 | + expectLastCall().anyTimes(); | ||
137 | + | ||
138 | + // Next hop on a VLAN | ||
139 | + IpAddress host3Address = IpAddress.valueOf("192.168.40.1"); | ||
140 | + Host host3 = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
141 | + MacAddress.valueOf("00:00:00:00:00:03"), VlanId.vlanId((short) 1), | ||
142 | + new HostLocation(SW4_ETH1, 1), | ||
143 | + Sets.newHashSet(host3Address)); | ||
144 | + | ||
145 | + expect(hostService.getHostsByIp(host3Address)) | ||
146 | + .andReturn(Sets.newHashSet(host3)).anyTimes(); | ||
147 | + hostService.startMonitoringIp(host3Address); | ||
148 | + expectLastCall().anyTimes(); | ||
149 | + | ||
150 | + // Called during shutdown | ||
151 | + hostService.removeListener(anyObject(HostListener.class)); | ||
152 | + | ||
153 | + replay(hostService); | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * Tests adding a route entry. | ||
158 | + */ | ||
159 | + @Test | ||
160 | + public void testRouteAdd() { | ||
161 | + // Construct a route entry | ||
162 | + IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
163 | + IpAddress nextHopIp = Ip4Address.valueOf("192.168.10.1"); | ||
164 | + | ||
165 | + RouteEntry routeEntry = new RouteEntry(prefix, nextHopIp); | ||
166 | + | ||
167 | + // Expected FIB entry | ||
168 | + FibEntry fibEntry = new FibEntry(prefix, nextHopIp, | ||
169 | + MacAddress.valueOf("00:00:00:00:00:01")); | ||
170 | + | ||
171 | + fibListener.update(Collections.singletonList(new FibUpdate( | ||
172 | + FibUpdate.Type.UPDATE, fibEntry)), Collections.emptyList()); | ||
173 | + | ||
174 | + replay(fibListener); | ||
175 | + | ||
176 | + router.processRouteUpdates(Collections.singletonList( | ||
177 | + new RouteUpdate(RouteUpdate.Type.UPDATE, routeEntry))); | ||
178 | + | ||
179 | + verify(fibListener); | ||
180 | + } | ||
181 | + | ||
182 | + /** | ||
183 | + * Tests updating a route entry. | ||
184 | + */ | ||
185 | + @Test | ||
186 | + public void testRouteUpdate() { | ||
187 | + // Firstly add a route | ||
188 | + testRouteAdd(); | ||
189 | + | ||
190 | + // Route entry with updated next hop for the original prefix | ||
191 | + RouteEntry routeEntryUpdate = new RouteEntry( | ||
192 | + Ip4Prefix.valueOf("1.1.1.0/24"), | ||
193 | + Ip4Address.valueOf("192.168.20.1")); | ||
194 | + | ||
195 | + // The old FIB entry will be withdrawn | ||
196 | + FibEntry withdrawFibEntry = new FibEntry( | ||
197 | + Ip4Prefix.valueOf("1.1.1.0/24"), null, null); | ||
198 | + | ||
199 | + // A new FIB entry will be added | ||
200 | + FibEntry updateFibEntry = new FibEntry( | ||
201 | + Ip4Prefix.valueOf("1.1.1.0/24"), | ||
202 | + Ip4Address.valueOf("192.168.20.1"), | ||
203 | + MacAddress.valueOf("00:00:00:00:00:02")); | ||
204 | + | ||
205 | + reset(fibListener); | ||
206 | + fibListener.update(Collections.singletonList(new FibUpdate( | ||
207 | + FibUpdate.Type.UPDATE, updateFibEntry)), | ||
208 | + Collections.singletonList(new FibUpdate( | ||
209 | + FibUpdate.Type.DELETE, withdrawFibEntry))); | ||
210 | + | ||
211 | + replay(fibListener); | ||
212 | + | ||
213 | + router.processRouteUpdates(Collections.singletonList(new RouteUpdate( | ||
214 | + RouteUpdate.Type.UPDATE, routeEntryUpdate))); | ||
215 | + | ||
216 | + verify(fibListener); | ||
217 | + } | ||
218 | + | ||
219 | + /** | ||
220 | + * Tests deleting a route entry. | ||
221 | + */ | ||
222 | + @Test | ||
223 | + public void testRouteDelete() { | ||
224 | + // Firstly add a route | ||
225 | + testRouteAdd(); | ||
226 | + | ||
227 | + RouteEntry deleteRouteEntry = new RouteEntry( | ||
228 | + Ip4Prefix.valueOf("1.1.1.0/24"), | ||
229 | + Ip4Address.valueOf("192.168.10.1")); | ||
230 | + | ||
231 | + FibEntry deleteFibEntry = new FibEntry( | ||
232 | + Ip4Prefix.valueOf("1.1.1.0/24"), null, null); | ||
233 | + | ||
234 | + reset(fibListener); | ||
235 | + fibListener.update(Collections.emptyList(), Collections.singletonList( | ||
236 | + new FibUpdate(FibUpdate.Type.DELETE, deleteFibEntry))); | ||
237 | + | ||
238 | + replay(fibListener); | ||
239 | + | ||
240 | + router.processRouteUpdates(Collections.singletonList( | ||
241 | + new RouteUpdate(RouteUpdate.Type.DELETE, deleteRouteEntry))); | ||
242 | + | ||
243 | + verify(fibListener); | ||
244 | + } | ||
245 | + | ||
246 | + /** | ||
247 | + * Tests adding a route whose next hop is the local BGP speaker. | ||
248 | + */ | ||
249 | + @Test | ||
250 | + public void testLocalRouteAdd() { | ||
251 | + // Construct a route entry, the next hop is the local BGP speaker | ||
252 | + RouteEntry routeEntry = new RouteEntry( | ||
253 | + Ip4Prefix.valueOf("1.1.1.0/24"), | ||
254 | + Ip4Address.valueOf("0.0.0.0")); | ||
255 | + | ||
256 | + // No methods on the FIB listener should be called | ||
257 | + replay(fibListener); | ||
258 | + | ||
259 | + // Call the processRouteUpdates() method in Router class | ||
260 | + RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE, | ||
261 | + routeEntry); | ||
262 | + router.processRouteUpdates(Collections.singletonList(routeUpdate)); | ||
263 | + | ||
264 | + // Verify | ||
265 | + assertEquals(1, router.getRoutes4().size()); | ||
266 | + assertTrue(router.getRoutes4().contains(routeEntry)); | ||
267 | + verify(fibListener); | ||
268 | + } | ||
269 | +} |
... | @@ -13,15 +13,16 @@ | ... | @@ -13,15 +13,16 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | 17 | ||
18 | -import static org.hamcrest.Matchers.is; | 18 | +import org.hamcrest.Matchers; |
19 | -import static org.hamcrest.Matchers.not; | 19 | +import org.junit.Test; |
20 | -import static org.junit.Assert.assertThat; | ||
21 | 20 | ||
22 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
23 | 22 | ||
24 | -import org.junit.Test; | 23 | +import static org.hamcrest.Matchers.is; |
24 | +import static org.hamcrest.Matchers.not; | ||
25 | +import static org.junit.Assert.assertThat; | ||
25 | 26 | ||
26 | /** | 27 | /** |
27 | * Unit tests for the BgpRouteEntry.AsPath class. | 28 | * Unit tests for the BgpRouteEntry.AsPath class. |
... | @@ -211,7 +212,7 @@ public class AsPathTest { | ... | @@ -211,7 +212,7 @@ public class AsPathTest { |
211 | // | 212 | // |
212 | BgpRouteEntry.AsPath asPath2 = new BgpRouteEntry.AsPath(pathSegments); | 213 | BgpRouteEntry.AsPath asPath2 = new BgpRouteEntry.AsPath(pathSegments); |
213 | 214 | ||
214 | - assertThat(asPath1, is(not(asPath2))); | 215 | + assertThat(asPath1, Matchers.is(not(asPath2))); |
215 | } | 216 | } |
216 | 217 | ||
217 | /** | 218 | /** | ... | ... |
... | @@ -13,22 +13,21 @@ | ... | @@ -13,22 +13,21 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | - | ||
18 | -import static org.easymock.EasyMock.createMock; | ||
19 | -import static org.easymock.EasyMock.expect; | ||
20 | -import static org.easymock.EasyMock.replay; | ||
21 | -import static org.hamcrest.Matchers.is; | ||
22 | -import static org.hamcrest.Matchers.not; | ||
23 | -import static org.junit.Assert.assertThat; | ||
24 | - | ||
25 | -import java.util.ArrayList; | ||
26 | 17 | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.hamcrest.Matchers; | ||
27 | import org.junit.Before; | 20 | import org.junit.Before; |
28 | import org.junit.Test; | 21 | import org.junit.Test; |
29 | import org.onlab.packet.Ip4Address; | 22 | import org.onlab.packet.Ip4Address; |
30 | import org.onlab.packet.Ip4Prefix; | 23 | import org.onlab.packet.Ip4Prefix; |
31 | 24 | ||
25 | +import java.util.ArrayList; | ||
26 | + | ||
27 | +import static org.hamcrest.Matchers.is; | ||
28 | +import static org.hamcrest.Matchers.not; | ||
29 | +import static org.junit.Assert.assertThat; | ||
30 | + | ||
32 | /** | 31 | /** |
33 | * Unit tests for the BgpRouteEntry class. | 32 | * Unit tests for the BgpRouteEntry class. |
34 | */ | 33 | */ |
... | @@ -63,9 +62,9 @@ public class BgpRouteEntryTest { | ... | @@ -63,9 +62,9 @@ public class BgpRouteEntryTest { |
63 | @Before | 62 | @Before |
64 | public void setUp() throws Exception { | 63 | public void setUp() throws Exception { |
65 | // Mock objects for testing | 64 | // Mock objects for testing |
66 | - bgpSession = createMock(BgpSession.class); | 65 | + bgpSession = EasyMock.createMock(BgpSession.class); |
67 | - bgpSession2 = createMock(BgpSession.class); | 66 | + bgpSession2 = EasyMock.createMock(BgpSession.class); |
68 | - bgpSession3 = createMock(BgpSession.class); | 67 | + bgpSession3 = EasyMock.createMock(BgpSession.class); |
69 | 68 | ||
70 | // Setup the BGP Sessions | 69 | // Setup the BGP Sessions |
71 | remoteInfo.setIp4Address(BGP_SESSION_IP_ADDRESS); | 70 | remoteInfo.setIp4Address(BGP_SESSION_IP_ADDRESS); |
... | @@ -75,16 +74,16 @@ public class BgpRouteEntryTest { | ... | @@ -75,16 +74,16 @@ public class BgpRouteEntryTest { |
75 | remoteInfo2.setBgpId(BGP_SESSION_BGP_ID2); | 74 | remoteInfo2.setBgpId(BGP_SESSION_BGP_ID2); |
76 | remoteInfo3.setBgpId(BGP_SESSION_BGP_ID3); | 75 | remoteInfo3.setBgpId(BGP_SESSION_BGP_ID3); |
77 | 76 | ||
78 | - expect(bgpSession.localInfo()).andReturn(localInfo).anyTimes(); | 77 | + EasyMock.expect(bgpSession.localInfo()).andReturn(localInfo).anyTimes(); |
79 | - expect(bgpSession.remoteInfo()).andReturn(remoteInfo).anyTimes(); | 78 | + EasyMock.expect(bgpSession.remoteInfo()).andReturn(remoteInfo).anyTimes(); |
80 | - expect(bgpSession2.localInfo()).andReturn(localInfo2).anyTimes(); | 79 | + EasyMock.expect(bgpSession2.localInfo()).andReturn(localInfo2).anyTimes(); |
81 | - expect(bgpSession2.remoteInfo()).andReturn(remoteInfo2).anyTimes(); | 80 | + EasyMock.expect(bgpSession2.remoteInfo()).andReturn(remoteInfo2).anyTimes(); |
82 | - expect(bgpSession3.localInfo()).andReturn(localInfo3).anyTimes(); | 81 | + EasyMock.expect(bgpSession3.localInfo()).andReturn(localInfo3).anyTimes(); |
83 | - expect(bgpSession3.remoteInfo()).andReturn(remoteInfo3).anyTimes(); | 82 | + EasyMock.expect(bgpSession3.remoteInfo()).andReturn(remoteInfo3).anyTimes(); |
84 | 83 | ||
85 | - replay(bgpSession); | 84 | + EasyMock.replay(bgpSession); |
86 | - replay(bgpSession2); | 85 | + EasyMock.replay(bgpSession2); |
87 | - replay(bgpSession3); | 86 | + EasyMock.replay(bgpSession3); |
88 | } | 87 | } |
89 | 88 | ||
90 | /** | 89 | /** |
... | @@ -500,7 +499,7 @@ public class BgpRouteEntryTest { | ... | @@ -500,7 +499,7 @@ public class BgpRouteEntryTest { |
500 | localPref); | 499 | localPref); |
501 | bgpRouteEntry2.setMultiExitDisc(multiExitDisc); | 500 | bgpRouteEntry2.setMultiExitDisc(multiExitDisc); |
502 | 501 | ||
503 | - assertThat(bgpRouteEntry1, is(not(bgpRouteEntry2))); | 502 | + assertThat(bgpRouteEntry1, Matchers.is(not(bgpRouteEntry2))); |
504 | } | 503 | } |
505 | 504 | ||
506 | /** | 505 | /** | ... | ... |
... | @@ -13,22 +13,9 @@ | ... | @@ -13,22 +13,9 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | - | ||
18 | -import static org.hamcrest.Matchers.hasSize; | ||
19 | -import static org.hamcrest.Matchers.is; | ||
20 | -import static org.hamcrest.Matchers.notNullValue; | ||
21 | -import static org.junit.Assert.assertThat; | ||
22 | - | ||
23 | -import java.net.InetAddress; | ||
24 | -import java.net.InetSocketAddress; | ||
25 | -import java.net.SocketAddress; | ||
26 | -import java.util.ArrayList; | ||
27 | -import java.util.Collection; | ||
28 | -import java.util.LinkedList; | ||
29 | -import java.util.concurrent.Executors; | ||
30 | -import java.util.concurrent.TimeUnit; | ||
31 | 17 | ||
18 | +import com.google.common.net.InetAddresses; | ||
32 | import org.hamcrest.Description; | 19 | import org.hamcrest.Description; |
33 | import org.hamcrest.TypeSafeMatcher; | 20 | import org.hamcrest.TypeSafeMatcher; |
34 | import org.jboss.netty.bootstrap.ClientBootstrap; | 21 | import org.jboss.netty.bootstrap.ClientBootstrap; |
... | @@ -44,12 +31,24 @@ import org.junit.Before; | ... | @@ -44,12 +31,24 @@ import org.junit.Before; |
44 | import org.junit.Test; | 31 | import org.junit.Test; |
45 | import org.onlab.junit.TestUtils; | 32 | import org.onlab.junit.TestUtils; |
46 | import org.onlab.junit.TestUtils.TestUtilsException; | 33 | import org.onlab.junit.TestUtils.TestUtilsException; |
47 | -import org.onosproject.sdnip.RouteListener; | ||
48 | -import org.onosproject.sdnip.RouteUpdate; | ||
49 | import org.onlab.packet.Ip4Address; | 34 | import org.onlab.packet.Ip4Address; |
50 | import org.onlab.packet.Ip4Prefix; | 35 | import org.onlab.packet.Ip4Prefix; |
36 | +import org.onosproject.routingapi.RouteListener; | ||
37 | +import org.onosproject.routingapi.RouteUpdate; | ||
51 | 38 | ||
52 | -import com.google.common.net.InetAddresses; | 39 | +import java.net.InetAddress; |
40 | +import java.net.InetSocketAddress; | ||
41 | +import java.net.SocketAddress; | ||
42 | +import java.util.ArrayList; | ||
43 | +import java.util.Collection; | ||
44 | +import java.util.LinkedList; | ||
45 | +import java.util.concurrent.Executors; | ||
46 | +import java.util.concurrent.TimeUnit; | ||
47 | + | ||
48 | +import static org.hamcrest.Matchers.hasSize; | ||
49 | +import static org.hamcrest.Matchers.is; | ||
50 | +import static org.hamcrest.Matchers.notNullValue; | ||
51 | +import static org.junit.Assert.assertThat; | ||
53 | 52 | ||
54 | /** | 53 | /** |
55 | * Unit tests for the BgpSessionManager class. | 54 | * Unit tests for the BgpSessionManager class. |
... | @@ -251,9 +250,9 @@ public class BgpSessionManagerTest { | ... | @@ -251,9 +250,9 @@ public class BgpSessionManagerTest { |
251 | // Setup the BGP Session Manager to test, and start listening for BGP | 250 | // Setup the BGP Session Manager to test, and start listening for BGP |
252 | // connections. | 251 | // connections. |
253 | // | 252 | // |
254 | - bgpSessionManager = new BgpSessionManager(dummyRouteListener); | 253 | + bgpSessionManager = new BgpSessionManager(); |
255 | // NOTE: We use port 0 to bind on any available port | 254 | // NOTE: We use port 0 to bind on any available port |
256 | - bgpSessionManager.start(0); | 255 | + bgpSessionManager.start(dummyRouteListener, 0); |
257 | 256 | ||
258 | // Get the port number the BGP Session Manager is listening on | 257 | // Get the port number the BGP Session Manager is listening on |
259 | Channel serverChannel = TestUtils.getField(bgpSessionManager, | 258 | Channel serverChannel = TestUtils.getField(bgpSessionManager, | ... | ... |
... | @@ -13,15 +13,16 @@ | ... | @@ -13,15 +13,16 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | 17 | ||
18 | -import static org.hamcrest.Matchers.is; | 18 | +import org.hamcrest.Matchers; |
19 | -import static org.hamcrest.Matchers.not; | 19 | +import org.junit.Test; |
20 | -import static org.junit.Assert.assertThat; | ||
21 | 20 | ||
22 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
23 | 22 | ||
24 | -import org.junit.Test; | 23 | +import static org.hamcrest.Matchers.is; |
24 | +import static org.hamcrest.Matchers.not; | ||
25 | +import static org.junit.Assert.assertThat; | ||
25 | 26 | ||
26 | /** | 27 | /** |
27 | * Unit tests for the BgpRouteEntry.PathSegment class. | 28 | * Unit tests for the BgpRouteEntry.PathSegment class. |
... | @@ -113,7 +114,7 @@ public class PathSegmentTest { | ... | @@ -113,7 +114,7 @@ public class PathSegmentTest { |
113 | BgpRouteEntry.PathSegment pathSegment2 = | 114 | BgpRouteEntry.PathSegment pathSegment2 = |
114 | new BgpRouteEntry.PathSegment(pathSegmentType, segmentAsNumbers); | 115 | new BgpRouteEntry.PathSegment(pathSegmentType, segmentAsNumbers); |
115 | 116 | ||
116 | - assertThat(pathSegment1, is(not(pathSegment2))); | 117 | + assertThat(pathSegment1, Matchers.is(not(pathSegment2))); |
117 | } | 118 | } |
118 | 119 | ||
119 | /** | 120 | /** | ... | ... |
... | @@ -13,9 +13,7 @@ | ... | @@ -13,9 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | - | ||
18 | -import java.util.Collection; | ||
19 | 17 | ||
20 | import org.jboss.netty.buffer.ChannelBuffer; | 18 | import org.jboss.netty.buffer.ChannelBuffer; |
21 | import org.jboss.netty.buffer.ChannelBuffers; | 19 | import org.jboss.netty.buffer.ChannelBuffers; |
... | @@ -25,6 +23,8 @@ import org.jboss.netty.channel.SimpleChannelHandler; | ... | @@ -25,6 +23,8 @@ import org.jboss.netty.channel.SimpleChannelHandler; |
25 | import org.onlab.packet.Ip4Address; | 23 | import org.onlab.packet.Ip4Address; |
26 | import org.onlab.packet.Ip4Prefix; | 24 | import org.onlab.packet.Ip4Prefix; |
27 | 25 | ||
26 | +import java.util.Collection; | ||
27 | + | ||
28 | /** | 28 | /** |
29 | * Class for handling the remote BGP Peer session. | 29 | * Class for handling the remote BGP Peer session. |
30 | */ | 30 | */ | ... | ... |
... | @@ -13,9 +13,7 @@ | ... | @@ -13,9 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.sdnip.bgp; | 16 | +package org.onosproject.routing.bgp; |
17 | - | ||
18 | -import java.util.concurrent.CountDownLatch; | ||
19 | 17 | ||
20 | import org.jboss.netty.buffer.ChannelBuffer; | 18 | import org.jboss.netty.buffer.ChannelBuffer; |
21 | import org.jboss.netty.channel.Channel; | 19 | import org.jboss.netty.channel.Channel; |
... | @@ -23,6 +21,8 @@ import org.jboss.netty.channel.ChannelHandlerContext; | ... | @@ -23,6 +21,8 @@ import org.jboss.netty.channel.ChannelHandlerContext; |
23 | import org.jboss.netty.handler.codec.frame.FrameDecoder; | 21 | import org.jboss.netty.handler.codec.frame.FrameDecoder; |
24 | import org.onlab.packet.Ip4Address; | 22 | import org.onlab.packet.Ip4Address; |
25 | 23 | ||
24 | +import java.util.concurrent.CountDownLatch; | ||
25 | + | ||
26 | /** | 26 | /** |
27 | * Class for handling the decoding of the BGP messages at the remote | 27 | * Class for handling the decoding of the BGP messages at the remote |
28 | * BGP peer session. | 28 | * BGP peer session. | ... | ... |
... | @@ -61,11 +61,6 @@ | ... | @@ -61,11 +61,6 @@ |
61 | 61 | ||
62 | <dependency> | 62 | <dependency> |
63 | <groupId>org.onosproject</groupId> | 63 | <groupId>org.onosproject</groupId> |
64 | - <artifactId>onlab-thirdparty</artifactId> | ||
65 | - </dependency> | ||
66 | - | ||
67 | - <dependency> | ||
68 | - <groupId>org.onosproject</groupId> | ||
69 | <artifactId>onlab-misc</artifactId> | 64 | <artifactId>onlab-misc</artifactId> |
70 | </dependency> | 65 | </dependency> |
71 | 66 | ||
... | @@ -85,13 +80,13 @@ | ... | @@ -85,13 +80,13 @@ |
85 | 80 | ||
86 | <dependency> | 81 | <dependency> |
87 | <groupId>org.onosproject</groupId> | 82 | <groupId>org.onosproject</groupId> |
88 | - <artifactId>onos-cli</artifactId> | 83 | + <artifactId>onos-app-routing-api</artifactId> |
89 | <version>${project.version}</version> | 84 | <version>${project.version}</version> |
90 | </dependency> | 85 | </dependency> |
91 | 86 | ||
92 | <dependency> | 87 | <dependency> |
93 | <groupId>org.onosproject</groupId> | 88 | <groupId>org.onosproject</groupId> |
94 | - <artifactId>onos-core-dist</artifactId> | 89 | + <artifactId>onos-cli</artifactId> |
95 | <version>${project.version}</version> | 90 | <version>${project.version}</version> |
96 | </dependency> | 91 | </dependency> |
97 | 92 | ||
... | @@ -107,11 +102,6 @@ | ... | @@ -107,11 +102,6 @@ |
107 | </dependency> | 102 | </dependency> |
108 | 103 | ||
109 | <dependency> | 104 | <dependency> |
110 | - <groupId>org.osgi</groupId> | ||
111 | - <artifactId>org.osgi.core</artifactId> | ||
112 | - </dependency> | ||
113 | - | ||
114 | - <dependency> | ||
115 | <groupId>org.easymock</groupId> | 105 | <groupId>org.easymock</groupId> |
116 | <artifactId>easymock</artifactId> | 106 | <artifactId>easymock</artifactId> |
117 | <scope>test</scope> | 107 | <scope>test</scope> | ... | ... |
... | @@ -36,6 +36,8 @@ import org.onosproject.net.intent.IntentService; | ... | @@ -36,6 +36,8 @@ import org.onosproject.net.intent.IntentService; |
36 | import org.onosproject.net.intent.IntentState; | 36 | import org.onosproject.net.intent.IntentState; |
37 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; | 37 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
38 | import org.onosproject.net.intent.PointToPointIntent; | 38 | import org.onosproject.net.intent.PointToPointIntent; |
39 | +import org.onosproject.routingapi.FibListener; | ||
40 | +import org.onosproject.routingapi.FibUpdate; | ||
39 | import org.onosproject.sdnip.config.BgpPeer; | 41 | import org.onosproject.sdnip.config.BgpPeer; |
40 | import org.onosproject.sdnip.config.Interface; | 42 | import org.onosproject.sdnip.config.Interface; |
41 | import org.onosproject.sdnip.config.SdnIpConfigurationService; | 43 | import org.onosproject.sdnip.config.SdnIpConfigurationService; | ... | ... |
... | @@ -15,15 +15,11 @@ | ... | @@ -15,15 +15,11 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.sdnip; | 16 | package org.onosproject.sdnip; |
17 | 17 | ||
18 | -import java.util.ArrayList; | ||
19 | -import java.util.Collection; | ||
20 | -import java.util.List; | ||
21 | - | ||
22 | import org.onlab.packet.Ethernet; | 18 | import org.onlab.packet.Ethernet; |
23 | import org.onlab.packet.IPv4; | 19 | import org.onlab.packet.IPv4; |
24 | import org.onlab.packet.IPv6; | 20 | import org.onlab.packet.IPv6; |
25 | -import org.onlab.packet.IpAddress; | ||
26 | import org.onlab.packet.Ip4Address; | 21 | import org.onlab.packet.Ip4Address; |
22 | +import org.onlab.packet.IpAddress; | ||
27 | import org.onlab.packet.IpPrefix; | 23 | import org.onlab.packet.IpPrefix; |
28 | import org.onosproject.core.ApplicationId; | 24 | import org.onosproject.core.ApplicationId; |
29 | import org.onosproject.net.ConnectPoint; | 25 | import org.onosproject.net.ConnectPoint; |
... | @@ -32,7 +28,6 @@ import org.onosproject.net.flow.DefaultTrafficTreatment; | ... | @@ -32,7 +28,6 @@ import org.onosproject.net.flow.DefaultTrafficTreatment; |
32 | import org.onosproject.net.flow.TrafficSelector; | 28 | import org.onosproject.net.flow.TrafficSelector; |
33 | import org.onosproject.net.flow.TrafficTreatment; | 29 | import org.onosproject.net.flow.TrafficTreatment; |
34 | import org.onosproject.net.intent.PointToPointIntent; | 30 | import org.onosproject.net.intent.PointToPointIntent; |
35 | -import org.onosproject.sdnip.bgp.BgpConstants; | ||
36 | import org.onosproject.sdnip.config.BgpPeer; | 31 | import org.onosproject.sdnip.config.BgpPeer; |
37 | import org.onosproject.sdnip.config.BgpSpeaker; | 32 | import org.onosproject.sdnip.config.BgpSpeaker; |
38 | import org.onosproject.sdnip.config.Interface; | 33 | import org.onosproject.sdnip.config.Interface; |
... | @@ -41,6 +36,10 @@ import org.onosproject.sdnip.config.SdnIpConfigurationService; | ... | @@ -41,6 +36,10 @@ import org.onosproject.sdnip.config.SdnIpConfigurationService; |
41 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
42 | import org.slf4j.LoggerFactory; | 37 | import org.slf4j.LoggerFactory; |
43 | 38 | ||
39 | +import java.util.ArrayList; | ||
40 | +import java.util.Collection; | ||
41 | +import java.util.List; | ||
42 | + | ||
44 | /** | 43 | /** |
45 | * Manages the connectivity requirements between peers. | 44 | * Manages the connectivity requirements between peers. |
46 | */ | 45 | */ |
... | @@ -49,6 +48,8 @@ public class PeerConnectivityManager { | ... | @@ -49,6 +48,8 @@ public class PeerConnectivityManager { |
49 | private static final Logger log = LoggerFactory.getLogger( | 48 | private static final Logger log = LoggerFactory.getLogger( |
50 | PeerConnectivityManager.class); | 49 | PeerConnectivityManager.class); |
51 | 50 | ||
51 | + private static final short BGP_PORT = 179; | ||
52 | + | ||
52 | private final IntentSynchronizer intentSynchronizer; | 53 | private final IntentSynchronizer intentSynchronizer; |
53 | private final SdnIpConfigurationService configService; | 54 | private final SdnIpConfigurationService configService; |
54 | private final InterfaceService interfaceService; | 55 | private final InterfaceService interfaceService; |
... | @@ -191,7 +192,7 @@ public class PeerConnectivityManager { | ... | @@ -191,7 +192,7 @@ public class PeerConnectivityManager { |
191 | bgpdAddress, | 192 | bgpdAddress, |
192 | bgpdPeerAddress, | 193 | bgpdPeerAddress, |
193 | null, | 194 | null, |
194 | - (short) BgpConstants.BGP_PORT); | 195 | + BGP_PORT); |
195 | 196 | ||
196 | intents.add(new PointToPointIntent(appId, selector, treatment, | 197 | intents.add(new PointToPointIntent(appId, selector, treatment, |
197 | bgpdConnectPoint, bgpdPeerConnectPoint)); | 198 | bgpdConnectPoint, bgpdPeerConnectPoint)); |
... | @@ -200,7 +201,7 @@ public class PeerConnectivityManager { | ... | @@ -200,7 +201,7 @@ public class PeerConnectivityManager { |
200 | selector = buildSelector(tcpProtocol, | 201 | selector = buildSelector(tcpProtocol, |
201 | bgpdAddress, | 202 | bgpdAddress, |
202 | bgpdPeerAddress, | 203 | bgpdPeerAddress, |
203 | - (short) BgpConstants.BGP_PORT, | 204 | + BGP_PORT, |
204 | null); | 205 | null); |
205 | 206 | ||
206 | intents.add(new PointToPointIntent(appId, selector, treatment, | 207 | intents.add(new PointToPointIntent(appId, selector, treatment, |
... | @@ -211,7 +212,7 @@ public class PeerConnectivityManager { | ... | @@ -211,7 +212,7 @@ public class PeerConnectivityManager { |
211 | bgpdPeerAddress, | 212 | bgpdPeerAddress, |
212 | bgpdAddress, | 213 | bgpdAddress, |
213 | null, | 214 | null, |
214 | - (short) BgpConstants.BGP_PORT); | 215 | + BGP_PORT); |
215 | 216 | ||
216 | intents.add(new PointToPointIntent(appId, selector, treatment, | 217 | intents.add(new PointToPointIntent(appId, selector, treatment, |
217 | bgpdPeerConnectPoint, bgpdConnectPoint)); | 218 | bgpdPeerConnectPoint, bgpdConnectPoint)); |
... | @@ -220,7 +221,7 @@ public class PeerConnectivityManager { | ... | @@ -220,7 +221,7 @@ public class PeerConnectivityManager { |
220 | selector = buildSelector(tcpProtocol, | 221 | selector = buildSelector(tcpProtocol, |
221 | bgpdPeerAddress, | 222 | bgpdPeerAddress, |
222 | bgpdAddress, | 223 | bgpdAddress, |
223 | - (short) BgpConstants.BGP_PORT, | 224 | + BGP_PORT, |
224 | null); | 225 | null); |
225 | 226 | ||
226 | intents.add(new PointToPointIntent(appId, selector, treatment, | 227 | intents.add(new PointToPointIntent(appId, selector, treatment, | ... | ... |
... | @@ -32,14 +32,11 @@ import org.onosproject.core.ApplicationId; | ... | @@ -32,14 +32,11 @@ import org.onosproject.core.ApplicationId; |
32 | import org.onosproject.core.CoreService; | 32 | import org.onosproject.core.CoreService; |
33 | import org.onosproject.net.host.HostService; | 33 | import org.onosproject.net.host.HostService; |
34 | import org.onosproject.net.intent.IntentService; | 34 | import org.onosproject.net.intent.IntentService; |
35 | -import org.onosproject.sdnip.bgp.BgpRouteEntry; | 35 | +import org.onosproject.routingapi.RoutingService; |
36 | -import org.onosproject.sdnip.bgp.BgpSession; | ||
37 | -import org.onosproject.sdnip.bgp.BgpSessionManager; | ||
38 | import org.onosproject.sdnip.config.SdnIpConfigurationReader; | 36 | import org.onosproject.sdnip.config.SdnIpConfigurationReader; |
39 | import org.osgi.service.component.ComponentContext; | 37 | import org.osgi.service.component.ComponentContext; |
40 | import org.slf4j.Logger; | 38 | import org.slf4j.Logger; |
41 | 39 | ||
42 | -import java.util.Collection; | ||
43 | import java.util.Dictionary; | 40 | import java.util.Dictionary; |
44 | 41 | ||
45 | import static org.slf4j.LoggerFactory.getLogger; | 42 | import static org.slf4j.LoggerFactory.getLogger; |
... | @@ -69,8 +66,11 @@ public class SdnIp implements SdnIpService { | ... | @@ -69,8 +66,11 @@ public class SdnIp implements SdnIpService { |
69 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 66 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
70 | protected LeadershipService leadershipService; | 67 | protected LeadershipService leadershipService; |
71 | 68 | ||
69 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
70 | + protected RoutingService routingService; | ||
71 | + | ||
72 | // | 72 | // |
73 | - // NOTE: Unused reference - needed to guarentee that the | 73 | + // NOTE: Unused reference - needed to guarantee that the |
74 | // NetworkConfigReader component is activated and the network configuration | 74 | // NetworkConfigReader component is activated and the network configuration |
75 | // is read. | 75 | // is read. |
76 | // | 76 | // |
... | @@ -83,8 +83,7 @@ public class SdnIp implements SdnIpService { | ... | @@ -83,8 +83,7 @@ public class SdnIp implements SdnIpService { |
83 | private IntentSynchronizer intentSynchronizer; | 83 | private IntentSynchronizer intentSynchronizer; |
84 | private SdnIpConfigurationReader config; | 84 | private SdnIpConfigurationReader config; |
85 | private PeerConnectivityManager peerConnectivity; | 85 | private PeerConnectivityManager peerConnectivity; |
86 | - private Router router; | 86 | + |
87 | - private BgpSessionManager bgpSessionManager; | ||
88 | private LeadershipEventListener leadershipEventListener = | 87 | private LeadershipEventListener leadershipEventListener = |
89 | new InnerLeadershipEventListener(); | 88 | new InnerLeadershipEventListener(); |
90 | private ApplicationId appId; | 89 | private ApplicationId appId; |
... | @@ -114,23 +113,18 @@ public class SdnIp implements SdnIpService { | ... | @@ -114,23 +113,18 @@ public class SdnIp implements SdnIpService { |
114 | interfaceService); | 113 | interfaceService); |
115 | peerConnectivity.start(); | 114 | peerConnectivity.start(); |
116 | 115 | ||
117 | - router = new Router(intentSynchronizer, hostService); | 116 | + routingService.start(intentSynchronizer); |
118 | - router.start(); | ||
119 | 117 | ||
120 | leadershipService.addListener(leadershipEventListener); | 118 | leadershipService.addListener(leadershipEventListener); |
121 | leadershipService.runForLeadership(appId.name()); | 119 | leadershipService.runForLeadership(appId.name()); |
122 | 120 | ||
123 | log.info("Starting BGP with port {}", bgpPort); | 121 | log.info("Starting BGP with port {}", bgpPort); |
124 | - | 122 | + // TODO feed port information through to the BgpService |
125 | - bgpSessionManager = new BgpSessionManager(router); | ||
126 | - bgpSessionManager.start(bgpPort); | ||
127 | } | 123 | } |
128 | 124 | ||
129 | @Deactivate | 125 | @Deactivate |
130 | protected void deactivate() { | 126 | protected void deactivate() { |
131 | - | 127 | + routingService.stop(); |
132 | - bgpSessionManager.stop(); | ||
133 | - router.stop(); | ||
134 | peerConnectivity.stop(); | 128 | peerConnectivity.stop(); |
135 | intentSynchronizer.stop(); | 129 | intentSynchronizer.stop(); |
136 | 130 | ||
... | @@ -168,31 +162,6 @@ public class SdnIp implements SdnIpService { | ... | @@ -168,31 +162,6 @@ public class SdnIp implements SdnIpService { |
168 | } | 162 | } |
169 | 163 | ||
170 | @Override | 164 | @Override |
171 | - public Collection<BgpSession> getBgpSessions() { | ||
172 | - return bgpSessionManager.getBgpSessions(); | ||
173 | - } | ||
174 | - | ||
175 | - @Override | ||
176 | - public Collection<BgpRouteEntry> getBgpRoutes4() { | ||
177 | - return bgpSessionManager.getBgpRoutes4(); | ||
178 | - } | ||
179 | - | ||
180 | - @Override | ||
181 | - public Collection<BgpRouteEntry> getBgpRoutes6() { | ||
182 | - return bgpSessionManager.getBgpRoutes6(); | ||
183 | - } | ||
184 | - | ||
185 | - @Override | ||
186 | - public Collection<RouteEntry> getRoutes4() { | ||
187 | - return router.getRoutes4(); | ||
188 | - } | ||
189 | - | ||
190 | - @Override | ||
191 | - public Collection<RouteEntry> getRoutes6() { | ||
192 | - return router.getRoutes6(); | ||
193 | - } | ||
194 | - | ||
195 | - @Override | ||
196 | public void modifyPrimary(boolean isPrimary) { | 165 | public void modifyPrimary(boolean isPrimary) { |
197 | intentSynchronizer.leaderChanged(isPrimary); | 166 | intentSynchronizer.leaderChanged(isPrimary); |
198 | } | 167 | } | ... | ... |
... | @@ -15,49 +15,10 @@ | ... | @@ -15,49 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.sdnip; | 16 | package org.onosproject.sdnip; |
17 | 17 | ||
18 | -import java.util.Collection; | ||
19 | - | ||
20 | -import org.onosproject.sdnip.bgp.BgpRouteEntry; | ||
21 | -import org.onosproject.sdnip.bgp.BgpSession; | ||
22 | - | ||
23 | /** | 18 | /** |
24 | * Service interface exported by SDN-IP. | 19 | * Service interface exported by SDN-IP. |
25 | */ | 20 | */ |
26 | public interface SdnIpService { | 21 | public interface SdnIpService { |
27 | - /** | ||
28 | - * Gets the BGP sessions. | ||
29 | - * | ||
30 | - * @return the BGP sessions | ||
31 | - */ | ||
32 | - public Collection<BgpSession> getBgpSessions(); | ||
33 | - | ||
34 | - /** | ||
35 | - * Gets the selected IPv4 BGP routes among all BGP sessions. | ||
36 | - * | ||
37 | - * @return the selected IPv4 BGP routes among all BGP sessions | ||
38 | - */ | ||
39 | - public Collection<BgpRouteEntry> getBgpRoutes4(); | ||
40 | - | ||
41 | - /** | ||
42 | - * Gets the selected IPv6 BGP routes among all BGP sessions. | ||
43 | - * | ||
44 | - * @return the selected IPv6 BGP routes among all BGP sessions | ||
45 | - */ | ||
46 | - public Collection<BgpRouteEntry> getBgpRoutes6(); | ||
47 | - | ||
48 | - /** | ||
49 | - * Gets all IPv4 routes known to SDN-IP. | ||
50 | - * | ||
51 | - * @return the SDN-IP IPv4 routes | ||
52 | - */ | ||
53 | - public Collection<RouteEntry> getRoutes4(); | ||
54 | - | ||
55 | - /** | ||
56 | - * Gets all IPv6 routes known to SDN-IP. | ||
57 | - * | ||
58 | - * @return the SDN-IP IPv6 routes | ||
59 | - */ | ||
60 | - public Collection<RouteEntry> getRoutes6(); | ||
61 | 22 | ||
62 | /** | 23 | /** |
63 | * Changes whether this SDN-IP instance is the primary or not based on the | 24 | * Changes whether this SDN-IP instance is the primary or not based on the | ... | ... |
... | @@ -17,15 +17,6 @@ | ... | @@ -17,15 +17,6 @@ |
17 | 17 | ||
18 | <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> | 18 | <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> |
19 | <command> | 19 | <command> |
20 | - <action class="org.onosproject.sdnip.cli.BgpNeighborsListCommand"/> | ||
21 | - </command> | ||
22 | - <command> | ||
23 | - <action class="org.onosproject.sdnip.cli.BgpRoutesListCommand"/> | ||
24 | - </command> | ||
25 | - <command> | ||
26 | - <action class="org.onosproject.sdnip.cli.RoutesListCommand"/> | ||
27 | - </command> | ||
28 | - <command> | ||
29 | <action class="org.onosproject.sdnip.cli.PrimaryChangeCommand"/> | 20 | <action class="org.onosproject.sdnip.cli.PrimaryChangeCommand"/> |
30 | </command> | 21 | </command> |
31 | </command-bundle> | 22 | </command-bundle> | ... | ... |
... | @@ -16,9 +16,8 @@ | ... | @@ -16,9 +16,8 @@ |
16 | package org.onosproject.sdnip; | 16 | package org.onosproject.sdnip; |
17 | 17 | ||
18 | import com.google.common.collect.Sets; | 18 | import com.google.common.collect.Sets; |
19 | -import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; | 19 | +import org.easymock.EasyMock; |
20 | -import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; | 20 | +import org.junit.Assert; |
21 | -import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; | ||
22 | import org.junit.Before; | 21 | import org.junit.Before; |
23 | import org.junit.Test; | 22 | import org.junit.Test; |
24 | import org.onlab.junit.TestUtils; | 23 | import org.onlab.junit.TestUtils; |
... | @@ -32,18 +31,12 @@ import org.onlab.packet.MacAddress; | ... | @@ -32,18 +31,12 @@ import org.onlab.packet.MacAddress; |
32 | import org.onlab.packet.VlanId; | 31 | import org.onlab.packet.VlanId; |
33 | import org.onosproject.core.ApplicationId; | 32 | import org.onosproject.core.ApplicationId; |
34 | import org.onosproject.net.ConnectPoint; | 33 | import org.onosproject.net.ConnectPoint; |
35 | -import org.onosproject.net.DefaultHost; | ||
36 | import org.onosproject.net.DeviceId; | 34 | import org.onosproject.net.DeviceId; |
37 | -import org.onosproject.net.Host; | ||
38 | -import org.onosproject.net.HostId; | ||
39 | -import org.onosproject.net.HostLocation; | ||
40 | import org.onosproject.net.PortNumber; | 35 | import org.onosproject.net.PortNumber; |
41 | import org.onosproject.net.flow.DefaultTrafficSelector; | 36 | import org.onosproject.net.flow.DefaultTrafficSelector; |
42 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 37 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
43 | import org.onosproject.net.flow.TrafficSelector; | 38 | import org.onosproject.net.flow.TrafficSelector; |
44 | import org.onosproject.net.flow.TrafficTreatment; | 39 | import org.onosproject.net.flow.TrafficTreatment; |
45 | -import org.onosproject.net.host.HostListener; | ||
46 | -import org.onosproject.net.host.HostService; | ||
47 | import org.onosproject.net.host.InterfaceIpAddress; | 40 | import org.onosproject.net.host.InterfaceIpAddress; |
48 | import org.onosproject.net.intent.AbstractIntentTest; | 41 | import org.onosproject.net.intent.AbstractIntentTest; |
49 | import org.onosproject.net.intent.Intent; | 42 | import org.onosproject.net.intent.Intent; |
... | @@ -51,10 +44,18 @@ import org.onosproject.net.intent.IntentOperations; | ... | @@ -51,10 +44,18 @@ import org.onosproject.net.intent.IntentOperations; |
51 | import org.onosproject.net.intent.IntentService; | 44 | import org.onosproject.net.intent.IntentService; |
52 | import org.onosproject.net.intent.IntentState; | 45 | import org.onosproject.net.intent.IntentState; |
53 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; | 46 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
54 | -import org.onosproject.net.provider.ProviderId; | 47 | +import org.onosproject.routingapi.FibEntry; |
48 | +import org.onosproject.routingapi.FibUpdate; | ||
49 | +import org.onosproject.routingapi.RouteEntry; | ||
50 | +import org.onosproject.sdnip.IntentSynchronizer.IntentKey; | ||
51 | +import org.onosproject.sdnip.config.BgpPeer; | ||
55 | import org.onosproject.sdnip.config.Interface; | 52 | import org.onosproject.sdnip.config.Interface; |
53 | +import org.onosproject.sdnip.config.SdnIpConfigurationService; | ||
56 | 54 | ||
55 | +import java.util.Collections; | ||
56 | +import java.util.HashMap; | ||
57 | import java.util.HashSet; | 57 | import java.util.HashSet; |
58 | +import java.util.Map; | ||
58 | import java.util.Set; | 59 | import java.util.Set; |
59 | import java.util.concurrent.ConcurrentHashMap; | 60 | import java.util.concurrent.ConcurrentHashMap; |
60 | 61 | ||
... | @@ -71,9 +72,9 @@ import static org.junit.Assert.assertTrue; | ... | @@ -71,9 +72,9 @@ import static org.junit.Assert.assertTrue; |
71 | */ | 72 | */ |
72 | public class IntentSyncTest extends AbstractIntentTest { | 73 | public class IntentSyncTest extends AbstractIntentTest { |
73 | 74 | ||
75 | + private SdnIpConfigurationService sdnIpConfigService; | ||
74 | private InterfaceService interfaceService; | 76 | private InterfaceService interfaceService; |
75 | private IntentService intentService; | 77 | private IntentService intentService; |
76 | - private HostService hostService; | ||
77 | 78 | ||
78 | private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | 79 | private static final ConnectPoint SW1_ETH1 = new ConnectPoint( |
79 | DeviceId.deviceId("of:0000000000000001"), | 80 | DeviceId.deviceId("of:0000000000000001"), |
... | @@ -87,8 +88,11 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -87,8 +88,11 @@ public class IntentSyncTest extends AbstractIntentTest { |
87 | DeviceId.deviceId("of:0000000000000003"), | 88 | DeviceId.deviceId("of:0000000000000003"), |
88 | PortNumber.portNumber(1)); | 89 | PortNumber.portNumber(1)); |
89 | 90 | ||
91 | + private static final ConnectPoint SW4_ETH1 = new ConnectPoint( | ||
92 | + DeviceId.deviceId("of:0000000000000004"), | ||
93 | + PortNumber.portNumber(1)); | ||
94 | + | ||
90 | private IntentSynchronizer intentSynchronizer; | 95 | private IntentSynchronizer intentSynchronizer; |
91 | - private Router router; | ||
92 | 96 | ||
93 | private static final ApplicationId APPID = new ApplicationId() { | 97 | private static final ApplicationId APPID = new ApplicationId() { |
94 | @Override | 98 | @Override |
... | @@ -106,12 +110,42 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -106,12 +110,42 @@ public class IntentSyncTest extends AbstractIntentTest { |
106 | public void setUp() throws Exception { | 110 | public void setUp() throws Exception { |
107 | super.setUp(); | 111 | super.setUp(); |
108 | setUpInterfaceService(); | 112 | setUpInterfaceService(); |
109 | - setUpHostService(); | 113 | + |
114 | + setUpBgpPeers(); | ||
110 | intentService = createMock(IntentService.class); | 115 | intentService = createMock(IntentService.class); |
111 | 116 | ||
112 | intentSynchronizer = new IntentSynchronizer(APPID, intentService, | 117 | intentSynchronizer = new IntentSynchronizer(APPID, intentService, |
113 | - null, interfaceService); | 118 | + sdnIpConfigService, interfaceService); |
114 | - router = new Router(intentSynchronizer, hostService); | 119 | + } |
120 | + | ||
121 | + /** | ||
122 | + * Sets up BGP peers in external networks. | ||
123 | + */ | ||
124 | + private void setUpBgpPeers() { | ||
125 | + | ||
126 | + Map<IpAddress, BgpPeer> peers = new HashMap<>(); | ||
127 | + | ||
128 | + String peerSw1Eth1 = "192.168.10.1"; | ||
129 | + peers.put(IpAddress.valueOf(peerSw1Eth1), | ||
130 | + new BgpPeer("00:00:00:00:00:00:00:01", 1, peerSw1Eth1)); | ||
131 | + | ||
132 | + // Two BGP peers are connected to switch 2 port 1. | ||
133 | + String peer1Sw2Eth1 = "192.168.20.1"; | ||
134 | + peers.put(IpAddress.valueOf(peer1Sw2Eth1), | ||
135 | + new BgpPeer("00:00:00:00:00:00:00:02", 1, peer1Sw2Eth1)); | ||
136 | + | ||
137 | + String peer2Sw2Eth1 = "192.168.20.2"; | ||
138 | + peers.put(IpAddress.valueOf(peer2Sw2Eth1), | ||
139 | + new BgpPeer("00:00:00:00:00:00:00:02", 1, peer2Sw2Eth1)); | ||
140 | + | ||
141 | + String peer1Sw4Eth1 = "192.168.40.1"; | ||
142 | + peers.put(IpAddress.valueOf(peer1Sw4Eth1), | ||
143 | + new BgpPeer("00:00:00:00:00:00:00:04", 1, peer1Sw4Eth1)); | ||
144 | + | ||
145 | + sdnIpConfigService = createMock(SdnIpConfigurationService.class); | ||
146 | + expect(sdnIpConfigService.getBgpPeers()).andReturn(peers).anyTimes(); | ||
147 | + EasyMock.replay(sdnIpConfigService); | ||
148 | + | ||
115 | } | 149 | } |
116 | 150 | ||
117 | /** | 151 | /** |
... | @@ -133,8 +167,8 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -133,8 +167,8 @@ public class IntentSyncTest extends AbstractIntentTest { |
133 | interfaces.add(sw1Eth1); | 167 | interfaces.add(sw1Eth1); |
134 | 168 | ||
135 | Set<InterfaceIpAddress> interfaceIpAddresses2 = Sets.newHashSet(); | 169 | Set<InterfaceIpAddress> interfaceIpAddresses2 = Sets.newHashSet(); |
136 | - interfaceIpAddresses2.add(new InterfaceIpAddress( | 170 | + interfaceIpAddresses2.add( |
137 | - IpAddress.valueOf("192.168.20.101"), | 171 | + new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), |
138 | IpPrefix.valueOf("192.168.20.0/24"))); | 172 | IpPrefix.valueOf("192.168.20.0/24"))); |
139 | Interface sw2Eth1 = new Interface(SW2_ETH1, | 173 | Interface sw2Eth1 = new Interface(SW2_ETH1, |
140 | interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | 174 | interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), |
... | @@ -142,71 +176,270 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -142,71 +176,270 @@ public class IntentSyncTest extends AbstractIntentTest { |
142 | interfaces.add(sw2Eth1); | 176 | interfaces.add(sw2Eth1); |
143 | 177 | ||
144 | Set<InterfaceIpAddress> interfaceIpAddresses3 = Sets.newHashSet(); | 178 | Set<InterfaceIpAddress> interfaceIpAddresses3 = Sets.newHashSet(); |
145 | - interfaceIpAddresses3.add(new InterfaceIpAddress( | 179 | + interfaceIpAddresses3.add( |
146 | - IpAddress.valueOf("192.168.30.101"), | 180 | + new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), |
147 | IpPrefix.valueOf("192.168.30.0/24"))); | 181 | IpPrefix.valueOf("192.168.30.0/24"))); |
148 | Interface sw3Eth1 = new Interface(SW3_ETH1, | 182 | Interface sw3Eth1 = new Interface(SW3_ETH1, |
149 | interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"), | 183 | interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"), |
150 | VlanId.NONE); | 184 | VlanId.NONE); |
151 | interfaces.add(sw3Eth1); | 185 | interfaces.add(sw3Eth1); |
152 | 186 | ||
187 | + InterfaceIpAddress interfaceIpAddress4 = | ||
188 | + new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), | ||
189 | + IpPrefix.valueOf("192.168.40.0/24")); | ||
190 | + Interface sw4Eth1 = new Interface(SW4_ETH1, | ||
191 | + Sets.newHashSet(interfaceIpAddress4), | ||
192 | + MacAddress.valueOf("00:00:00:00:00:04"), | ||
193 | + VlanId.vlanId((short) 1)); | ||
194 | + | ||
195 | + expect(interfaceService.getInterface(SW4_ETH1)).andReturn(sw4Eth1).anyTimes(); | ||
196 | + interfaces.add(sw4Eth1); | ||
197 | + | ||
153 | expect(interfaceService.getInterface(SW1_ETH1)).andReturn( | 198 | expect(interfaceService.getInterface(SW1_ETH1)).andReturn( |
154 | sw1Eth1).anyTimes(); | 199 | sw1Eth1).anyTimes(); |
155 | expect(interfaceService.getInterface(SW2_ETH1)).andReturn( | 200 | expect(interfaceService.getInterface(SW2_ETH1)).andReturn( |
156 | sw2Eth1).anyTimes(); | 201 | sw2Eth1).anyTimes(); |
157 | expect(interfaceService.getInterface(SW3_ETH1)).andReturn( | 202 | expect(interfaceService.getInterface(SW3_ETH1)).andReturn( |
158 | sw3Eth1).anyTimes(); | 203 | sw3Eth1).anyTimes(); |
159 | - expect(interfaceService.getInterfaces()).andReturn( | 204 | + expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); |
160 | - interfaces).anyTimes(); | ||
161 | replay(interfaceService); | 205 | replay(interfaceService); |
162 | } | 206 | } |
163 | 207 | ||
164 | /** | 208 | /** |
165 | - * Sets up the host service with details of hosts. | 209 | + * Tests adding a FIB entry to the IntentSynchronizer. |
210 | + * | ||
211 | + * We verify that the synchronizer records the correct state and that the | ||
212 | + * correct intent is submitted to the IntentService. | ||
213 | + * | ||
214 | + * @throws TestUtilsException | ||
215 | + */ | ||
216 | + @Test | ||
217 | + public void testFibAdd() throws TestUtilsException { | ||
218 | + FibEntry fibEntry = new FibEntry( | ||
219 | + Ip4Prefix.valueOf("1.1.1.0/24"), | ||
220 | + Ip4Address.valueOf("192.168.10.1"), | ||
221 | + MacAddress.valueOf("00:00:00:00:00:01")); | ||
222 | + | ||
223 | + // Construct a MultiPointToSinglePointIntent intent | ||
224 | + TrafficSelector.Builder selectorBuilder = | ||
225 | + DefaultTrafficSelector.builder(); | ||
226 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( | ||
227 | + fibEntry.prefix()); | ||
228 | + | ||
229 | + TrafficTreatment.Builder treatmentBuilder = | ||
230 | + DefaultTrafficTreatment.builder(); | ||
231 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); | ||
232 | + | ||
233 | + Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
234 | + ingressPoints.add(SW2_ETH1); | ||
235 | + ingressPoints.add(SW3_ETH1); | ||
236 | + ingressPoints.add(SW4_ETH1); | ||
237 | + | ||
238 | + MultiPointToSinglePointIntent intent = | ||
239 | + new MultiPointToSinglePointIntent(APPID, | ||
240 | + selectorBuilder.build(), treatmentBuilder.build(), | ||
241 | + ingressPoints, SW1_ETH1); | ||
242 | + | ||
243 | + // Setup the expected intents | ||
244 | + IntentOperations.Builder builder = IntentOperations.builder(APPID); | ||
245 | + builder.addSubmitOperation(intent); | ||
246 | + intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
247 | + builder.build())); | ||
248 | + replay(intentService); | ||
249 | + | ||
250 | + intentSynchronizer.leaderChanged(true); | ||
251 | + TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
252 | + | ||
253 | + FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, | ||
254 | + fibEntry); | ||
255 | + intentSynchronizer.update(Collections.singleton(fibUpdate), | ||
256 | + Collections.emptyList()); | ||
257 | + | ||
258 | + Assert.assertEquals(intentSynchronizer.getRouteIntents().size(), 1); | ||
259 | + Intent firstIntent = | ||
260 | + intentSynchronizer.getRouteIntents().iterator().next(); | ||
261 | + IntentKey firstIntentKey = new IntentKey(firstIntent); | ||
262 | + IntentKey intentKey = new IntentKey(intent); | ||
263 | + assertTrue(firstIntentKey.equals(intentKey)); | ||
264 | + verify(intentService); | ||
265 | + } | ||
266 | + | ||
267 | + /** | ||
268 | + * Tests adding a FIB entry with to a next hop in a VLAN. | ||
269 | + * | ||
270 | + * We verify that the synchronizer records the correct state and that the | ||
271 | + * correct intent is submitted to the IntentService. | ||
272 | + * | ||
273 | + * @throws TestUtilsException | ||
274 | + */ | ||
275 | + @Test | ||
276 | + public void testFibAddWithVlan() throws TestUtilsException { | ||
277 | + FibEntry fibEntry = new FibEntry( | ||
278 | + Ip4Prefix.valueOf("3.3.3.0/24"), | ||
279 | + Ip4Address.valueOf("192.168.40.1"), | ||
280 | + MacAddress.valueOf("00:00:00:00:00:04")); | ||
281 | + | ||
282 | + // Construct a MultiPointToSinglePointIntent intent | ||
283 | + TrafficSelector.Builder selectorBuilder = | ||
284 | + DefaultTrafficSelector.builder(); | ||
285 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4) | ||
286 | + .matchIPDst(fibEntry.prefix()) | ||
287 | + .matchVlanId(VlanId.ANY); | ||
288 | + | ||
289 | + TrafficTreatment.Builder treatmentBuilder = | ||
290 | + DefaultTrafficTreatment.builder(); | ||
291 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:04")) | ||
292 | + .setVlanId(VlanId.vlanId((short) 1)); | ||
293 | + | ||
294 | + Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
295 | + ingressPoints.add(SW1_ETH1); | ||
296 | + ingressPoints.add(SW2_ETH1); | ||
297 | + ingressPoints.add(SW3_ETH1); | ||
298 | + | ||
299 | + MultiPointToSinglePointIntent intent = | ||
300 | + new MultiPointToSinglePointIntent(APPID, | ||
301 | + selectorBuilder.build(), treatmentBuilder.build(), | ||
302 | + ingressPoints, SW4_ETH1); | ||
303 | + | ||
304 | + // Setup the expected intents | ||
305 | + IntentOperations.Builder builder = IntentOperations.builder(APPID); | ||
306 | + builder.addSubmitOperation(intent); | ||
307 | + intentService.execute( | ||
308 | + TestIntentServiceHelper.eqExceptId(builder.build())); | ||
309 | + replay(intentService); | ||
310 | + | ||
311 | + // Run the test | ||
312 | + intentSynchronizer.leaderChanged(true); | ||
313 | + TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
314 | + FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry); | ||
315 | + | ||
316 | + intentSynchronizer.update(Collections.singleton(fibUpdate), | ||
317 | + Collections.emptyList()); | ||
318 | + | ||
319 | + // Verify | ||
320 | + Assert.assertEquals(intentSynchronizer.getRouteIntents().size(), 1); | ||
321 | + Intent firstIntent = | ||
322 | + intentSynchronizer.getRouteIntents().iterator().next(); | ||
323 | + IntentKey firstIntentKey = new IntentKey(firstIntent); | ||
324 | + IntentKey intentKey = new IntentKey(intent); | ||
325 | + assertTrue(firstIntentKey.equals(intentKey)); | ||
326 | + verify(intentService); | ||
327 | + } | ||
328 | + | ||
329 | + /** | ||
330 | + * Tests updating a FIB entry. | ||
331 | + * | ||
332 | + * We verify that the synchronizer records the correct state and that the | ||
333 | + * correct intent is submitted to the IntentService. | ||
334 | + * | ||
335 | + * @throws TestUtilsException | ||
166 | */ | 336 | */ |
167 | - private void setUpHostService() { | 337 | + @Test |
168 | - hostService = createMock(HostService.class); | 338 | + public void testFibUpdate() throws TestUtilsException { |
339 | + // Firstly add a route | ||
340 | + testFibAdd(); | ||
341 | + | ||
342 | + Intent addedIntent = | ||
343 | + intentSynchronizer.getRouteIntents().iterator().next(); | ||
344 | + | ||
345 | + // Start to construct a new route entry and new intent | ||
346 | + FibEntry fibEntryUpdate = new FibEntry( | ||
347 | + Ip4Prefix.valueOf("1.1.1.0/24"), | ||
348 | + Ip4Address.valueOf("192.168.20.1"), | ||
349 | + MacAddress.valueOf("00:00:00:00:00:02")); | ||
350 | + | ||
351 | + // Construct a new MultiPointToSinglePointIntent intent | ||
352 | + TrafficSelector.Builder selectorBuilderNew = | ||
353 | + DefaultTrafficSelector.builder(); | ||
354 | + selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( | ||
355 | + fibEntryUpdate.prefix()); | ||
356 | + | ||
357 | + TrafficTreatment.Builder treatmentBuilderNew = | ||
358 | + DefaultTrafficTreatment.builder(); | ||
359 | + treatmentBuilderNew.setEthDst(MacAddress.valueOf("00:00:00:00:00:02")); | ||
169 | 360 | ||
170 | - hostService.addListener(anyObject(HostListener.class)); | ||
171 | - expectLastCall().anyTimes(); | ||
172 | 361 | ||
173 | - IpAddress host1Address = IpAddress.valueOf("192.168.10.1"); | 362 | + Set<ConnectPoint> ingressPointsNew = new HashSet<>(); |
174 | - Host host1 = new DefaultHost(ProviderId.NONE, HostId.NONE, | 363 | + ingressPointsNew.add(SW1_ETH1); |
175 | - MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE, | 364 | + ingressPointsNew.add(SW3_ETH1); |
176 | - new HostLocation(SW1_ETH1, 1), | 365 | + ingressPointsNew.add(SW4_ETH1); |
177 | - Sets.newHashSet(host1Address)); | ||
178 | 366 | ||
179 | - expect(hostService.getHostsByIp(host1Address)) | 367 | + MultiPointToSinglePointIntent intentNew = |
180 | - .andReturn(Sets.newHashSet(host1)).anyTimes(); | 368 | + new MultiPointToSinglePointIntent(APPID, |
181 | - hostService.startMonitoringIp(host1Address); | 369 | + selectorBuilderNew.build(), |
182 | - expectLastCall().anyTimes(); | 370 | + treatmentBuilderNew.build(), |
371 | + ingressPointsNew, SW2_ETH1); | ||
372 | + | ||
373 | + // Set up test expectation | ||
374 | + reset(intentService); | ||
375 | + // Setup the expected intents | ||
376 | + IntentOperations.Builder builder = IntentOperations.builder(APPID); | ||
377 | + builder.addWithdrawOperation(addedIntent.id()); | ||
378 | + intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
379 | + builder.build())); | ||
380 | + builder = IntentOperations.builder(APPID); | ||
381 | + builder.addSubmitOperation(intentNew); | ||
382 | + intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
383 | + builder.build())); | ||
384 | + replay(intentService); | ||
183 | 385 | ||
386 | + // Call the update() method in IntentSynchronizer class | ||
387 | + intentSynchronizer.leaderChanged(true); | ||
388 | + TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
389 | + FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, | ||
390 | + fibEntryUpdate); | ||
391 | + intentSynchronizer.update(Collections.singletonList(fibUpdate), | ||
392 | + Collections.emptyList()); | ||
184 | 393 | ||
185 | - IpAddress host2Address = IpAddress.valueOf("192.168.20.1"); | 394 | + // Verify |
186 | - Host host2 = new DefaultHost(ProviderId.NONE, HostId.NONE, | 395 | + Assert.assertEquals(intentSynchronizer.getRouteIntents().size(), 1); |
187 | - MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE, | 396 | + Intent firstIntent = |
188 | - new HostLocation(SW2_ETH1, 1), | 397 | + intentSynchronizer.getRouteIntents().iterator().next(); |
189 | - Sets.newHashSet(host2Address)); | 398 | + IntentKey firstIntentKey = new IntentKey(firstIntent); |
399 | + IntentKey intentNewKey = new IntentKey(intentNew); | ||
400 | + assertTrue(firstIntentKey.equals(intentNewKey)); | ||
401 | + verify(intentService); | ||
402 | + } | ||
190 | 403 | ||
191 | - expect(hostService.getHostsByIp(host2Address)) | 404 | + /** |
192 | - .andReturn(Sets.newHashSet(host2)).anyTimes(); | 405 | + * Tests deleting a FIB entry. |
193 | - hostService.startMonitoringIp(host2Address); | 406 | + * |
194 | - expectLastCall().anyTimes(); | 407 | + * We verify that the synchronizer records the correct state and that the |
408 | + * correct intent is withdrawn from the IntentService. | ||
409 | + * | ||
410 | + * @throws TestUtilsException | ||
411 | + */ | ||
412 | + @Test | ||
413 | + public void testFibDelete() throws TestUtilsException { | ||
414 | + // Firstly add a route | ||
415 | + testFibAdd(); | ||
195 | 416 | ||
417 | + Intent addedIntent = | ||
418 | + intentSynchronizer.getRouteIntents().iterator().next(); | ||
196 | 419 | ||
197 | - IpAddress host3Address = IpAddress.valueOf("192.168.30.1"); | 420 | + // Construct the existing route entry |
198 | - Host host3 = new DefaultHost(ProviderId.NONE, HostId.NONE, | 421 | + FibEntry fibEntry = new FibEntry( |
199 | - MacAddress.valueOf("00:00:00:00:00:03"), VlanId.NONE, | 422 | + Ip4Prefix.valueOf("1.1.1.0/24"), null, null); |
200 | - new HostLocation(SW3_ETH1, 1), | ||
201 | - Sets.newHashSet(host3Address)); | ||
202 | 423 | ||
203 | - expect(hostService.getHostsByIp(host3Address)) | 424 | + // Set up expectation |
204 | - .andReturn(Sets.newHashSet(host3)).anyTimes(); | 425 | + reset(intentService); |
205 | - hostService.startMonitoringIp(host3Address); | 426 | + // Setup the expected intents |
206 | - expectLastCall().anyTimes(); | 427 | + IntentOperations.Builder builder = IntentOperations.builder(APPID); |
428 | + builder.addWithdrawOperation(addedIntent.id()); | ||
429 | + intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
430 | + builder.build())); | ||
431 | + replay(intentService); | ||
207 | 432 | ||
433 | + // Call the update() method in IntentSynchronizer class | ||
434 | + intentSynchronizer.leaderChanged(true); | ||
435 | + TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
436 | + FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry); | ||
437 | + intentSynchronizer.update(Collections.emptyList(), | ||
438 | + Collections.singletonList(fibUpdate)); | ||
208 | 439 | ||
209 | - replay(hostService); | 440 | + // Verify |
441 | + Assert.assertEquals(intentSynchronizer.getRouteIntents().size(), 0); | ||
442 | + verify(intentService); | ||
210 | } | 443 | } |
211 | 444 | ||
212 | /** | 445 | /** |
... | @@ -287,25 +520,7 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -287,25 +520,7 @@ public class IntentSyncTest extends AbstractIntentTest { |
287 | MultiPointToSinglePointIntent intent6 = intentBuilder( | 520 | MultiPointToSinglePointIntent intent6 = intentBuilder( |
288 | routeEntry6.prefix(), "00:00:00:00:00:01", SW1_ETH1); | 521 | routeEntry6.prefix(), "00:00:00:00:00:01", SW1_ETH1); |
289 | 522 | ||
290 | - // Set up the ribTable field in Router class and routeIntents fields | 523 | + // Set up the routeIntents field in IntentSynchronizer class |
291 | - // in IntentSynchronizer class | ||
292 | - InvertedRadixTree<RouteEntry> ribTable = | ||
293 | - new ConcurrentInvertedRadixTree<>( | ||
294 | - new DefaultByteArrayNodeFactory()); | ||
295 | - ribTable.put(RouteEntry.createBinaryString(routeEntry1.prefix()), | ||
296 | - routeEntry1); | ||
297 | - ribTable.put(RouteEntry.createBinaryString(routeEntry3.prefix()), | ||
298 | - routeEntry3); | ||
299 | - ribTable.put(RouteEntry.createBinaryString(routeEntry4Update.prefix()), | ||
300 | - routeEntry4Update); | ||
301 | - ribTable.put(RouteEntry.createBinaryString(routeEntry5.prefix()), | ||
302 | - routeEntry5); | ||
303 | - ribTable.put(RouteEntry.createBinaryString(routeEntry6.prefix()), | ||
304 | - routeEntry6); | ||
305 | - ribTable.put(RouteEntry.createBinaryString(routeEntry7.prefix()), | ||
306 | - routeEntry7); | ||
307 | - TestUtils.setField(router, "ribTable4", ribTable); | ||
308 | - | ||
309 | ConcurrentHashMap<IpPrefix, MultiPointToSinglePointIntent> | 524 | ConcurrentHashMap<IpPrefix, MultiPointToSinglePointIntent> |
310 | routeIntents = new ConcurrentHashMap<>(); | 525 | routeIntents = new ConcurrentHashMap<>(); |
311 | routeIntents.put(routeEntry1.prefix(), intent1); | 526 | routeIntents.put(routeEntry1.prefix(), intent1); |
... | @@ -353,20 +568,9 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -353,20 +568,9 @@ public class IntentSyncTest extends AbstractIntentTest { |
353 | 568 | ||
354 | // Start the test | 569 | // Start the test |
355 | intentSynchronizer.leaderChanged(true); | 570 | intentSynchronizer.leaderChanged(true); |
356 | - /* | ||
357 | - TestUtils.callMethod(intentSynchronizer, "synchronizeIntents", | ||
358 | - new Class<?>[] {}); | ||
359 | - */ | ||
360 | intentSynchronizer.synchronizeIntents(); | 571 | intentSynchronizer.synchronizeIntents(); |
361 | 572 | ||
362 | // Verify | 573 | // Verify |
363 | - assertEquals(router.getRoutes4().size(), 6); | ||
364 | - assertTrue(router.getRoutes4().contains(routeEntry1)); | ||
365 | - assertTrue(router.getRoutes4().contains(routeEntry3)); | ||
366 | - assertTrue(router.getRoutes4().contains(routeEntry4Update)); | ||
367 | - assertTrue(router.getRoutes4().contains(routeEntry5)); | ||
368 | - assertTrue(router.getRoutes4().contains(routeEntry6)); | ||
369 | - | ||
370 | assertEquals(intentSynchronizer.getRouteIntents().size(), 6); | 574 | assertEquals(intentSynchronizer.getRouteIntents().size(), 6); |
371 | assertTrue(intentSynchronizer.getRouteIntents().contains(intent1)); | 575 | assertTrue(intentSynchronizer.getRouteIntents().contains(intent1)); |
372 | assertTrue(intentSynchronizer.getRouteIntents().contains(intent3)); | 576 | assertTrue(intentSynchronizer.getRouteIntents().contains(intent3)); | ... | ... |
... | @@ -41,7 +41,6 @@ import org.onosproject.net.intent.Intent; | ... | @@ -41,7 +41,6 @@ import org.onosproject.net.intent.Intent; |
41 | import org.onosproject.net.intent.IntentOperations; | 41 | import org.onosproject.net.intent.IntentOperations; |
42 | import org.onosproject.net.intent.IntentService; | 42 | import org.onosproject.net.intent.IntentService; |
43 | import org.onosproject.net.intent.PointToPointIntent; | 43 | import org.onosproject.net.intent.PointToPointIntent; |
44 | -import org.onosproject.sdnip.bgp.BgpConstants; | ||
45 | import org.onosproject.sdnip.config.BgpPeer; | 44 | import org.onosproject.sdnip.config.BgpPeer; |
46 | import org.onosproject.sdnip.config.BgpSpeaker; | 45 | import org.onosproject.sdnip.config.BgpSpeaker; |
47 | import org.onosproject.sdnip.config.Interface; | 46 | import org.onosproject.sdnip.config.Interface; |
... | @@ -302,7 +301,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -302,7 +301,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
302 | */ | 301 | */ |
303 | private void setUpBgpIntents() { | 302 | private void setUpBgpIntents() { |
304 | 303 | ||
305 | - Short bgpPort = Short.valueOf((short) BgpConstants.BGP_PORT); | 304 | + Short bgpPort = 179; |
306 | 305 | ||
307 | // Start to build intents between BGP speaker1 and BGP peer1 | 306 | // Start to build intents between BGP speaker1 and BGP peer1 |
308 | bgpPathintentConstructor( | 307 | bgpPathintentConstructor( | ... | ... |
1 | -/* | ||
2 | - * Copyright 2014 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.onosproject.sdnip; | ||
17 | - | ||
18 | -import com.google.common.collect.Sets; | ||
19 | -import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; | ||
20 | -import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; | ||
21 | -import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; | ||
22 | -import org.junit.Before; | ||
23 | -import org.junit.Test; | ||
24 | -import org.onlab.junit.TestUtils; | ||
25 | -import org.onlab.junit.TestUtils.TestUtilsException; | ||
26 | -import org.onlab.packet.Ethernet; | ||
27 | -import org.onlab.packet.Ip4Address; | ||
28 | -import org.onlab.packet.Ip4Prefix; | ||
29 | -import org.onlab.packet.IpAddress; | ||
30 | -import org.onlab.packet.IpPrefix; | ||
31 | -import org.onlab.packet.MacAddress; | ||
32 | -import org.onlab.packet.VlanId; | ||
33 | -import org.onosproject.core.ApplicationId; | ||
34 | -import org.onosproject.net.ConnectPoint; | ||
35 | -import org.onosproject.net.DefaultHost; | ||
36 | -import org.onosproject.net.DeviceId; | ||
37 | -import org.onosproject.net.Host; | ||
38 | -import org.onosproject.net.HostId; | ||
39 | -import org.onosproject.net.HostLocation; | ||
40 | -import org.onosproject.net.PortNumber; | ||
41 | -import org.onosproject.net.flow.DefaultTrafficSelector; | ||
42 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
43 | -import org.onosproject.net.flow.TrafficSelector; | ||
44 | -import org.onosproject.net.flow.TrafficTreatment; | ||
45 | -import org.onosproject.net.host.HostEvent; | ||
46 | -import org.onosproject.net.host.HostService; | ||
47 | -import org.onosproject.net.host.InterfaceIpAddress; | ||
48 | -import org.onosproject.net.intent.AbstractIntentTest; | ||
49 | -import org.onosproject.net.intent.Intent; | ||
50 | -import org.onosproject.net.intent.IntentOperations; | ||
51 | -import org.onosproject.net.intent.IntentService; | ||
52 | -import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
53 | -import org.onosproject.net.provider.ProviderId; | ||
54 | -import org.onosproject.sdnip.IntentSynchronizer.IntentKey; | ||
55 | -import org.onosproject.sdnip.Router.InternalHostListener; | ||
56 | -import org.onosproject.sdnip.config.BgpPeer; | ||
57 | -import org.onosproject.sdnip.config.Interface; | ||
58 | -import org.onosproject.sdnip.config.SdnIpConfigurationService; | ||
59 | - | ||
60 | -import java.util.Collections; | ||
61 | -import java.util.HashMap; | ||
62 | -import java.util.HashSet; | ||
63 | -import java.util.Map; | ||
64 | -import java.util.Set; | ||
65 | -import java.util.concurrent.ConcurrentHashMap; | ||
66 | - | ||
67 | -import static org.easymock.EasyMock.*; | ||
68 | -import static org.junit.Assert.assertEquals; | ||
69 | -import static org.junit.Assert.assertTrue; | ||
70 | - | ||
71 | -/** | ||
72 | - * This class tests adding a route, updating a route, deleting a route, and | ||
73 | - * the ARP module answers the MAC address asynchronously. | ||
74 | - */ | ||
75 | -public class RouterAsyncArpTest extends AbstractIntentTest { | ||
76 | - | ||
77 | - private SdnIpConfigurationService sdnIpConfigService; | ||
78 | - private InterfaceService interfaceService; | ||
79 | - private IntentService intentService; | ||
80 | - private HostService hostService; | ||
81 | - | ||
82 | - private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
83 | - DeviceId.deviceId("of:0000000000000001"), | ||
84 | - PortNumber.portNumber(1)); | ||
85 | - | ||
86 | - private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
87 | - DeviceId.deviceId("of:0000000000000002"), | ||
88 | - PortNumber.portNumber(1)); | ||
89 | - | ||
90 | - private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
91 | - DeviceId.deviceId("of:0000000000000003"), | ||
92 | - PortNumber.portNumber(1)); | ||
93 | - | ||
94 | - private IntentSynchronizer intentSynchronizer; | ||
95 | - private Router router; | ||
96 | - private InternalHostListener internalHostListener; | ||
97 | - | ||
98 | - private static final ApplicationId APPID = new ApplicationId() { | ||
99 | - @Override | ||
100 | - public short id() { | ||
101 | - return 1; | ||
102 | - } | ||
103 | - | ||
104 | - @Override | ||
105 | - public String name() { | ||
106 | - return "SDNIP"; | ||
107 | - } | ||
108 | - }; | ||
109 | - | ||
110 | - @Before | ||
111 | - public void setUp() throws Exception { | ||
112 | - super.setUp(); | ||
113 | - | ||
114 | - setUpSdnIpConfigService(); | ||
115 | - setUpInterfaceService(); | ||
116 | - hostService = createMock(HostService.class); | ||
117 | - intentService = createMock(IntentService.class); | ||
118 | - | ||
119 | - intentSynchronizer = new IntentSynchronizer(APPID, intentService, | ||
120 | - sdnIpConfigService, | ||
121 | - interfaceService); | ||
122 | - router = new Router(intentSynchronizer, hostService); | ||
123 | - internalHostListener = router.new InternalHostListener(); | ||
124 | - } | ||
125 | - | ||
126 | - /** | ||
127 | - * Sets up SdnIpConfigService. | ||
128 | - */ | ||
129 | - private void setUpSdnIpConfigService() { | ||
130 | - | ||
131 | - sdnIpConfigService = createMock(SdnIpConfigurationService.class); | ||
132 | - | ||
133 | - Map<IpAddress, BgpPeer> peers = new HashMap<>(); | ||
134 | - | ||
135 | - String peerSw1Eth1 = "192.168.10.1"; | ||
136 | - peers.put(IpAddress.valueOf(peerSw1Eth1), | ||
137 | - new BgpPeer("00:00:00:00:00:00:00:01", 1, peerSw1Eth1)); | ||
138 | - | ||
139 | - // Two BGP peers are connected to switch 2 port 1. | ||
140 | - String peer1Sw2Eth1 = "192.168.20.1"; | ||
141 | - peers.put(IpAddress.valueOf(peer1Sw2Eth1), | ||
142 | - new BgpPeer("00:00:00:00:00:00:00:02", 1, peer1Sw2Eth1)); | ||
143 | - | ||
144 | - String peer2Sw2Eth1 = "192.168.20.2"; | ||
145 | - peers.put(IpAddress.valueOf(peer2Sw2Eth1), | ||
146 | - new BgpPeer("00:00:00:00:00:00:00:02", 1, peer2Sw2Eth1)); | ||
147 | - | ||
148 | - expect(sdnIpConfigService.getBgpPeers()).andReturn(peers).anyTimes(); | ||
149 | - replay(sdnIpConfigService); | ||
150 | - } | ||
151 | - | ||
152 | - /** | ||
153 | - * Sets up InterfaceService. | ||
154 | - */ | ||
155 | - private void setUpInterfaceService() { | ||
156 | - | ||
157 | - interfaceService = createMock(InterfaceService.class); | ||
158 | - | ||
159 | - Set<Interface> interfaces = Sets.newHashSet(); | ||
160 | - | ||
161 | - Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet(); | ||
162 | - interfaceIpAddresses1.add(new InterfaceIpAddress( | ||
163 | - IpAddress.valueOf("192.168.10.101"), | ||
164 | - IpPrefix.valueOf("192.168.10.0/24"))); | ||
165 | - Interface sw1Eth1 = new Interface(SW1_ETH1, | ||
166 | - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | ||
167 | - VlanId.NONE); | ||
168 | - interfaces.add(sw1Eth1); | ||
169 | - | ||
170 | - Set<InterfaceIpAddress> interfaceIpAddresses2 = Sets.newHashSet(); | ||
171 | - interfaceIpAddresses2.add(new InterfaceIpAddress( | ||
172 | - IpAddress.valueOf("192.168.20.101"), | ||
173 | - IpPrefix.valueOf("192.168.20.0/24"))); | ||
174 | - Interface sw2Eth1 = new Interface(SW2_ETH1, | ||
175 | - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
176 | - VlanId.NONE); | ||
177 | - interfaces.add(sw2Eth1); | ||
178 | - | ||
179 | - Set<InterfaceIpAddress> interfaceIpAddresses3 = Sets.newHashSet(); | ||
180 | - interfaceIpAddresses3.add(new InterfaceIpAddress( | ||
181 | - IpAddress.valueOf("192.168.30.101"), | ||
182 | - IpPrefix.valueOf("192.168.30.0/24"))); | ||
183 | - Interface sw3Eth1 = new Interface(SW3_ETH1, | ||
184 | - interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"), | ||
185 | - VlanId.NONE); | ||
186 | - interfaces.add(sw3Eth1); | ||
187 | - | ||
188 | - expect(interfaceService.getInterface(SW1_ETH1)).andReturn(sw1Eth1).anyTimes(); | ||
189 | - expect(interfaceService.getInterface(SW2_ETH1)).andReturn(sw2Eth1).anyTimes(); | ||
190 | - expect(interfaceService.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes(); | ||
191 | - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | ||
192 | - replay(interfaceService); | ||
193 | - } | ||
194 | - | ||
195 | - /** | ||
196 | - * This method tests adding a route entry. | ||
197 | - */ | ||
198 | - @Test | ||
199 | - public void testRouteAdd() throws TestUtilsException { | ||
200 | - | ||
201 | - // Construct a route entry | ||
202 | - RouteEntry routeEntry = new RouteEntry( | ||
203 | - Ip4Prefix.valueOf("1.1.1.0/24"), | ||
204 | - Ip4Address.valueOf("192.168.10.1")); | ||
205 | - | ||
206 | - // Construct a route intent | ||
207 | - MultiPointToSinglePointIntent intent = staticIntentBuilder(); | ||
208 | - | ||
209 | - // Set up test expectation | ||
210 | - reset(hostService); | ||
211 | - expect(hostService.getHostsByIp(anyObject(IpAddress.class))).andReturn( | ||
212 | - new HashSet<Host>()).anyTimes(); | ||
213 | - hostService.startMonitoringIp(IpAddress.valueOf("192.168.10.1")); | ||
214 | - replay(hostService); | ||
215 | - | ||
216 | - reset(intentService); | ||
217 | - IntentOperations.Builder builder = IntentOperations.builder(APPID); | ||
218 | - builder.addSubmitOperation(intent); | ||
219 | - intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
220 | - builder.build())); | ||
221 | - replay(intentService); | ||
222 | - | ||
223 | - // Call the processRouteUpdates() method in Router class | ||
224 | - intentSynchronizer.leaderChanged(true); | ||
225 | - TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
226 | - RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE, | ||
227 | - routeEntry); | ||
228 | - router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate)); | ||
229 | - | ||
230 | - Host host = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
231 | - MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE, | ||
232 | - new HostLocation( | ||
233 | - SW1_ETH1.deviceId(), | ||
234 | - SW1_ETH1.port(), 1), | ||
235 | - Sets.newHashSet(IpAddress.valueOf("192.168.10.1"))); | ||
236 | - internalHostListener.event( | ||
237 | - new HostEvent(HostEvent.Type.HOST_ADDED, host)); | ||
238 | - | ||
239 | - // Verify | ||
240 | - assertEquals(router.getRoutes4().size(), 1); | ||
241 | - assertTrue(router.getRoutes4().contains(routeEntry)); | ||
242 | - assertEquals(intentSynchronizer.getRouteIntents().size(), 1); | ||
243 | - Intent firstIntent = | ||
244 | - intentSynchronizer.getRouteIntents().iterator().next(); | ||
245 | - IntentKey firstIntentKey = new IntentKey(firstIntent); | ||
246 | - IntentKey intentKey = new IntentKey(intent); | ||
247 | - assertTrue(firstIntentKey.equals(intentKey)); | ||
248 | - verify(intentService); | ||
249 | - verify(hostService); | ||
250 | - | ||
251 | - } | ||
252 | - | ||
253 | - /** | ||
254 | - * This method tests updating a route entry. | ||
255 | - * | ||
256 | - * @throws TestUtilsException | ||
257 | - */ | ||
258 | - @Test | ||
259 | - public void testRouteUpdate() throws TestUtilsException { | ||
260 | - | ||
261 | - // Construct the existing route entry | ||
262 | - RouteEntry routeEntry = new RouteEntry( | ||
263 | - Ip4Prefix.valueOf("1.1.1.0/24"), | ||
264 | - Ip4Address.valueOf("192.168.10.1")); | ||
265 | - | ||
266 | - // Construct the existing MultiPointToSinglePointIntent intent | ||
267 | - MultiPointToSinglePointIntent intent = staticIntentBuilder(); | ||
268 | - | ||
269 | - // Set up the ribTable field of Router class with existing route, and | ||
270 | - // routeIntents field with the corresponding existing intent | ||
271 | - setRibTableField(routeEntry); | ||
272 | - setRouteIntentsField(routeEntry, intent); | ||
273 | - | ||
274 | - // Start to construct a new route entry and new intent | ||
275 | - RouteEntry routeEntryUpdate = new RouteEntry( | ||
276 | - Ip4Prefix.valueOf("1.1.1.0/24"), | ||
277 | - Ip4Address.valueOf("192.168.20.1")); | ||
278 | - | ||
279 | - // Construct a new MultiPointToSinglePointIntent intent | ||
280 | - TrafficSelector.Builder selectorBuilderNew = | ||
281 | - DefaultTrafficSelector.builder(); | ||
282 | - selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( | ||
283 | - routeEntryUpdate.prefix()); | ||
284 | - | ||
285 | - TrafficTreatment.Builder treatmentBuilderNew = | ||
286 | - DefaultTrafficTreatment.builder(); | ||
287 | - treatmentBuilderNew.setEthDst(MacAddress.valueOf("00:00:00:00:00:02")); | ||
288 | - | ||
289 | - Set<ConnectPoint> ingressPointsNew = new HashSet<ConnectPoint>(); | ||
290 | - ingressPointsNew.add(SW1_ETH1); | ||
291 | - ingressPointsNew.add(SW3_ETH1); | ||
292 | - | ||
293 | - MultiPointToSinglePointIntent intentNew = | ||
294 | - new MultiPointToSinglePointIntent(APPID, | ||
295 | - selectorBuilderNew.build(), | ||
296 | - treatmentBuilderNew.build(), | ||
297 | - ingressPointsNew, SW2_ETH1); | ||
298 | - | ||
299 | - // Set up test expectation | ||
300 | - reset(hostService); | ||
301 | - expect(hostService.getHostsByIp(anyObject(IpAddress.class))).andReturn( | ||
302 | - new HashSet<Host>()).anyTimes(); | ||
303 | - hostService.startMonitoringIp(IpAddress.valueOf("192.168.20.1")); | ||
304 | - replay(hostService); | ||
305 | - | ||
306 | - reset(intentService); | ||
307 | - IntentOperations.Builder builder = IntentOperations.builder(APPID); | ||
308 | - builder.addWithdrawOperation(intent.id()); | ||
309 | - intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
310 | - builder.build())); | ||
311 | - builder = IntentOperations.builder(APPID); | ||
312 | - builder.addSubmitOperation(intentNew); | ||
313 | - intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
314 | - builder.build())); | ||
315 | - replay(intentService); | ||
316 | - | ||
317 | - // Call the processRouteUpdates() method in Router class | ||
318 | - intentSynchronizer.leaderChanged(true); | ||
319 | - TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
320 | - RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE, | ||
321 | - routeEntryUpdate); | ||
322 | - router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate)); | ||
323 | - | ||
324 | - Host host = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
325 | - MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE, | ||
326 | - new HostLocation( | ||
327 | - SW2_ETH1.deviceId(), | ||
328 | - SW2_ETH1.port(), 1), | ||
329 | - Sets.newHashSet(IpAddress.valueOf("192.168.20.1"))); | ||
330 | - internalHostListener.event( | ||
331 | - new HostEvent(HostEvent.Type.HOST_ADDED, host)); | ||
332 | - | ||
333 | - // Verify | ||
334 | - assertEquals(router.getRoutes4().size(), 1); | ||
335 | - assertTrue(router.getRoutes4().contains(routeEntryUpdate)); | ||
336 | - assertEquals(intentSynchronizer.getRouteIntents().size(), 1); | ||
337 | - Intent firstIntent = | ||
338 | - intentSynchronizer.getRouteIntents().iterator().next(); | ||
339 | - IntentKey firstIntentKey = new IntentKey(firstIntent); | ||
340 | - IntentKey intentNewKey = new IntentKey(intentNew); | ||
341 | - assertTrue(firstIntentKey.equals(intentNewKey)); | ||
342 | - verify(intentService); | ||
343 | - verify(hostService); | ||
344 | - } | ||
345 | - | ||
346 | - /** | ||
347 | - * This method tests deleting a route entry. | ||
348 | - */ | ||
349 | - @Test | ||
350 | - public void testRouteDelete() throws TestUtilsException { | ||
351 | - | ||
352 | - // Construct the existing route entry | ||
353 | - RouteEntry routeEntry = new RouteEntry( | ||
354 | - Ip4Prefix.valueOf("1.1.1.0/24"), | ||
355 | - Ip4Address.valueOf("192.168.10.1")); | ||
356 | - | ||
357 | - // Construct the existing MultiPointToSinglePointIntent intent | ||
358 | - MultiPointToSinglePointIntent intent = staticIntentBuilder(); | ||
359 | - | ||
360 | - // Set up the ribTable field of Router class with existing route, and | ||
361 | - // routeIntents field with the corresponding existing intent | ||
362 | - setRibTableField(routeEntry); | ||
363 | - setRouteIntentsField(routeEntry, intent); | ||
364 | - | ||
365 | - // Set up expectation | ||
366 | - reset(intentService); | ||
367 | - IntentOperations.Builder builder = IntentOperations.builder(APPID); | ||
368 | - builder.addWithdrawOperation(intent.id()); | ||
369 | - intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
370 | - builder.build())); | ||
371 | - replay(intentService); | ||
372 | - | ||
373 | - // Call the processRouteUpdates() method in Router class | ||
374 | - intentSynchronizer.leaderChanged(true); | ||
375 | - TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
376 | - RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.DELETE, | ||
377 | - routeEntry); | ||
378 | - router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate)); | ||
379 | - | ||
380 | - // Verify | ||
381 | - assertEquals(router.getRoutes4().size(), 0); | ||
382 | - assertEquals(intentSynchronizer.getRouteIntents().size(), 0); | ||
383 | - verify(intentService); | ||
384 | - } | ||
385 | - | ||
386 | - /** | ||
387 | - * Constructs a static MultiPointToSinglePointIntent. | ||
388 | - */ | ||
389 | - private MultiPointToSinglePointIntent staticIntentBuilder() { | ||
390 | - | ||
391 | - TrafficSelector.Builder selectorBuilder = | ||
392 | - DefaultTrafficSelector.builder(); | ||
393 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( | ||
394 | - IpPrefix.valueOf("1.1.1.0/24")); | ||
395 | - | ||
396 | - TrafficTreatment.Builder treatmentBuilder = | ||
397 | - DefaultTrafficTreatment.builder(); | ||
398 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); | ||
399 | - | ||
400 | - Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>(); | ||
401 | - ingressPoints.add(SW2_ETH1); | ||
402 | - ingressPoints.add(SW3_ETH1); | ||
403 | - | ||
404 | - MultiPointToSinglePointIntent intent = | ||
405 | - new MultiPointToSinglePointIntent(APPID, | ||
406 | - selectorBuilder.build(), treatmentBuilder.build(), | ||
407 | - ingressPoints, SW1_ETH1); | ||
408 | - | ||
409 | - return intent; | ||
410 | - } | ||
411 | - | ||
412 | - /** | ||
413 | - * Sets ribTable Field in Router class. | ||
414 | - * | ||
415 | - * @throws TestUtilsException | ||
416 | - */ | ||
417 | - private void setRibTableField(RouteEntry routeEntry) | ||
418 | - throws TestUtilsException { | ||
419 | - | ||
420 | - InvertedRadixTree<RouteEntry> ribTable = | ||
421 | - new ConcurrentInvertedRadixTree<>( | ||
422 | - new DefaultByteArrayNodeFactory()); | ||
423 | - ribTable.put(RouteEntry.createBinaryString(routeEntry.prefix()), | ||
424 | - routeEntry); | ||
425 | - TestUtils.setField(router, "ribTable4", ribTable); | ||
426 | - } | ||
427 | - | ||
428 | - /** | ||
429 | - * Sets routeIntentsField in IntentSynchronizer class. | ||
430 | - * | ||
431 | - * @throws TestUtilsException | ||
432 | - */ | ||
433 | - private void setRouteIntentsField(RouteEntry routeEntry, | ||
434 | - MultiPointToSinglePointIntent intent) | ||
435 | - throws TestUtilsException { | ||
436 | - | ||
437 | - ConcurrentHashMap<IpPrefix, MultiPointToSinglePointIntent> | ||
438 | - routeIntents = new ConcurrentHashMap<>(); | ||
439 | - routeIntents.put(routeEntry.prefix(), intent); | ||
440 | - TestUtils.setField(intentSynchronizer, "routeIntents", routeIntents); | ||
441 | - } | ||
442 | -} |
1 | -/* | ||
2 | - * Copyright 2014 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.onosproject.sdnip; | ||
17 | - | ||
18 | -import com.google.common.collect.Sets; | ||
19 | -import org.junit.Before; | ||
20 | -import org.junit.Test; | ||
21 | -import org.onlab.junit.TestUtils; | ||
22 | -import org.onlab.junit.TestUtils.TestUtilsException; | ||
23 | -import org.onlab.packet.Ethernet; | ||
24 | -import org.onlab.packet.Ip4Address; | ||
25 | -import org.onlab.packet.Ip4Prefix; | ||
26 | -import org.onlab.packet.IpAddress; | ||
27 | -import org.onlab.packet.IpPrefix; | ||
28 | -import org.onlab.packet.MacAddress; | ||
29 | -import org.onlab.packet.VlanId; | ||
30 | -import org.onosproject.core.ApplicationId; | ||
31 | -import org.onosproject.net.ConnectPoint; | ||
32 | -import org.onosproject.net.DefaultHost; | ||
33 | -import org.onosproject.net.DeviceId; | ||
34 | -import org.onosproject.net.Host; | ||
35 | -import org.onosproject.net.HostId; | ||
36 | -import org.onosproject.net.HostLocation; | ||
37 | -import org.onosproject.net.PortNumber; | ||
38 | -import org.onosproject.net.flow.DefaultTrafficSelector; | ||
39 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
40 | -import org.onosproject.net.flow.TrafficSelector; | ||
41 | -import org.onosproject.net.flow.TrafficTreatment; | ||
42 | -import org.onosproject.net.host.HostListener; | ||
43 | -import org.onosproject.net.host.HostService; | ||
44 | -import org.onosproject.net.host.InterfaceIpAddress; | ||
45 | -import org.onosproject.net.intent.AbstractIntentTest; | ||
46 | -import org.onosproject.net.intent.Intent; | ||
47 | -import org.onosproject.net.intent.IntentOperations; | ||
48 | -import org.onosproject.net.intent.IntentService; | ||
49 | -import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
50 | -import org.onosproject.net.provider.ProviderId; | ||
51 | -import org.onosproject.sdnip.IntentSynchronizer.IntentKey; | ||
52 | -import org.onosproject.sdnip.config.BgpPeer; | ||
53 | -import org.onosproject.sdnip.config.Interface; | ||
54 | -import org.onosproject.sdnip.config.SdnIpConfigurationService; | ||
55 | - | ||
56 | -import java.util.Collections; | ||
57 | -import java.util.HashMap; | ||
58 | -import java.util.HashSet; | ||
59 | -import java.util.Map; | ||
60 | -import java.util.Set; | ||
61 | - | ||
62 | -import static org.easymock.EasyMock.*; | ||
63 | -import static org.junit.Assert.assertEquals; | ||
64 | -import static org.junit.Assert.assertTrue; | ||
65 | - | ||
66 | -/** | ||
67 | - * This class tests adding a route, updating a route, deleting a route, | ||
68 | - * and adding a route whose next hop is the local BGP speaker. | ||
69 | - * <p/> | ||
70 | - * ARP module answers the MAC address synchronously. | ||
71 | - */ | ||
72 | -public class RouterTest extends AbstractIntentTest { | ||
73 | - | ||
74 | - private SdnIpConfigurationService sdnIpConfigService; | ||
75 | - private InterfaceService interfaceService; | ||
76 | - private IntentService intentService; | ||
77 | - private HostService hostService; | ||
78 | - | ||
79 | - private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
80 | - DeviceId.deviceId("of:0000000000000001"), | ||
81 | - PortNumber.portNumber(1)); | ||
82 | - | ||
83 | - private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
84 | - DeviceId.deviceId("of:0000000000000002"), | ||
85 | - PortNumber.portNumber(1)); | ||
86 | - | ||
87 | - private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
88 | - DeviceId.deviceId("of:0000000000000003"), | ||
89 | - PortNumber.portNumber(1)); | ||
90 | - | ||
91 | - private static final ConnectPoint SW4_ETH1 = new ConnectPoint( | ||
92 | - DeviceId.deviceId("of:0000000000000004"), | ||
93 | - PortNumber.portNumber(1)); | ||
94 | - | ||
95 | - private static final ApplicationId APPID = new ApplicationId() { | ||
96 | - @Override | ||
97 | - public short id() { | ||
98 | - return 1; | ||
99 | - } | ||
100 | - | ||
101 | - @Override | ||
102 | - public String name() { | ||
103 | - return "SDNIP"; | ||
104 | - } | ||
105 | - }; | ||
106 | - | ||
107 | - private IntentSynchronizer intentSynchronizer; | ||
108 | - private Router router; | ||
109 | - | ||
110 | - @Before | ||
111 | - public void setUp() throws Exception { | ||
112 | - super.setUp(); | ||
113 | - | ||
114 | - setUpBgpPeers(); | ||
115 | - | ||
116 | - setUpInterfaceService(); | ||
117 | - setUpHostService(); | ||
118 | - | ||
119 | - intentService = createMock(IntentService.class); | ||
120 | - | ||
121 | - intentSynchronizer = new IntentSynchronizer(APPID, intentService, | ||
122 | - sdnIpConfigService, | ||
123 | - interfaceService); | ||
124 | - router = new Router(intentSynchronizer, hostService); | ||
125 | - } | ||
126 | - | ||
127 | - /** | ||
128 | - * Sets up BGP peers in external networks. | ||
129 | - */ | ||
130 | - private void setUpBgpPeers() { | ||
131 | - | ||
132 | - Map<IpAddress, BgpPeer> peers = new HashMap<>(); | ||
133 | - | ||
134 | - String peerSw1Eth1 = "192.168.10.1"; | ||
135 | - peers.put(IpAddress.valueOf(peerSw1Eth1), | ||
136 | - new BgpPeer("00:00:00:00:00:00:00:01", 1, peerSw1Eth1)); | ||
137 | - | ||
138 | - // Two BGP peers are connected to switch 2 port 1. | ||
139 | - String peer1Sw2Eth1 = "192.168.20.1"; | ||
140 | - peers.put(IpAddress.valueOf(peer1Sw2Eth1), | ||
141 | - new BgpPeer("00:00:00:00:00:00:00:02", 1, peer1Sw2Eth1)); | ||
142 | - | ||
143 | - String peer2Sw2Eth1 = "192.168.20.2"; | ||
144 | - peers.put(IpAddress.valueOf(peer2Sw2Eth1), | ||
145 | - new BgpPeer("00:00:00:00:00:00:00:02", 1, peer2Sw2Eth1)); | ||
146 | - | ||
147 | - String peer1Sw4Eth1 = "192.168.40.1"; | ||
148 | - peers.put(IpAddress.valueOf(peer1Sw4Eth1), | ||
149 | - new BgpPeer("00:00:00:00:00:00:00:04", 1, peer1Sw4Eth1)); | ||
150 | - | ||
151 | - sdnIpConfigService = createMock(SdnIpConfigurationService.class); | ||
152 | - expect(sdnIpConfigService.getBgpPeers()).andReturn(peers).anyTimes(); | ||
153 | - replay(sdnIpConfigService); | ||
154 | - | ||
155 | - } | ||
156 | - | ||
157 | - /** | ||
158 | - * Sets up logical interfaces, which emulate the configured interfaces | ||
159 | - * in SDN-IP application. | ||
160 | - */ | ||
161 | - private void setUpInterfaceService() { | ||
162 | - interfaceService = createMock(InterfaceService.class); | ||
163 | - | ||
164 | - Set<Interface> interfaces = Sets.newHashSet(); | ||
165 | - | ||
166 | - InterfaceIpAddress ia1 = | ||
167 | - new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), | ||
168 | - IpPrefix.valueOf("192.168.10.0/24")); | ||
169 | - Interface sw1Eth1 = new Interface(SW1_ETH1, | ||
170 | - Sets.newHashSet(ia1), | ||
171 | - MacAddress.valueOf("00:00:00:00:00:01"), | ||
172 | - VlanId.NONE); | ||
173 | - | ||
174 | - expect(interfaceService.getInterface(SW1_ETH1)).andReturn(sw1Eth1).anyTimes(); | ||
175 | - interfaces.add(sw1Eth1); | ||
176 | - | ||
177 | - InterfaceIpAddress ia2 = | ||
178 | - new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), | ||
179 | - IpPrefix.valueOf("192.168.20.0/24")); | ||
180 | - Interface sw2Eth1 = new Interface(SW2_ETH1, | ||
181 | - Sets.newHashSet(ia2), | ||
182 | - MacAddress.valueOf("00:00:00:00:00:02"), | ||
183 | - VlanId.NONE); | ||
184 | - | ||
185 | - expect(interfaceService.getInterface(SW2_ETH1)).andReturn(sw2Eth1).anyTimes(); | ||
186 | - interfaces.add(sw2Eth1); | ||
187 | - | ||
188 | - InterfaceIpAddress ia3 = | ||
189 | - new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), | ||
190 | - IpPrefix.valueOf("192.168.30.0/24")); | ||
191 | - Interface sw3Eth1 = new Interface(SW3_ETH1, | ||
192 | - Sets.newHashSet(ia3), | ||
193 | - MacAddress.valueOf("00:00:00:00:00:03"), | ||
194 | - VlanId.NONE); | ||
195 | - | ||
196 | - expect(interfaceService.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes(); | ||
197 | - interfaces.add(sw3Eth1); | ||
198 | - | ||
199 | - InterfaceIpAddress ia4 = | ||
200 | - new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), | ||
201 | - IpPrefix.valueOf("192.168.40.0/24")); | ||
202 | - Interface sw4Eth1 = new Interface(SW4_ETH1, | ||
203 | - Sets.newHashSet(ia4), | ||
204 | - MacAddress.valueOf("00:00:00:00:00:04"), | ||
205 | - VlanId.vlanId((short) 1)); | ||
206 | - | ||
207 | - expect(interfaceService.getInterface(SW4_ETH1)).andReturn(sw4Eth1).anyTimes(); | ||
208 | - interfaces.add(sw4Eth1); | ||
209 | - | ||
210 | - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | ||
211 | - | ||
212 | - replay(interfaceService); | ||
213 | - } | ||
214 | - | ||
215 | - /** | ||
216 | - * Sets up the host service with details of some hosts. | ||
217 | - */ | ||
218 | - private void setUpHostService() { | ||
219 | - hostService = createMock(HostService.class); | ||
220 | - | ||
221 | - hostService.addListener(anyObject(HostListener.class)); | ||
222 | - expectLastCall().anyTimes(); | ||
223 | - | ||
224 | - IpAddress host1Address = IpAddress.valueOf("192.168.10.1"); | ||
225 | - Host host1 = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
226 | - MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE, | ||
227 | - new HostLocation(SW1_ETH1, 1), | ||
228 | - Sets.newHashSet(host1Address)); | ||
229 | - | ||
230 | - expect(hostService.getHostsByIp(host1Address)) | ||
231 | - .andReturn(Sets.newHashSet(host1)).anyTimes(); | ||
232 | - hostService.startMonitoringIp(host1Address); | ||
233 | - expectLastCall().anyTimes(); | ||
234 | - | ||
235 | - | ||
236 | - IpAddress host2Address = IpAddress.valueOf("192.168.20.1"); | ||
237 | - Host host2 = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
238 | - MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE, | ||
239 | - new HostLocation(SW2_ETH1, 1), | ||
240 | - Sets.newHashSet(host2Address)); | ||
241 | - | ||
242 | - expect(hostService.getHostsByIp(host2Address)) | ||
243 | - .andReturn(Sets.newHashSet(host2)).anyTimes(); | ||
244 | - hostService.startMonitoringIp(host2Address); | ||
245 | - expectLastCall().anyTimes(); | ||
246 | - | ||
247 | - // Next hop on a VLAN | ||
248 | - IpAddress host3Address = IpAddress.valueOf("192.168.40.1"); | ||
249 | - Host host3 = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
250 | - MacAddress.valueOf("00:00:00:00:00:03"), VlanId.vlanId((short) 1), | ||
251 | - new HostLocation(SW4_ETH1, 1), | ||
252 | - Sets.newHashSet(host3Address)); | ||
253 | - | ||
254 | - expect(hostService.getHostsByIp(host3Address)) | ||
255 | - .andReturn(Sets.newHashSet(host3)).anyTimes(); | ||
256 | - hostService.startMonitoringIp(host3Address); | ||
257 | - expectLastCall().anyTimes(); | ||
258 | - | ||
259 | - | ||
260 | - replay(hostService); | ||
261 | - } | ||
262 | - | ||
263 | - /** | ||
264 | - * This method tests adding a route entry. | ||
265 | - */ | ||
266 | - @Test | ||
267 | - public void testRouteAdd() throws TestUtilsException { | ||
268 | - // Construct a route entry | ||
269 | - RouteEntry routeEntry = new RouteEntry( | ||
270 | - Ip4Prefix.valueOf("1.1.1.0/24"), | ||
271 | - Ip4Address.valueOf("192.168.10.1")); | ||
272 | - | ||
273 | - // Construct a MultiPointToSinglePointIntent intent | ||
274 | - TrafficSelector.Builder selectorBuilder = | ||
275 | - DefaultTrafficSelector.builder(); | ||
276 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( | ||
277 | - routeEntry.prefix()); | ||
278 | - | ||
279 | - TrafficTreatment.Builder treatmentBuilder = | ||
280 | - DefaultTrafficTreatment.builder(); | ||
281 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); | ||
282 | - | ||
283 | - Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>(); | ||
284 | - ingressPoints.add(SW2_ETH1); | ||
285 | - ingressPoints.add(SW3_ETH1); | ||
286 | - ingressPoints.add(SW4_ETH1); | ||
287 | - | ||
288 | - MultiPointToSinglePointIntent intent = | ||
289 | - new MultiPointToSinglePointIntent(APPID, | ||
290 | - selectorBuilder.build(), treatmentBuilder.build(), | ||
291 | - ingressPoints, SW1_ETH1); | ||
292 | - | ||
293 | - // Set up test expectation | ||
294 | - reset(intentService); | ||
295 | - // Setup the expected intents | ||
296 | - IntentOperations.Builder builder = IntentOperations.builder(APPID); | ||
297 | - builder.addSubmitOperation(intent); | ||
298 | - intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
299 | - builder.build())); | ||
300 | - replay(intentService); | ||
301 | - | ||
302 | - // Call the processRouteUpdates() method in Router class | ||
303 | - intentSynchronizer.leaderChanged(true); | ||
304 | - TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
305 | - RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE, | ||
306 | - routeEntry); | ||
307 | - router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate)); | ||
308 | - | ||
309 | - // Verify | ||
310 | - assertEquals(router.getRoutes4().size(), 1); | ||
311 | - assertTrue(router.getRoutes4().contains(routeEntry)); | ||
312 | - assertEquals(intentSynchronizer.getRouteIntents().size(), 1); | ||
313 | - Intent firstIntent = | ||
314 | - intentSynchronizer.getRouteIntents().iterator().next(); | ||
315 | - IntentKey firstIntentKey = new IntentKey(firstIntent); | ||
316 | - IntentKey intentKey = new IntentKey(intent); | ||
317 | - assertTrue(firstIntentKey.equals(intentKey)); | ||
318 | - verify(intentService); | ||
319 | - } | ||
320 | - | ||
321 | - /** | ||
322 | - * This method tests adding a route entry. | ||
323 | - */ | ||
324 | - @Test | ||
325 | - public void testRouteAddWithVlan() throws TestUtilsException { | ||
326 | - // Construct a route entry | ||
327 | - RouteEntry routeEntry = new RouteEntry( | ||
328 | - Ip4Prefix.valueOf("3.3.3.0/24"), | ||
329 | - Ip4Address.valueOf("192.168.40.1")); | ||
330 | - | ||
331 | - // Construct a MultiPointToSinglePointIntent intent | ||
332 | - TrafficSelector.Builder selectorBuilder = | ||
333 | - DefaultTrafficSelector.builder(); | ||
334 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4) | ||
335 | - .matchIPDst(routeEntry.prefix()) | ||
336 | - .matchVlanId(VlanId.ANY); | ||
337 | - | ||
338 | - TrafficTreatment.Builder treatmentBuilder = | ||
339 | - DefaultTrafficTreatment.builder(); | ||
340 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) | ||
341 | - .setVlanId(VlanId.vlanId((short) 1)); | ||
342 | - | ||
343 | - Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>(); | ||
344 | - ingressPoints.add(SW1_ETH1); | ||
345 | - ingressPoints.add(SW2_ETH1); | ||
346 | - ingressPoints.add(SW3_ETH1); | ||
347 | - | ||
348 | - MultiPointToSinglePointIntent intent = | ||
349 | - new MultiPointToSinglePointIntent(APPID, | ||
350 | - selectorBuilder.build(), treatmentBuilder.build(), | ||
351 | - ingressPoints, SW4_ETH1); | ||
352 | - | ||
353 | - // Set up test expectation | ||
354 | - reset(intentService); | ||
355 | - // Setup the expected intents | ||
356 | - IntentOperations.Builder builder = IntentOperations.builder(APPID); | ||
357 | - builder.addSubmitOperation(intent); | ||
358 | - intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
359 | - builder.build())); | ||
360 | - replay(intentService); | ||
361 | - | ||
362 | - // Call the processRouteUpdates() method in Router class | ||
363 | - intentSynchronizer.leaderChanged(true); | ||
364 | - TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
365 | - RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE, | ||
366 | - routeEntry); | ||
367 | - router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate)); | ||
368 | - | ||
369 | - // Verify | ||
370 | - assertEquals(router.getRoutes4().size(), 1); | ||
371 | - assertTrue(router.getRoutes4().contains(routeEntry)); | ||
372 | - assertEquals(intentSynchronizer.getRouteIntents().size(), 1); | ||
373 | - Intent firstIntent = | ||
374 | - intentSynchronizer.getRouteIntents().iterator().next(); | ||
375 | - IntentKey firstIntentKey = new IntentKey(firstIntent); | ||
376 | - IntentKey intentKey = new IntentKey(intent); | ||
377 | - assertTrue(firstIntentKey.equals(intentKey)); | ||
378 | - verify(intentService); | ||
379 | - } | ||
380 | - | ||
381 | - /** | ||
382 | - * This method tests updating a route entry. | ||
383 | - * | ||
384 | - * @throws TestUtilsException | ||
385 | - */ | ||
386 | - @Test | ||
387 | - public void testRouteUpdate() throws TestUtilsException { | ||
388 | - // Firstly add a route | ||
389 | - testRouteAdd(); | ||
390 | - | ||
391 | - Intent addedIntent = | ||
392 | - intentSynchronizer.getRouteIntents().iterator().next(); | ||
393 | - | ||
394 | - // Start to construct a new route entry and new intent | ||
395 | - RouteEntry routeEntryUpdate = new RouteEntry( | ||
396 | - Ip4Prefix.valueOf("1.1.1.0/24"), | ||
397 | - Ip4Address.valueOf("192.168.20.1")); | ||
398 | - | ||
399 | - // Construct a new MultiPointToSinglePointIntent intent | ||
400 | - TrafficSelector.Builder selectorBuilderNew = | ||
401 | - DefaultTrafficSelector.builder(); | ||
402 | - selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( | ||
403 | - routeEntryUpdate.prefix()); | ||
404 | - | ||
405 | - TrafficTreatment.Builder treatmentBuilderNew = | ||
406 | - DefaultTrafficTreatment.builder(); | ||
407 | - treatmentBuilderNew.setEthDst(MacAddress.valueOf("00:00:00:00:00:02")); | ||
408 | - | ||
409 | - | ||
410 | - Set<ConnectPoint> ingressPointsNew = new HashSet<ConnectPoint>(); | ||
411 | - ingressPointsNew.add(SW1_ETH1); | ||
412 | - ingressPointsNew.add(SW3_ETH1); | ||
413 | - ingressPointsNew.add(SW4_ETH1); | ||
414 | - | ||
415 | - MultiPointToSinglePointIntent intentNew = | ||
416 | - new MultiPointToSinglePointIntent(APPID, | ||
417 | - selectorBuilderNew.build(), | ||
418 | - treatmentBuilderNew.build(), | ||
419 | - ingressPointsNew, SW2_ETH1); | ||
420 | - | ||
421 | - // Set up test expectation | ||
422 | - reset(intentService); | ||
423 | - // Setup the expected intents | ||
424 | - IntentOperations.Builder builder = IntentOperations.builder(APPID); | ||
425 | - builder.addWithdrawOperation(addedIntent.id()); | ||
426 | - intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
427 | - builder.build())); | ||
428 | - builder = IntentOperations.builder(APPID); | ||
429 | - builder.addSubmitOperation(intentNew); | ||
430 | - intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
431 | - builder.build())); | ||
432 | - replay(intentService); | ||
433 | - | ||
434 | - // Call the processRouteUpdates() method in Router class | ||
435 | - intentSynchronizer.leaderChanged(true); | ||
436 | - TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
437 | - RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE, | ||
438 | - routeEntryUpdate); | ||
439 | - router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate)); | ||
440 | - | ||
441 | - // Verify | ||
442 | - assertEquals(router.getRoutes4().size(), 1); | ||
443 | - assertTrue(router.getRoutes4().contains(routeEntryUpdate)); | ||
444 | - assertEquals(intentSynchronizer.getRouteIntents().size(), 1); | ||
445 | - Intent firstIntent = | ||
446 | - intentSynchronizer.getRouteIntents().iterator().next(); | ||
447 | - IntentKey firstIntentKey = new IntentKey(firstIntent); | ||
448 | - IntentKey intentNewKey = new IntentKey(intentNew); | ||
449 | - assertTrue(firstIntentKey.equals(intentNewKey)); | ||
450 | - verify(intentService); | ||
451 | - } | ||
452 | - | ||
453 | - /** | ||
454 | - * This method tests deleting a route entry. | ||
455 | - */ | ||
456 | - @Test | ||
457 | - public void testRouteDelete() throws TestUtilsException { | ||
458 | - // Firstly add a route | ||
459 | - testRouteAdd(); | ||
460 | - | ||
461 | - Intent addedIntent = | ||
462 | - intentSynchronizer.getRouteIntents().iterator().next(); | ||
463 | - | ||
464 | - // Construct the existing route entry | ||
465 | - RouteEntry routeEntry = new RouteEntry( | ||
466 | - Ip4Prefix.valueOf("1.1.1.0/24"), | ||
467 | - Ip4Address.valueOf("192.168.10.1")); | ||
468 | - | ||
469 | - // Set up expectation | ||
470 | - reset(intentService); | ||
471 | - // Setup the expected intents | ||
472 | - IntentOperations.Builder builder = IntentOperations.builder(APPID); | ||
473 | - builder.addWithdrawOperation(addedIntent.id()); | ||
474 | - intentService.execute(TestIntentServiceHelper.eqExceptId( | ||
475 | - builder.build())); | ||
476 | - replay(intentService); | ||
477 | - | ||
478 | - // Call the processRouteUpdates() method in Router class | ||
479 | - intentSynchronizer.leaderChanged(true); | ||
480 | - TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
481 | - RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.DELETE, | ||
482 | - routeEntry); | ||
483 | - router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate)); | ||
484 | - | ||
485 | - // Verify | ||
486 | - assertEquals(router.getRoutes4().size(), 0); | ||
487 | - assertEquals(intentSynchronizer.getRouteIntents().size(), 0); | ||
488 | - verify(intentService); | ||
489 | - } | ||
490 | - | ||
491 | - /** | ||
492 | - * This method tests when the next hop of a route is the local BGP speaker. | ||
493 | - * | ||
494 | - * @throws TestUtilsException | ||
495 | - */ | ||
496 | - @Test | ||
497 | - public void testLocalRouteAdd() throws TestUtilsException { | ||
498 | - // Construct a route entry, the next hop is the local BGP speaker | ||
499 | - RouteEntry routeEntry = new RouteEntry( | ||
500 | - Ip4Prefix.valueOf("1.1.1.0/24"), | ||
501 | - Ip4Address.valueOf("0.0.0.0")); | ||
502 | - | ||
503 | - // Reset intentService to check whether the submit method is called | ||
504 | - reset(intentService); | ||
505 | - replay(intentService); | ||
506 | - | ||
507 | - // Call the processRouteUpdates() method in Router class | ||
508 | - intentSynchronizer.leaderChanged(true); | ||
509 | - TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
510 | - RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE, | ||
511 | - routeEntry); | ||
512 | - router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate)); | ||
513 | - | ||
514 | - // Verify | ||
515 | - assertEquals(router.getRoutes4().size(), 1); | ||
516 | - assertTrue(router.getRoutes4().contains(routeEntry)); | ||
517 | - assertEquals(intentSynchronizer.getRouteIntents().size(), 0); | ||
518 | - verify(intentService); | ||
519 | - } | ||
520 | -} |
1 | -/* | ||
2 | - * Copyright 2014 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.onosproject.sdnip; | ||
17 | - | ||
18 | -import com.google.common.collect.Sets; | ||
19 | -import org.easymock.IAnswer; | ||
20 | -import org.junit.Before; | ||
21 | -import org.junit.Test; | ||
22 | -import org.junit.experimental.categories.Category; | ||
23 | -import org.onlab.junit.IntegrationTest; | ||
24 | -import org.onlab.junit.TestUtils; | ||
25 | -import org.onlab.junit.TestUtils.TestUtilsException; | ||
26 | -import org.onlab.packet.Ethernet; | ||
27 | -import org.onlab.packet.Ip4Address; | ||
28 | -import org.onlab.packet.Ip4Prefix; | ||
29 | -import org.onlab.packet.IpAddress; | ||
30 | -import org.onlab.packet.IpPrefix; | ||
31 | -import org.onlab.packet.MacAddress; | ||
32 | -import org.onlab.packet.VlanId; | ||
33 | -import org.onosproject.core.ApplicationId; | ||
34 | -import org.onosproject.net.ConnectPoint; | ||
35 | -import org.onosproject.net.DeviceId; | ||
36 | -import org.onosproject.net.PortNumber; | ||
37 | -import org.onosproject.net.flow.DefaultTrafficSelector; | ||
38 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
39 | -import org.onosproject.net.flow.TrafficSelector; | ||
40 | -import org.onosproject.net.flow.TrafficTreatment; | ||
41 | -import org.onosproject.net.host.HostService; | ||
42 | -import org.onosproject.net.host.InterfaceIpAddress; | ||
43 | -import org.onosproject.net.intent.AbstractIntentTest; | ||
44 | -import org.onosproject.net.intent.IntentService; | ||
45 | -import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
46 | -import org.onosproject.sdnip.config.BgpPeer; | ||
47 | -import org.onosproject.sdnip.config.Interface; | ||
48 | -import org.onosproject.sdnip.config.SdnIpConfigurationService; | ||
49 | - | ||
50 | -import java.nio.ByteBuffer; | ||
51 | -import java.util.ArrayList; | ||
52 | -import java.util.HashMap; | ||
53 | -import java.util.HashSet; | ||
54 | -import java.util.List; | ||
55 | -import java.util.Map; | ||
56 | -import java.util.Random; | ||
57 | -import java.util.Set; | ||
58 | -import java.util.concurrent.CountDownLatch; | ||
59 | -import java.util.concurrent.TimeUnit; | ||
60 | - | ||
61 | -import static org.easymock.EasyMock.*; | ||
62 | -import static org.junit.Assert.assertEquals; | ||
63 | -import static org.junit.Assert.assertNotNull; | ||
64 | - | ||
65 | -/** | ||
66 | - * Integration tests for the SDN-IP application. | ||
67 | - * <p/> | ||
68 | - * The tests are very coarse-grained. They feed route updates in to | ||
69 | - * {@link Router} (simulating routes learnt from iBGP module inside SDN-IP | ||
70 | - * application), then they check that the correct intents are created and | ||
71 | - * submitted to the intent service. The entire route processing logic of | ||
72 | - * Router class is tested. | ||
73 | - */ | ||
74 | -@Category(IntegrationTest.class) | ||
75 | -public class SdnIpTest extends AbstractIntentTest { | ||
76 | - private static final int MAC_ADDRESS_LENGTH = 6; | ||
77 | - private static final int MIN_PREFIX_LENGTH = 1; | ||
78 | - private static final int MAX_PREFIX_LENGTH = 32; | ||
79 | - | ||
80 | - private IntentSynchronizer intentSynchronizer; | ||
81 | - static Router router; | ||
82 | - | ||
83 | - private SdnIpConfigurationService sdnIpConfigService; | ||
84 | - private InterfaceService interfaceService; | ||
85 | - private HostService hostService; | ||
86 | - private IntentService intentService; | ||
87 | - | ||
88 | - private Map<IpAddress, BgpPeer> bgpPeers; | ||
89 | - | ||
90 | - private Random random; | ||
91 | - | ||
92 | - static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
93 | - DeviceId.deviceId("of:0000000000000001"), | ||
94 | - PortNumber.portNumber(1)); | ||
95 | - | ||
96 | - static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
97 | - DeviceId.deviceId("of:0000000000000002"), | ||
98 | - PortNumber.portNumber(1)); | ||
99 | - | ||
100 | - static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
101 | - DeviceId.deviceId("of:0000000000000003"), | ||
102 | - PortNumber.portNumber(1)); | ||
103 | - | ||
104 | - private static final ApplicationId APPID = new ApplicationId() { | ||
105 | - @Override | ||
106 | - public short id() { | ||
107 | - return 1; | ||
108 | - } | ||
109 | - | ||
110 | - @Override | ||
111 | - public String name() { | ||
112 | - return "SDNIP"; | ||
113 | - } | ||
114 | - }; | ||
115 | - | ||
116 | - @Before | ||
117 | - public void setUp() throws Exception { | ||
118 | - super.setUp(); | ||
119 | - | ||
120 | - setUpInterfaceService(); | ||
121 | - setUpSdnIpConfigService(); | ||
122 | - | ||
123 | - hostService = new TestHostService(); | ||
124 | - intentService = createMock(IntentService.class); | ||
125 | - random = new Random(); | ||
126 | - | ||
127 | - intentSynchronizer = new IntentSynchronizer(APPID, intentService, | ||
128 | - sdnIpConfigService, | ||
129 | - interfaceService); | ||
130 | - router = new Router(intentSynchronizer, hostService); | ||
131 | - } | ||
132 | - | ||
133 | - /** | ||
134 | - * Sets up InterfaceService and virtual {@link Interface}s. | ||
135 | - */ | ||
136 | - private void setUpInterfaceService() { | ||
137 | - | ||
138 | - interfaceService = createMock(InterfaceService.class); | ||
139 | - | ||
140 | - Set<Interface> interfaces = Sets.newHashSet(); | ||
141 | - | ||
142 | - Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet(); | ||
143 | - interfaceIpAddresses1.add(new InterfaceIpAddress( | ||
144 | - IpAddress.valueOf("192.168.10.101"), | ||
145 | - IpPrefix.valueOf("192.168.10.0/24"))); | ||
146 | - Interface sw1Eth1 = new Interface(SW1_ETH1, | ||
147 | - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | ||
148 | - VlanId.NONE); | ||
149 | - interfaces.add(sw1Eth1); | ||
150 | - | ||
151 | - Set<InterfaceIpAddress> interfaceIpAddresses2 = Sets.newHashSet(); | ||
152 | - interfaceIpAddresses2.add(new InterfaceIpAddress( | ||
153 | - IpAddress.valueOf("192.168.20.101"), | ||
154 | - IpPrefix.valueOf("192.168.20.0/24"))); | ||
155 | - Interface sw2Eth1 = new Interface(SW2_ETH1, | ||
156 | - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
157 | - VlanId.NONE); | ||
158 | - interfaces.add(sw2Eth1); | ||
159 | - | ||
160 | - Set<InterfaceIpAddress> interfaceIpAddresses3 = Sets.newHashSet(); | ||
161 | - interfaceIpAddresses3.add(new InterfaceIpAddress( | ||
162 | - IpAddress.valueOf("192.168.30.101"), | ||
163 | - IpPrefix.valueOf("192.168.30.0/24"))); | ||
164 | - Interface sw3Eth1 = new Interface(SW3_ETH1, | ||
165 | - interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"), | ||
166 | - VlanId.NONE); | ||
167 | - interfaces.add(sw3Eth1); | ||
168 | - | ||
169 | - expect(interfaceService.getInterface(SW1_ETH1)).andReturn( | ||
170 | - sw1Eth1).anyTimes(); | ||
171 | - expect(interfaceService.getInterface(SW2_ETH1)).andReturn( | ||
172 | - sw2Eth1).anyTimes(); | ||
173 | - expect(interfaceService.getInterface(SW3_ETH1)).andReturn( | ||
174 | - sw3Eth1).anyTimes(); | ||
175 | - | ||
176 | - expect(interfaceService.getInterfaces()).andReturn( | ||
177 | - interfaces).anyTimes(); | ||
178 | - replay(interfaceService); | ||
179 | - } | ||
180 | - | ||
181 | - /** | ||
182 | - * Sets up SdnIpConfigService and BGP peers in external networks. | ||
183 | - */ | ||
184 | - private void setUpSdnIpConfigService() { | ||
185 | - | ||
186 | - sdnIpConfigService = createMock(SdnIpConfigurationService.class); | ||
187 | - | ||
188 | - bgpPeers = new HashMap<>(); | ||
189 | - | ||
190 | - String peerSw1Eth1 = "192.168.10.1"; | ||
191 | - bgpPeers.put(IpAddress.valueOf(peerSw1Eth1), | ||
192 | - new BgpPeer("00:00:00:00:00:00:00:01", 1, peerSw1Eth1)); | ||
193 | - | ||
194 | - String peer1Sw2Eth1 = "192.168.20.1"; | ||
195 | - bgpPeers.put(IpAddress.valueOf(peer1Sw2Eth1), | ||
196 | - new BgpPeer("00:00:00:00:00:00:00:02", 1, peer1Sw2Eth1)); | ||
197 | - | ||
198 | - String peer2Sw2Eth1 = "192.168.30.1"; | ||
199 | - bgpPeers.put(IpAddress.valueOf(peer2Sw2Eth1), | ||
200 | - new BgpPeer("00:00:00:00:00:00:00:03", 1, peer2Sw2Eth1)); | ||
201 | - | ||
202 | - expect(sdnIpConfigService.getBgpPeers()).andReturn(bgpPeers).anyTimes(); | ||
203 | - replay(sdnIpConfigService); | ||
204 | - } | ||
205 | - | ||
206 | - /** | ||
207 | - * Tests adding a set of routes into {@link Router}. | ||
208 | - * <p/> | ||
209 | - * Random routes are generated and fed in to the route processing | ||
210 | - * logic (via processRouteAdd in Router class). We check that the correct | ||
211 | - * intents are generated and submitted to our mock intent service. | ||
212 | - * | ||
213 | - * @throws InterruptedException if interrupted while waiting on a latch | ||
214 | - * @throws TestUtilsException if exceptions when using TestUtils | ||
215 | - */ | ||
216 | - @Test | ||
217 | - public void testAddRoutes() throws InterruptedException, TestUtilsException { | ||
218 | - int numRoutes = 100; | ||
219 | - | ||
220 | - final CountDownLatch latch = new CountDownLatch(numRoutes); | ||
221 | - | ||
222 | - List<RouteUpdate> routeUpdates = generateRouteUpdates(numRoutes); | ||
223 | - | ||
224 | - // Set up expectation | ||
225 | - reset(intentService); | ||
226 | - | ||
227 | - for (RouteUpdate update : routeUpdates) { | ||
228 | - IpAddress nextHopAddress = update.routeEntry().nextHop(); | ||
229 | - | ||
230 | - // Find out the egress ConnectPoint | ||
231 | - ConnectPoint egressConnectPoint = getConnectPoint(nextHopAddress); | ||
232 | - | ||
233 | - MultiPointToSinglePointIntent intent = getIntentForUpdate(update, | ||
234 | - generateMacAddress(nextHopAddress), | ||
235 | - egressConnectPoint); | ||
236 | - intentService.submit(TestIntentServiceHelper.eqExceptId(intent)); | ||
237 | - | ||
238 | - expectLastCall().andAnswer(new IAnswer<Object>() { | ||
239 | - @Override | ||
240 | - public Object answer() throws Throwable { | ||
241 | - latch.countDown(); | ||
242 | - return null; | ||
243 | - } | ||
244 | - }).once(); | ||
245 | - } | ||
246 | - | ||
247 | - replay(intentService); | ||
248 | - | ||
249 | - intentSynchronizer.leaderChanged(true); | ||
250 | - TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
251 | - | ||
252 | - // Add route updates | ||
253 | - router.processRouteUpdates(routeUpdates); | ||
254 | - | ||
255 | - latch.await(5000, TimeUnit.MILLISECONDS); | ||
256 | - | ||
257 | - assertEquals(router.getRoutes4().size(), numRoutes); | ||
258 | - assertEquals(intentSynchronizer.getRouteIntents().size(), | ||
259 | - numRoutes); | ||
260 | - | ||
261 | - verify(intentService); | ||
262 | - } | ||
263 | - | ||
264 | - /** | ||
265 | - * Tests adding then deleting a set of routes from {@link Router}. | ||
266 | - * <p/> | ||
267 | - * Random routes are generated and fed in to the route processing | ||
268 | - * logic (via processRouteAdd in Router class), and we check that the | ||
269 | - * correct intents are generated. We then delete the entire set of routes | ||
270 | - * (by feeding updates to processRouteDelete), and check that the correct | ||
271 | - * intents are withdrawn from the intent service. | ||
272 | - * | ||
273 | - * @throws InterruptedException if interrupted while waiting on a latch | ||
274 | - * @throws TestUtilsException exceptions when using TestUtils | ||
275 | - */ | ||
276 | - @Test | ||
277 | - public void testDeleteRoutes() throws InterruptedException, TestUtilsException { | ||
278 | - int numRoutes = 100; | ||
279 | - List<RouteUpdate> routeUpdates = generateRouteUpdates(numRoutes); | ||
280 | - | ||
281 | - final CountDownLatch installCount = new CountDownLatch(numRoutes); | ||
282 | - final CountDownLatch deleteCount = new CountDownLatch(numRoutes); | ||
283 | - | ||
284 | - // Set up expectation | ||
285 | - reset(intentService); | ||
286 | - | ||
287 | - for (RouteUpdate update : routeUpdates) { | ||
288 | - IpAddress nextHopAddress = update.routeEntry().nextHop(); | ||
289 | - | ||
290 | - // Find out the egress ConnectPoint | ||
291 | - ConnectPoint egressConnectPoint = getConnectPoint(nextHopAddress); | ||
292 | - MultiPointToSinglePointIntent intent = getIntentForUpdate(update, | ||
293 | - generateMacAddress(nextHopAddress), | ||
294 | - egressConnectPoint); | ||
295 | - intentService.submit(TestIntentServiceHelper.eqExceptId(intent)); | ||
296 | - expectLastCall().andAnswer(new IAnswer<Object>() { | ||
297 | - @Override | ||
298 | - public Object answer() throws Throwable { | ||
299 | - installCount.countDown(); | ||
300 | - return null; | ||
301 | - } | ||
302 | - }).once(); | ||
303 | - intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent)); | ||
304 | - expectLastCall().andAnswer(new IAnswer<Object>() { | ||
305 | - @Override | ||
306 | - public Object answer() throws Throwable { | ||
307 | - deleteCount.countDown(); | ||
308 | - return null; | ||
309 | - } | ||
310 | - }).once(); | ||
311 | - } | ||
312 | - | ||
313 | - replay(intentService); | ||
314 | - | ||
315 | - intentSynchronizer.leaderChanged(true); | ||
316 | - TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | ||
317 | - | ||
318 | - // Send the add updates first | ||
319 | - router.processRouteUpdates(routeUpdates); | ||
320 | - | ||
321 | - // Give some time to let the intents be submitted | ||
322 | - installCount.await(5000, TimeUnit.MILLISECONDS); | ||
323 | - | ||
324 | - // Send the DELETE updates | ||
325 | - List<RouteUpdate> deleteRouteUpdates = new ArrayList<>(); | ||
326 | - for (RouteUpdate update : routeUpdates) { | ||
327 | - RouteUpdate deleteUpdate = new RouteUpdate(RouteUpdate.Type.DELETE, | ||
328 | - update.routeEntry()); | ||
329 | - deleteRouteUpdates.add(deleteUpdate); | ||
330 | - } | ||
331 | - router.processRouteUpdates(deleteRouteUpdates); | ||
332 | - | ||
333 | - deleteCount.await(5000, TimeUnit.MILLISECONDS); | ||
334 | - | ||
335 | - assertEquals(0, router.getRoutes4().size()); | ||
336 | - assertEquals(0, intentSynchronizer.getRouteIntents().size()); | ||
337 | - verify(intentService); | ||
338 | - } | ||
339 | - | ||
340 | - /** | ||
341 | - * This methods generates random route updates. | ||
342 | - * | ||
343 | - * @param numRoutes the number of route updates to generate | ||
344 | - * @return a list of route update | ||
345 | - */ | ||
346 | - private List<RouteUpdate> generateRouteUpdates(int numRoutes) { | ||
347 | - List<RouteUpdate> routeUpdates = new ArrayList<>(numRoutes); | ||
348 | - | ||
349 | - Set<Ip4Prefix> prefixes = new HashSet<>(); | ||
350 | - | ||
351 | - for (int i = 0; i < numRoutes; i++) { | ||
352 | - Ip4Prefix prefix; | ||
353 | - do { | ||
354 | - // Generate a random prefix length between MIN_PREFIX_LENGTH | ||
355 | - // and MAX_PREFIX_LENGTH | ||
356 | - int prefixLength = random.nextInt( | ||
357 | - (MAX_PREFIX_LENGTH - MIN_PREFIX_LENGTH) + 1) | ||
358 | - + MIN_PREFIX_LENGTH; | ||
359 | - prefix = | ||
360 | - Ip4Prefix.valueOf(Ip4Address.valueOf(random.nextInt()), | ||
361 | - prefixLength); | ||
362 | - // We have to ensure we don't generate the same prefix twice | ||
363 | - // (this is quite easy to happen with small prefix lengths). | ||
364 | - } while (prefixes.contains(prefix)); | ||
365 | - | ||
366 | - prefixes.add(prefix); | ||
367 | - | ||
368 | - // Randomly select a peer to use as the next hop | ||
369 | - BgpPeer nextHop = null; | ||
370 | - int peerNumber = random.nextInt(sdnIpConfigService.getBgpPeers() | ||
371 | - .size()); | ||
372 | - int j = 0; | ||
373 | - for (BgpPeer peer : sdnIpConfigService.getBgpPeers().values()) { | ||
374 | - if (j++ == peerNumber) { | ||
375 | - nextHop = peer; | ||
376 | - break; | ||
377 | - } | ||
378 | - } | ||
379 | - | ||
380 | - assertNotNull(nextHop); | ||
381 | - | ||
382 | - RouteUpdate update = | ||
383 | - new RouteUpdate(RouteUpdate.Type.UPDATE, | ||
384 | - new RouteEntry(prefix, | ||
385 | - nextHop.ipAddress().getIp4Address())); | ||
386 | - | ||
387 | - routeUpdates.add(update); | ||
388 | - } | ||
389 | - | ||
390 | - return routeUpdates; | ||
391 | - } | ||
392 | - | ||
393 | - /** | ||
394 | - * Generates the MultiPointToSinglePointIntent that should be | ||
395 | - * submitted/withdrawn for a particular RouteUpdate. | ||
396 | - * | ||
397 | - * @param update the RouteUpdate to generate an intent for | ||
398 | - * @param nextHopMac a MAC address to use as the dst-mac for the intent | ||
399 | - * @param egressConnectPoint the outgoing ConnectPoint for the intent | ||
400 | - * @return the generated intent | ||
401 | - */ | ||
402 | - private MultiPointToSinglePointIntent getIntentForUpdate(RouteUpdate update, | ||
403 | - MacAddress nextHopMac, ConnectPoint egressConnectPoint) { | ||
404 | - IpPrefix ip4Prefix = update.routeEntry().prefix(); | ||
405 | - | ||
406 | - TrafficSelector.Builder selectorBuilder = | ||
407 | - DefaultTrafficSelector.builder(); | ||
408 | - | ||
409 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ip4Prefix); | ||
410 | - | ||
411 | - TrafficTreatment.Builder treatmentBuilder = | ||
412 | - DefaultTrafficTreatment.builder(); | ||
413 | - treatmentBuilder.setEthDst(nextHopMac); | ||
414 | - | ||
415 | - Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>(); | ||
416 | - for (Interface intf : interfaceService.getInterfaces()) { | ||
417 | - if (!intf.connectPoint().equals(egressConnectPoint)) { | ||
418 | - ConnectPoint srcPort = intf.connectPoint(); | ||
419 | - ingressPoints.add(srcPort); | ||
420 | - } | ||
421 | - } | ||
422 | - | ||
423 | - MultiPointToSinglePointIntent intent = | ||
424 | - new MultiPointToSinglePointIntent(APPID, | ||
425 | - selectorBuilder.build(), treatmentBuilder.build(), | ||
426 | - ingressPoints, egressConnectPoint); | ||
427 | - | ||
428 | - return intent; | ||
429 | - } | ||
430 | - | ||
431 | - /** | ||
432 | - * Generates a MAC address based on an IP address. | ||
433 | - * For the test we need MAC addresses but the actual values don't have any | ||
434 | - * meaning, so we'll just generate them based on the IP address. This means | ||
435 | - * we have a deterministic mapping from IP address to MAC address. | ||
436 | - * | ||
437 | - * @param ipAddress IP address used to generate a MAC address | ||
438 | - * @return generated MAC address | ||
439 | - */ | ||
440 | - static MacAddress generateMacAddress(IpAddress ipAddress) { | ||
441 | - byte[] macAddress = new byte[MAC_ADDRESS_LENGTH]; | ||
442 | - ByteBuffer bb = ByteBuffer.wrap(macAddress); | ||
443 | - | ||
444 | - // Put the IP address bytes into the lower four bytes of the MAC | ||
445 | - // address. Leave the first two bytes set to 0. | ||
446 | - bb.position(2); | ||
447 | - bb.put(ipAddress.toOctets()); | ||
448 | - | ||
449 | - return MacAddress.valueOf(bb.array()); | ||
450 | - } | ||
451 | - | ||
452 | - /** | ||
453 | - * Finds out the ConnectPoint for a BGP peer address. | ||
454 | - * | ||
455 | - * @param bgpPeerAddress the BGP peer address. | ||
456 | - */ | ||
457 | - private ConnectPoint getConnectPoint(IpAddress bgpPeerAddress) { | ||
458 | - ConnectPoint connectPoint = null; | ||
459 | - | ||
460 | - for (BgpPeer bgpPeer: bgpPeers.values()) { | ||
461 | - if (bgpPeer.ipAddress().equals(bgpPeerAddress)) { | ||
462 | - connectPoint = bgpPeer.connectPoint(); | ||
463 | - break; | ||
464 | - } | ||
465 | - } | ||
466 | - return connectPoint; | ||
467 | - } | ||
468 | -} |
1 | -/* | ||
2 | - * Copyright 2014 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.onosproject.sdnip; | ||
17 | - | ||
18 | -import java.util.HashSet; | ||
19 | -import java.util.Random; | ||
20 | -import java.util.Set; | ||
21 | -import java.util.concurrent.Executors; | ||
22 | -import java.util.concurrent.ScheduledExecutorService; | ||
23 | -import java.util.concurrent.TimeUnit; | ||
24 | - | ||
25 | -import org.onosproject.net.ConnectPoint; | ||
26 | -import org.onosproject.net.DefaultHost; | ||
27 | -import org.onosproject.net.DeviceId; | ||
28 | -import org.onosproject.net.Host; | ||
29 | -import org.onosproject.net.HostId; | ||
30 | -import org.onosproject.net.HostLocation; | ||
31 | -import org.onosproject.net.host.HostEvent; | ||
32 | -import org.onosproject.net.host.HostListener; | ||
33 | -import org.onosproject.net.host.HostService; | ||
34 | -import org.onosproject.net.host.PortAddresses; | ||
35 | -import org.onosproject.net.provider.ProviderId; | ||
36 | -import org.onosproject.sdnip.Router.InternalHostListener; | ||
37 | -import org.onlab.packet.IpAddress; | ||
38 | -import org.onlab.packet.MacAddress; | ||
39 | -import org.onlab.packet.VlanId; | ||
40 | - | ||
41 | -import com.google.common.collect.Sets; | ||
42 | - | ||
43 | -/** | ||
44 | - * Test version of the HostService which is used to simulate delays in | ||
45 | - * receiving ARP replies, as you would see in a real system due to the time | ||
46 | - * it takes to proxy ARP packets to/from the host. Requests are asynchronous, | ||
47 | - * and replies may come back to the requestor in a different order than the | ||
48 | - * requests were sent, which again you would expect to see in a real system. | ||
49 | - */ | ||
50 | -public class TestHostService implements HostService { | ||
51 | - | ||
52 | - /** | ||
53 | - * The maximum possible delay before an ARP reply is received. | ||
54 | - */ | ||
55 | - private static final int MAX_ARP_REPLY_DELAY = 30; // milliseconds | ||
56 | - | ||
57 | - /** | ||
58 | - * The probability that we already have the MAC address cached when the | ||
59 | - * caller calls {@link #getHostsByIp(IpAddress ipAddress)}. | ||
60 | - */ | ||
61 | - private static final float MAC_ALREADY_KNOWN_PROBABILITY = 0.3f; | ||
62 | - | ||
63 | - private final ScheduledExecutorService replyTaskExecutor; | ||
64 | - private final Random random; | ||
65 | - | ||
66 | - /** | ||
67 | - * Class constructor. | ||
68 | - */ | ||
69 | - public TestHostService() { | ||
70 | - replyTaskExecutor = Executors.newSingleThreadScheduledExecutor(); | ||
71 | - random = new Random(); | ||
72 | - } | ||
73 | - | ||
74 | - /** | ||
75 | - * Task used to reply to ARP requests from a different thread. Replies | ||
76 | - * usually come on a different thread in the real system, so we need to | ||
77 | - * ensure we test this behavior. | ||
78 | - */ | ||
79 | - private class ReplyTask implements Runnable { | ||
80 | - private HostListener listener; | ||
81 | - private IpAddress ipAddress; | ||
82 | - | ||
83 | - /** | ||
84 | - * Class constructor. | ||
85 | - * | ||
86 | - * @param listener the client who requests and waits the MAC address | ||
87 | - * @param ipAddress the target IP address of the request | ||
88 | - */ | ||
89 | - public ReplyTask(InternalHostListener listener, | ||
90 | - IpAddress ipAddress) { | ||
91 | - this.listener = listener; | ||
92 | - this.ipAddress = ipAddress; | ||
93 | - } | ||
94 | - | ||
95 | - @Override | ||
96 | - public void run() { | ||
97 | - Host host = getHostsByIp(ipAddress).iterator().next(); | ||
98 | - HostEvent hostevent = | ||
99 | - new HostEvent(HostEvent.Type.HOST_ADDED, host); | ||
100 | - listener.event(hostevent); | ||
101 | - } | ||
102 | - } | ||
103 | - | ||
104 | - @Override | ||
105 | - public Set<Host> getHostsByIp(IpAddress ipAddress) { | ||
106 | - float replyChance = random.nextFloat(); | ||
107 | - | ||
108 | - // We don't care what the attachment point is in the test, | ||
109 | - // so for all the hosts, we use a same ConnectPoint. | ||
110 | - Host host = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
111 | - SdnIpTest.generateMacAddress(ipAddress), VlanId.NONE, | ||
112 | - new HostLocation(SdnIpTest.SW1_ETH1, 1), | ||
113 | - Sets.newHashSet(ipAddress)); | ||
114 | - | ||
115 | - if (replyChance < MAC_ALREADY_KNOWN_PROBABILITY) { | ||
116 | - // Some percentage of the time we already know the MAC address, so | ||
117 | - // we reply directly when the requestor asks for the MAC address | ||
118 | - return Sets.newHashSet(host); | ||
119 | - } | ||
120 | - return new HashSet<Host>(); | ||
121 | - } | ||
122 | - | ||
123 | - @Override | ||
124 | - public void startMonitoringIp(IpAddress ipAddress) { | ||
125 | - | ||
126 | - // Randomly select an amount of time to delay the reply coming back to | ||
127 | - int delay = random.nextInt(MAX_ARP_REPLY_DELAY); | ||
128 | - ReplyTask replyTask = new ReplyTask( | ||
129 | - (SdnIpTest.router.new InternalHostListener()), ipAddress); | ||
130 | - replyTaskExecutor.schedule(replyTask, delay, TimeUnit.MILLISECONDS); | ||
131 | - } | ||
132 | - | ||
133 | - @Override | ||
134 | - public int getHostCount() { | ||
135 | - return 0; | ||
136 | - } | ||
137 | - | ||
138 | - @Override | ||
139 | - public Iterable<Host> getHosts() { | ||
140 | - return null; | ||
141 | - } | ||
142 | - | ||
143 | - @Override | ||
144 | - public Host getHost(HostId hostId) { | ||
145 | - return null; | ||
146 | - } | ||
147 | - | ||
148 | - @Override | ||
149 | - public Set<Host> getHostsByVlan(VlanId vlanId) { | ||
150 | - return null; | ||
151 | - } | ||
152 | - | ||
153 | - @Override | ||
154 | - public Set<Host> getHostsByMac(MacAddress mac) { | ||
155 | - return null; | ||
156 | - } | ||
157 | - | ||
158 | - @Override | ||
159 | - public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { | ||
160 | - return null; | ||
161 | - } | ||
162 | - | ||
163 | - @Override | ||
164 | - public Set<Host> getConnectedHosts(DeviceId deviceId) { | ||
165 | - return null; | ||
166 | - } | ||
167 | - | ||
168 | - @Override | ||
169 | - public void stopMonitoringIp(IpAddress ip) { | ||
170 | - | ||
171 | - } | ||
172 | - | ||
173 | - @Override | ||
174 | - public void requestMac(IpAddress ip) { | ||
175 | - | ||
176 | - } | ||
177 | - | ||
178 | - @Override | ||
179 | - public Set<PortAddresses> getAddressBindings() { | ||
180 | - return null; | ||
181 | - } | ||
182 | - | ||
183 | - @Override | ||
184 | - public Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint) { | ||
185 | - return null; | ||
186 | - } | ||
187 | - | ||
188 | - @Override | ||
189 | - public void addListener(HostListener listener) { | ||
190 | - | ||
191 | - } | ||
192 | - | ||
193 | - @Override | ||
194 | - public void removeListener(HostListener listener) { | ||
195 | - | ||
196 | - } | ||
197 | - | ||
198 | -} |
... | @@ -216,6 +216,8 @@ | ... | @@ -216,6 +216,8 @@ |
216 | <feature>onos-app-proxyarp</feature> | 216 | <feature>onos-app-proxyarp</feature> |
217 | <feature>onos-app-config</feature> | 217 | <feature>onos-app-config</feature> |
218 | <bundle>mvn:org.onosproject/onos-app-sdnip/@ONOS-VERSION</bundle> | 218 | <bundle>mvn:org.onosproject/onos-app-sdnip/@ONOS-VERSION</bundle> |
219 | + <bundle>mvn:org.onosproject/onos-app-routing-api/@ONOS-VERSION</bundle> | ||
220 | + <bundle>mvn:org.onosproject/onos-app-routing/@ONOS-VERSION</bundle> | ||
219 | </feature> | 221 | </feature> |
220 | 222 | ||
221 | <feature name="onos-app-calendar" version="@FEATURE-VERSION" | 223 | <feature name="onos-app-calendar" version="@FEATURE-VERSION" | ... | ... |
-
Please register or login to post a comment