Committed by
Gerrit Code Review
[ONOS-2263] - OVSDB -- Create the implementation of TunnelProvider using
OVSDB protocol. 1.Notify the Tunnel System when tunnel is added/updated/removed. Change-Id: I98d918a55dab77005531918ecb8864dfafbc0c42
Showing
5 changed files
with
354 additions
and
0 deletions
providers/ovsdb/tunnel/pom.xml
0 → 100644
1 | +<?xml version="1.0"?> | ||
2 | +<project | ||
3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
4 | + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
5 | + <modelVersion>4.0.0</modelVersion> | ||
6 | + | ||
7 | + <parent> | ||
8 | + <groupId>org.onosproject</groupId> | ||
9 | + <artifactId>onos-ovsdb-providers</artifactId> | ||
10 | + <version>1.3.0-SNAPSHOT</version> | ||
11 | + </parent> | ||
12 | + | ||
13 | + <artifactId>onos-ovsdb-provider-tunnel</artifactId> | ||
14 | + <packaging>bundle</packaging> | ||
15 | + | ||
16 | + <dependencies> | ||
17 | + <dependency> | ||
18 | + <groupId>org.easymock</groupId> | ||
19 | + <artifactId>easymock</artifactId> | ||
20 | + <scope>test</scope> | ||
21 | + </dependency> | ||
22 | + </dependencies> | ||
23 | + | ||
24 | +</project> |
providers/ovsdb/tunnel/src/main/java/org/onosproject/ovsdb/provider/tunnel/OvsdbTunnelProvider.java
0 → 100644
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.ovsdb.provider.tunnel; | ||
17 | + | ||
18 | +import static org.slf4j.LoggerFactory.getLogger; | ||
19 | + | ||
20 | +import org.apache.felix.scr.annotations.Activate; | ||
21 | +import org.apache.felix.scr.annotations.Component; | ||
22 | +import org.apache.felix.scr.annotations.Deactivate; | ||
23 | +import org.apache.felix.scr.annotations.Reference; | ||
24 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
25 | +import org.apache.felix.scr.annotations.Service; | ||
26 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
27 | +import org.onosproject.incubator.net.tunnel.TunnelDescription; | ||
28 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
29 | +import org.onosproject.incubator.net.tunnel.TunnelProvider; | ||
30 | +import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry; | ||
31 | +import org.onosproject.incubator.net.tunnel.TunnelProviderService; | ||
32 | +import org.onosproject.incubator.net.tunnel.TunnelService; | ||
33 | +import org.onosproject.net.ElementId; | ||
34 | +import org.onosproject.net.Path; | ||
35 | +import org.onosproject.net.provider.AbstractProvider; | ||
36 | +import org.onosproject.net.provider.ProviderId; | ||
37 | +import org.slf4j.Logger; | ||
38 | + | ||
39 | +/** | ||
40 | + * Provider which uses when tunnel added/removed. | ||
41 | + */ | ||
42 | +@Component(immediate = true) | ||
43 | +@Service | ||
44 | +public class OvsdbTunnelProvider extends AbstractProvider | ||
45 | + implements TunnelProvider { | ||
46 | + private final Logger log = getLogger(getClass()); | ||
47 | + | ||
48 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
49 | + protected TunnelProviderRegistry providerRegistry; | ||
50 | + | ||
51 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
52 | + protected TunnelService tunnelService; | ||
53 | + | ||
54 | + private TunnelProviderService providerService; | ||
55 | + | ||
56 | + @Activate | ||
57 | + public void activate() { | ||
58 | + providerService = providerRegistry.register(this); | ||
59 | + log.info("Started"); | ||
60 | + } | ||
61 | + | ||
62 | + @Deactivate | ||
63 | + public void deactivate() { | ||
64 | + providerRegistry.unregister(this); | ||
65 | + providerService = null; | ||
66 | + log.info("Stopped"); | ||
67 | + } | ||
68 | + | ||
69 | + public OvsdbTunnelProvider() { | ||
70 | + super(new ProviderId("ovsdb", "org.onosproject.ovsdb.provider.tunnel")); | ||
71 | + } | ||
72 | + | ||
73 | + @Override | ||
74 | + public void setupTunnel(Tunnel tunnel, Path path) { | ||
75 | + // TODO: This will be implemented later. | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) { | ||
80 | + // TODO: This will be implemented later. | ||
81 | + } | ||
82 | + | ||
83 | + @Override | ||
84 | + public void releaseTunnel(Tunnel tunnel) { | ||
85 | + // TODO: This will be implemented later. | ||
86 | + } | ||
87 | + | ||
88 | + @Override | ||
89 | + public void releaseTunnel(ElementId srcElement, Tunnel tunnel) { | ||
90 | + // TODO: This will be implemented later. | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public void updateTunnel(Tunnel tunnel, Path path) { | ||
95 | + // TODO: This will be implemented later. | ||
96 | + } | ||
97 | + | ||
98 | + @Override | ||
99 | + public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) { | ||
100 | + // TODO: This will be implemented later. | ||
101 | + } | ||
102 | + | ||
103 | + @Override | ||
104 | + public TunnelId tunnelAdded(TunnelDescription tunnel) { | ||
105 | + return providerService.tunnelAdded(tunnel); | ||
106 | + } | ||
107 | + | ||
108 | + @Override | ||
109 | + public void tunnelRemoved(TunnelDescription tunnel) { | ||
110 | + providerService.tunnelRemoved(tunnel); | ||
111 | + } | ||
112 | + | ||
113 | + @Override | ||
114 | + public void tunnelUpdated(TunnelDescription tunnel) { | ||
115 | + providerService.tunnelUpdated(tunnel); | ||
116 | + } | ||
117 | + | ||
118 | + @Override | ||
119 | + public Tunnel tunnelQueryById(TunnelId tunnelId) { | ||
120 | + // TODO: This will be implemented later. | ||
121 | + return null; | ||
122 | + } | ||
123 | +} |
providers/ovsdb/tunnel/src/main/java/org/onosproject/ovsdb/provider/tunnel/package-info.java
0 → 100644
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 | + | ||
17 | +/** | ||
18 | + *Provider that uses ovsdb controller as a means of infrastructure tunnel discovery. | ||
19 | + * | ||
20 | + */ | ||
21 | +package org.onosproject.ovsdb.provider.tunnel; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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.ovsdb.provider.tunnel; | ||
17 | + | ||
18 | +import static org.junit.Assert.assertEquals; | ||
19 | +import static org.junit.Assert.assertNotNull; | ||
20 | + | ||
21 | +import java.util.ArrayList; | ||
22 | +import java.util.HashSet; | ||
23 | +import java.util.List; | ||
24 | +import java.util.Set; | ||
25 | + | ||
26 | +import org.junit.After; | ||
27 | +import org.junit.Before; | ||
28 | +import org.junit.Test; | ||
29 | +import org.onlab.packet.IpAddress; | ||
30 | +import org.onosproject.core.DefaultGroupId; | ||
31 | +import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription; | ||
32 | +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | ||
33 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
34 | +import org.onosproject.incubator.net.tunnel.TunnelDescription; | ||
35 | +import org.onosproject.incubator.net.tunnel.TunnelEndPoint; | ||
36 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
37 | +import org.onosproject.incubator.net.tunnel.TunnelName; | ||
38 | +import org.onosproject.incubator.net.tunnel.TunnelProvider; | ||
39 | +import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry; | ||
40 | +import org.onosproject.incubator.net.tunnel.TunnelProviderService; | ||
41 | +import org.onosproject.net.ConnectPoint; | ||
42 | +import org.onosproject.net.DefaultAnnotations; | ||
43 | +import org.onosproject.net.DefaultLink; | ||
44 | +import org.onosproject.net.DefaultPath; | ||
45 | +import org.onosproject.net.Link; | ||
46 | +import org.onosproject.net.SparseAnnotations; | ||
47 | +import org.onosproject.net.provider.AbstractProviderService; | ||
48 | +import org.onosproject.net.provider.ProviderId; | ||
49 | + | ||
50 | +/** | ||
51 | + * Test for ovsdb tunnel provider. | ||
52 | + */ | ||
53 | +public class OvsdbTunnelProviderTest { | ||
54 | + private final OvsdbTunnelProvider provider = new OvsdbTunnelProvider(); | ||
55 | + private final TestTunnelRegistry tunnelRegistry = new TestTunnelRegistry(); | ||
56 | + private TestTunnelProviderService providerService; | ||
57 | + | ||
58 | + @Before | ||
59 | + public void setUp() { | ||
60 | + provider.providerRegistry = tunnelRegistry; | ||
61 | + provider.activate(); | ||
62 | + } | ||
63 | + | ||
64 | + @Test | ||
65 | + public void basics() { | ||
66 | + assertNotNull("registration expected", providerService); | ||
67 | + assertEquals("incorrect provider", provider, providerService.provider()); | ||
68 | + } | ||
69 | + | ||
70 | + @Test | ||
71 | + public void testTunnelAdded() { | ||
72 | + TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress | ||
73 | + .valueOf("192.168.1.1")); | ||
74 | + TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress | ||
75 | + .valueOf("192.168.1.3")); | ||
76 | + SparseAnnotations annotations = DefaultAnnotations.builder() | ||
77 | + .set("bandwidth", "1024").build(); | ||
78 | + Link link = new DefaultLink( | ||
79 | + this.provider.id(), | ||
80 | + ConnectPoint.deviceConnectPoint("192.168.2.3/20"), | ||
81 | + ConnectPoint.deviceConnectPoint("192.168.2.4/30"), | ||
82 | + Link.Type.DIRECT); | ||
83 | + List<Link> links = new ArrayList<Link>(); | ||
84 | + links.add(link); | ||
85 | + TunnelDescription tunnel = new DefaultTunnelDescription( | ||
86 | + TunnelId.valueOf("1234"), | ||
87 | + src, | ||
88 | + dst, | ||
89 | + Tunnel.Type.VXLAN, | ||
90 | + new DefaultGroupId(0), | ||
91 | + this.provider.id(), | ||
92 | + TunnelName.tunnelName("tunnel12"), | ||
93 | + new DefaultPath(this.provider.id(), links, 0.3), | ||
94 | + annotations); | ||
95 | + provider.tunnelAdded(tunnel); | ||
96 | + assertEquals(1, providerService.tunnelSet.size()); | ||
97 | + } | ||
98 | + | ||
99 | + @Test | ||
100 | + public void testTunnelRemoved() { | ||
101 | + TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress | ||
102 | + .valueOf("192.168.1.1")); | ||
103 | + TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress | ||
104 | + .valueOf("192.168.1.3")); | ||
105 | + SparseAnnotations annotations = DefaultAnnotations.builder() | ||
106 | + .set("bandwidth", "1024").build(); | ||
107 | + Link link = new DefaultLink( | ||
108 | + this.provider.id(), | ||
109 | + ConnectPoint.deviceConnectPoint("192.168.2.3/20"), | ||
110 | + ConnectPoint.deviceConnectPoint("192.168.2.4/30"), | ||
111 | + Link.Type.DIRECT); | ||
112 | + List<Link> links = new ArrayList<Link>(); | ||
113 | + links.add(link); | ||
114 | + TunnelDescription tunnel = new DefaultTunnelDescription( | ||
115 | + TunnelId.valueOf("1234"), | ||
116 | + src, | ||
117 | + dst, | ||
118 | + Tunnel.Type.VXLAN, | ||
119 | + new DefaultGroupId(0), | ||
120 | + this.provider.id(), | ||
121 | + TunnelName.tunnelName("tunnel1"), | ||
122 | + new DefaultPath(this.provider.id(), links, 0.3), | ||
123 | + annotations); | ||
124 | + provider.tunnelRemoved(tunnel); | ||
125 | + assertEquals(0, providerService.tunnelSet.size()); | ||
126 | + } | ||
127 | + | ||
128 | + @After | ||
129 | + public void tearDown() { | ||
130 | + provider.deactivate(); | ||
131 | + provider.providerRegistry = null; | ||
132 | + } | ||
133 | + | ||
134 | + private class TestTunnelRegistry implements TunnelProviderRegistry { | ||
135 | + | ||
136 | + @Override | ||
137 | + public TunnelProviderService register(TunnelProvider provider) { | ||
138 | + providerService = new TestTunnelProviderService(provider); | ||
139 | + return providerService; | ||
140 | + } | ||
141 | + | ||
142 | + @Override | ||
143 | + public void unregister(TunnelProvider provider) { | ||
144 | + | ||
145 | + } | ||
146 | + | ||
147 | + @Override | ||
148 | + public Set<ProviderId> getProviders() { | ||
149 | + return null; | ||
150 | + } | ||
151 | + | ||
152 | + } | ||
153 | + | ||
154 | + private class TestTunnelProviderService | ||
155 | + extends AbstractProviderService<TunnelProvider> | ||
156 | + implements TunnelProviderService { | ||
157 | + Set<TunnelDescription> tunnelSet = new HashSet<TunnelDescription>(); | ||
158 | + | ||
159 | + protected TestTunnelProviderService(TunnelProvider provider) { | ||
160 | + super(provider); | ||
161 | + } | ||
162 | + | ||
163 | + @Override | ||
164 | + public TunnelId tunnelAdded(TunnelDescription tunnel) { | ||
165 | + tunnelSet.add(tunnel); | ||
166 | + return null; | ||
167 | + } | ||
168 | + | ||
169 | + @Override | ||
170 | + public void tunnelRemoved(TunnelDescription tunnel) { | ||
171 | + tunnelSet.remove(tunnel); | ||
172 | + } | ||
173 | + | ||
174 | + @Override | ||
175 | + public void tunnelUpdated(TunnelDescription tunnel) { | ||
176 | + | ||
177 | + } | ||
178 | + | ||
179 | + @Override | ||
180 | + public Tunnel tunnelQueryById(TunnelId tunnelId) { | ||
181 | + return null; | ||
182 | + } | ||
183 | + | ||
184 | + } | ||
185 | +} |
-
Please register or login to post a comment