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
1085 additions
and
523 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 | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -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(); | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -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> | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -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( | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
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