Jonathan Hart
Committed by Gerrit Code Review

Remove old CordFabric app

Change-Id: Id8b22f3ab78adae6f09e94f54ec15bc743459cb2
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2015-2016 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.6.0-SNAPSHOT</version>
24 - <relativePath>../pom.xml</relativePath>
25 - </parent>
26 - <modelVersion>4.0.0</modelVersion>
27 -
28 - <artifactId>onos-app-cordfabric</artifactId>
29 -
30 - <packaging>bundle</packaging>
31 - <description>Simple fabric application for CORD</description>
32 -
33 - <properties>
34 - <onos.app.name>org.onosproject.cordfabric</onos.app.name>
35 - <onos.app.title>CORD Fabric App</onos.app.title>
36 - <onos.app.category>Traffic Steering</onos.app.category>
37 - <onos.app.url>http://onosproject.org</onos.app.url>
38 - <onos.app.readme>Simple fabric application for CORD.</onos.app.readme>
39 - <web.context>/onos/cordfabric</web.context>
40 - <api.version>1.0.0</api.version>
41 - <api.title>ONOS CORD Fabric REST API</api.title>
42 - <api.description>
43 - APIs for interacting with the CORD Fabric application.
44 - </api.description>
45 - <api.package>org.onosproject.cordfabric</api.package>
46 - </properties>
47 -
48 - <dependencies>
49 - <dependency>
50 - <groupId>org.onosproject</groupId>
51 - <artifactId>onos-cli</artifactId>
52 - <version>${project.version}</version>
53 - </dependency>
54 -
55 - <dependency>
56 - <groupId>org.apache.karaf.shell</groupId>
57 - <artifactId>org.apache.karaf.shell.console</artifactId>
58 - </dependency>
59 - <dependency>
60 - <groupId>org.onosproject</groupId>
61 - <artifactId>onos-rest</artifactId>
62 - <version>${project.version}</version>
63 - </dependency>
64 - <dependency>
65 - <groupId>org.onosproject</groupId>
66 - <artifactId>onlab-rest</artifactId>
67 - <version>${project.version}</version>
68 - </dependency>
69 - <dependency>
70 - <groupId>javax.ws.rs</groupId>
71 - <artifactId>javax.ws.rs-api</artifactId>
72 - <version>2.0.1</version>
73 - </dependency>
74 - <dependency>
75 - <groupId>org.glassfish.jersey.containers</groupId>
76 - <artifactId>jersey-container-servlet</artifactId>
77 - </dependency>
78 - <dependency>
79 - <groupId>com.fasterxml.jackson.core</groupId>
80 - <artifactId>jackson-databind</artifactId>
81 - </dependency>
82 -
83 - <dependency>
84 - <groupId>com.fasterxml.jackson.core</groupId>
85 - <artifactId>jackson-annotations</artifactId>
86 - </dependency>
87 -
88 - <dependency>
89 - <groupId>org.osgi</groupId>
90 - <artifactId>org.osgi.compendium</artifactId>
91 - </dependency>
92 - <dependency>
93 - <groupId>org.osgi</groupId>
94 - <artifactId>org.osgi.core</artifactId>
95 - </dependency>
96 - </dependencies>
97 -
98 - <build>
99 - <plugins>
100 - <plugin>
101 - <groupId>org.apache.felix</groupId>
102 - <artifactId>maven-bundle-plugin</artifactId>
103 - <extensions>true</extensions>
104 - <configuration>
105 - <instructions>
106 - <_wab>src/main/webapp/</_wab>
107 - <Include-Resource>
108 - WEB-INF/classes/apidoc/swagger.json=target/swagger.json,
109 - {maven-resources}
110 - </Include-Resource>
111 - <Bundle-SymbolicName>
112 - ${project.groupId}.${project.artifactId}
113 - </Bundle-SymbolicName>
114 - <Import-Package>
115 - org.slf4j,
116 - org.osgi.framework,
117 - javax.ws.rs,
118 - javax.ws.rs.core,
119 - org.glassfish.jersey,
120 - org.glassfish.jersey.servlet,
121 - com.fasterxml.jackson.databind,
122 - com.fasterxml.jackson.databind.node,
123 - org.apache.karaf.shell.commands,
124 - com.google.common.*,
125 - org.onlab.packet.*,
126 - org.onosproject.*,
127 - </Import-Package>
128 - <Web-ContextPath>${web.context}</Web-ContextPath>
129 - </instructions>
130 - </configuration>
131 - </plugin>
132 - </plugins>
133 - </build>
134 -</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 -
17 -package org.onosproject.cordfabric;
18 -
19 -import com.google.common.collect.HashMultimap;
20 -import com.google.common.collect.Multimap;
21 -import org.apache.felix.scr.annotations.Activate;
22 -import org.apache.felix.scr.annotations.Component;
23 -import org.apache.felix.scr.annotations.Deactivate;
24 -import org.apache.felix.scr.annotations.Reference;
25 -import org.apache.felix.scr.annotations.ReferenceCardinality;
26 -import org.apache.felix.scr.annotations.Service;
27 -import org.onlab.packet.Ethernet;
28 -import org.onlab.packet.IPv4;
29 -import org.onlab.packet.MacAddress;
30 -import org.onlab.packet.TpPort;
31 -import org.onlab.packet.VlanId;
32 -import org.onosproject.core.ApplicationId;
33 -import org.onosproject.core.CoreService;
34 -import org.onosproject.net.ConnectPoint;
35 -import org.onosproject.net.DeviceId;
36 -import org.onosproject.net.PortNumber;
37 -import org.onosproject.net.device.DeviceEvent;
38 -import org.onosproject.net.device.DeviceListener;
39 -import org.onosproject.net.device.DeviceService;
40 -import org.onosproject.net.flow.DefaultTrafficSelector;
41 -import org.onosproject.net.flow.DefaultTrafficTreatment;
42 -import org.onosproject.net.flow.TrafficSelector;
43 -import org.onosproject.net.flow.TrafficTreatment;
44 -import org.onosproject.net.flowobjective.DefaultForwardingObjective;
45 -import org.onosproject.net.flowobjective.FlowObjectiveService;
46 -import org.onosproject.net.flowobjective.ForwardingObjective;
47 -import org.onosproject.net.flowobjective.Objective;
48 -import org.onosproject.net.flowobjective.ObjectiveContext;
49 -import org.onosproject.net.flowobjective.ObjectiveError;
50 -import org.slf4j.Logger;
51 -import org.slf4j.LoggerFactory;
52 -
53 -import java.util.ArrayList;
54 -import java.util.Collection;
55 -import java.util.List;
56 -import java.util.stream.Collectors;
57 -
58 -import static com.google.common.base.Preconditions.checkArgument;
59 -import static com.google.common.base.Preconditions.checkNotNull;
60 -import static org.slf4j.LoggerFactory.getLogger;
61 -
62 -/**
63 - * CORD fabric application.
64 - */
65 -@Service
66 -@Component(immediate = true)
67 -public class CordFabricManager implements FabricService {
68 -
69 - private final Logger log = getLogger(getClass());
70 -
71 - private ApplicationId appId;
72 -
73 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
74 - protected CoreService coreService;
75 -
76 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
77 - protected FlowObjectiveService flowObjectiveService;
78 -
79 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
80 - protected DeviceService deviceService;
81 -
82 - private InternalDeviceListener deviceListener = new InternalDeviceListener();
83 -
84 - private static final int PRIORITY = 50000;
85 - private static final int TESTPRIO = 49999;
86 -
87 - private short radiusPort = 1812;
88 -
89 - private short ofPort = 6653;
90 -
91 - private DeviceId fabricDeviceId = DeviceId.deviceId("of:5e3e486e73000187");
92 -
93 - private final Multimap<VlanId, ConnectPoint> vlans = HashMultimap.create();
94 -
95 - //TODO make this configurable
96 - private boolean testMode = true;
97 -
98 -
99 - @Activate
100 - public void activate() {
101 - appId = coreService.registerApplication("org.onosproject.cordfabric");
102 -
103 - deviceService.addListener(deviceListener);
104 -
105 - if (deviceService.isAvailable(fabricDeviceId)) {
106 - setupDefaultFlows();
107 - }
108 -
109 - log.info("Started");
110 - }
111 -
112 - @Deactivate
113 - public void deactivate() {
114 - deviceService.removeListener(deviceListener);
115 -
116 - log.info("Stopped");
117 - }
118 -
119 - private void setupDefaultFlows() {
120 - TrafficSelector ofInBandMatchUp = DefaultTrafficSelector.builder()
121 - .matchEthType(Ethernet.TYPE_IPV4)
122 - .matchIPProtocol(IPv4.PROTOCOL_TCP)
123 - .matchTcpDst(TpPort.tpPort(ofPort))
124 - .matchInPort(PortNumber.portNumber(6))
125 - .build();
126 -
127 - TrafficSelector ofInBandMatchDown = DefaultTrafficSelector.builder()
128 - .matchEthType(Ethernet.TYPE_IPV4)
129 - .matchIPProtocol(IPv4.PROTOCOL_TCP)
130 - .matchTcpSrc(TpPort.tpPort(ofPort))
131 - .matchInPort(PortNumber.portNumber(1))
132 - .build();
133 -
134 - TrafficSelector oltMgmtUp = DefaultTrafficSelector.builder()
135 - .matchEthSrc(MacAddress.valueOf("00:0c:d5:00:01:01"))
136 - .matchInPort(PortNumber.portNumber(2))
137 - .build();
138 -
139 - TrafficSelector oltMgmtDown = DefaultTrafficSelector.builder()
140 - .matchEthDst(MacAddress.valueOf("00:0c:d5:00:01:01"))
141 - .matchInPort(PortNumber.portNumber(9))
142 - .build();
143 -
144 - TrafficTreatment up = DefaultTrafficTreatment.builder()
145 - .setOutput(PortNumber.portNumber(1))
146 - .build();
147 -
148 - TrafficTreatment down = DefaultTrafficTreatment.builder()
149 - .setOutput(PortNumber.portNumber(6))
150 - .build();
151 -
152 - TrafficSelector toRadius = DefaultTrafficSelector.builder()
153 - .matchInPort(PortNumber.portNumber(2))
154 - .matchEthType(Ethernet.TYPE_IPV4)
155 - .matchIPProtocol(IPv4.PROTOCOL_UDP)
156 - .matchUdpDst(TpPort.tpPort(radiusPort))
157 - .build();
158 -
159 - TrafficSelector fromRadius = DefaultTrafficSelector.builder()
160 - .matchInPort(PortNumber.portNumber(5))
161 - .matchEthType(Ethernet.TYPE_IPV4)
162 - .matchIPProtocol(IPv4.PROTOCOL_UDP)
163 - .matchUdpDst(TpPort.tpPort(radiusPort))
164 - .build();
165 -
166 - TrafficTreatment toOlt = DefaultTrafficTreatment.builder()
167 - .setOutput(PortNumber.portNumber(2))
168 - .build();
169 -
170 - TrafficTreatment toVolt = DefaultTrafficTreatment.builder()
171 - .setOutput(PortNumber.portNumber(9))
172 - .build();
173 -
174 - TrafficTreatment sentToRadius = DefaultTrafficTreatment.builder()
175 - .setOutput(PortNumber.portNumber(5))
176 - .build();
177 -
178 - TrafficTreatment testPort = DefaultTrafficTreatment.builder()
179 - .setOutput(PortNumber.portNumber(8))
180 - .build();
181 -
182 - ForwardingObjective ofTestPath = DefaultForwardingObjective.builder()
183 - .fromApp(appId)
184 - .makePermanent()
185 - .withFlag(ForwardingObjective.Flag.VERSATILE)
186 - .withPriority(TESTPRIO)
187 - .withSelector(
188 - DefaultTrafficSelector.builder()
189 - .matchInPort(PortNumber.portNumber(2))
190 - .build())
191 - .withTreatment(testPort)
192 - .add();
193 -
194 - ForwardingObjective radiusToServer = DefaultForwardingObjective.builder()
195 - .fromApp(appId)
196 - .makePermanent()
197 - .withFlag(ForwardingObjective.Flag.VERSATILE)
198 - .withPriority(PRIORITY)
199 - .withSelector(toRadius)
200 - .withTreatment(sentToRadius)
201 - .add();
202 -
203 - ForwardingObjective serverToRadius = DefaultForwardingObjective.builder()
204 - .fromApp(appId)
205 - .makePermanent()
206 - .withFlag(ForwardingObjective.Flag.VERSATILE)
207 - .withPriority(PRIORITY)
208 - .withSelector(fromRadius)
209 - .withTreatment(toOlt)
210 - .add();
211 -
212 -
213 -
214 - ForwardingObjective upCtrl = DefaultForwardingObjective.builder()
215 - .fromApp(appId)
216 - .makePermanent()
217 - .withFlag(ForwardingObjective.Flag.VERSATILE)
218 - .withPriority(PRIORITY)
219 - .withSelector(ofInBandMatchUp)
220 - .withTreatment(up)
221 - .add();
222 -
223 - ForwardingObjective downCtrl = DefaultForwardingObjective.builder()
224 - .fromApp(appId)
225 - .makePermanent()
226 - .withFlag(ForwardingObjective.Flag.VERSATILE)
227 - .withPriority(PRIORITY)
228 - .withSelector(ofInBandMatchDown)
229 - .withTreatment(down)
230 - .add();
231 -
232 - ForwardingObjective upOltMgmt = DefaultForwardingObjective.builder()
233 - .fromApp(appId)
234 - .makePermanent()
235 - .withFlag(ForwardingObjective.Flag.VERSATILE)
236 - .withPriority(PRIORITY)
237 - .withSelector(oltMgmtUp)
238 - .withTreatment(toVolt)
239 - .add();
240 -
241 - ForwardingObjective downOltMgmt = DefaultForwardingObjective.builder()
242 - .fromApp(appId)
243 - .makePermanent()
244 - .withFlag(ForwardingObjective.Flag.VERSATILE)
245 - .withPriority(PRIORITY)
246 - .withSelector(oltMgmtDown)
247 - .withTreatment(toOlt)
248 - .add();
249 -
250 - if (testMode) {
251 - flowObjectiveService.forward(fabricDeviceId, ofTestPath);
252 - }
253 -
254 - flowObjectiveService.forward(fabricDeviceId, upCtrl);
255 - flowObjectiveService.forward(fabricDeviceId, downCtrl);
256 - flowObjectiveService.forward(fabricDeviceId, radiusToServer);
257 - flowObjectiveService.forward(fabricDeviceId, serverToRadius);
258 - flowObjectiveService.forward(fabricDeviceId, upOltMgmt);
259 - flowObjectiveService.forward(fabricDeviceId, downOltMgmt);
260 - }
261 -
262 - @Override
263 - public void addVlan(FabricVlan vlan) {
264 - checkNotNull(vlan);
265 - checkArgument(vlan.ports().size() > 1);
266 - verifyPorts(vlan.ports());
267 -
268 - removeVlan(vlan.vlan());
269 -
270 - if (vlan.iptv()) {
271 - provisionIpTv();
272 - }
273 -
274 - vlan.ports().forEach(cp -> {
275 - if (vlans.put(vlan.vlan(), cp)) {
276 - addForwarding(vlan.vlan(), cp.deviceId(), cp.port(),
277 - vlan.ports().stream()
278 - .filter(p -> p != cp)
279 - .map(ConnectPoint::port)
280 - .collect(Collectors.toList()));
281 - }
282 - });
283 - }
284 -
285 - //FIXME: pass iptv vlan in here.
286 - private void provisionIpTv() {
287 - TrafficSelector ipTvUp = DefaultTrafficSelector.builder()
288 - .matchVlanId(VlanId.vlanId((short) 7))
289 - .matchInPort(PortNumber.portNumber(2))
290 - .build();
291 -
292 - TrafficTreatment ipTvActUp = DefaultTrafficTreatment.builder()
293 - .setOutput(PortNumber.portNumber(7)).build();
294 -
295 - TrafficSelector ipTvDown = DefaultTrafficSelector.builder()
296 - .matchVlanId(VlanId.vlanId((short) 7))
297 - .matchInPort(PortNumber.portNumber(7))
298 - .build();
299 -
300 - TrafficTreatment ipTvActDown = DefaultTrafficTreatment.builder()
301 - .setOutput(PortNumber.portNumber(2)).build();
302 -
303 - ForwardingObjective ipTvUpstream = DefaultForwardingObjective.builder()
304 - .fromApp(appId)
305 - .makePermanent()
306 - .withFlag(ForwardingObjective.Flag.VERSATILE)
307 - .withPriority(PRIORITY)
308 - .withSelector(ipTvUp)
309 - .withTreatment(ipTvActUp)
310 - .add();
311 -
312 - ForwardingObjective ipTvDownstream = DefaultForwardingObjective.builder()
313 - .fromApp(appId)
314 - .makePermanent()
315 - .withFlag(ForwardingObjective.Flag.VERSATILE)
316 - .withPriority(PRIORITY)
317 - .withSelector(ipTvDown)
318 - .withTreatment(ipTvActDown)
319 - .add();
320 -
321 - flowObjectiveService.forward(fabricDeviceId, ipTvUpstream);
322 - flowObjectiveService.forward(fabricDeviceId, ipTvDownstream);
323 - }
324 -
325 - @Override
326 - public void removeVlan(VlanId vlanId) {
327 - Collection<ConnectPoint> ports = vlans.removeAll(vlanId);
328 -
329 - ports.forEach(cp -> removeForwarding(vlanId, cp.deviceId(), cp.port(),
330 - ports.stream()
331 - .filter(p -> p != cp)
332 - .map(ConnectPoint::port)
333 - .collect(Collectors.toList())));
334 - }
335 -
336 - @Override
337 - public List<FabricVlan> getVlans() {
338 - List<FabricVlan> fVlans = new ArrayList<>();
339 - vlans.keySet().forEach(vlan -> fVlans.add(
340 - //FIXME: Very aweful but will fo for now
341 - new FabricVlan(vlan, vlans.get(vlan), vlan.toShort() == 201)));
342 - return fVlans;
343 - }
344 -
345 - private static void verifyPorts(List<ConnectPoint> ports) {
346 - DeviceId deviceId = ports.get(0).deviceId();
347 - for (ConnectPoint connectPoint : ports) {
348 - if (!connectPoint.deviceId().equals(deviceId)) {
349 - throw new IllegalArgumentException("Ports must all be on the same device");
350 - }
351 - }
352 - }
353 -
354 - private void addForwarding(VlanId vlanId, DeviceId deviceId, PortNumber inPort,
355 - List<PortNumber> outPorts) {
356 -
357 - TrafficSelector selector = DefaultTrafficSelector.builder()
358 - .matchVlanId(vlanId)
359 - .matchInPort(inPort)
360 - .build();
361 -
362 - TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
363 -
364 - outPorts.forEach(p -> treatmentBuilder.setOutput(p));
365 -
366 - ForwardingObjective objective = DefaultForwardingObjective.builder()
367 - .fromApp(appId)
368 - .makePermanent()
369 - .withFlag(ForwardingObjective.Flag.VERSATILE)
370 - .withPriority(PRIORITY)
371 - .withSelector(selector)
372 - .withTreatment(treatmentBuilder.build())
373 - .add(new ObjectiveHandler());
374 -
375 - flowObjectiveService.forward(deviceId, objective);
376 - }
377 -
378 - private void removeForwarding(VlanId vlanId, DeviceId deviceId, PortNumber inPort,
379 - List<PortNumber> outPorts) {
380 - TrafficSelector selector = DefaultTrafficSelector.builder()
381 - .matchVlanId(vlanId)
382 - .matchInPort(inPort)
383 - .build();
384 -
385 - TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
386 -
387 - outPorts.forEach(p -> treatmentBuilder.setOutput(p));
388 -
389 - ForwardingObjective objective = DefaultForwardingObjective.builder()
390 - .fromApp(appId)
391 - .makePermanent()
392 - .withFlag(ForwardingObjective.Flag.VERSATILE)
393 - .withPriority(PRIORITY)
394 - .withSelector(selector)
395 - .withTreatment(treatmentBuilder.build())
396 - .remove(new ObjectiveHandler());
397 -
398 - flowObjectiveService.forward(deviceId, objective);
399 - }
400 -
401 - private static class ObjectiveHandler implements ObjectiveContext {
402 - private static Logger log = LoggerFactory.getLogger(ObjectiveHandler.class);
403 -
404 - @Override
405 - public void onSuccess(Objective objective) {
406 - log.info("Flow objective operation successful: {}", objective);
407 - }
408 -
409 - @Override
410 - public void onError(Objective objective, ObjectiveError error) {
411 - log.info("Flow objective operation failed: {}", objective);
412 - }
413 - }
414 -
415 - /**
416 - * Internal listener for device service events.
417 - */
418 - private class InternalDeviceListener implements DeviceListener {
419 - @Override
420 - public void event(DeviceEvent event) {
421 - switch (event.type()) {
422 - case DEVICE_ADDED:
423 - case DEVICE_AVAILABILITY_CHANGED:
424 - if (event.subject().id().equals(fabricDeviceId) &&
425 - deviceService.isAvailable(event.subject().id())) {
426 - setupDefaultFlows();
427 - }
428 - break;
429 - default:
430 - break;
431 - }
432 - }
433 - }
434 -}
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 -package org.onosproject.cordfabric;
18 -
19 -import org.onlab.packet.VlanId;
20 -
21 -import java.util.List;
22 -
23 -/**
24 - * Service used to interact with fabric.
25 - */
26 -public interface FabricService {
27 -
28 - /**
29 - * Remaps a vlan to the specified ports. The specified ports will be the
30 - * only ports in this vlan once the operation completes.
31 - *
32 - * @param vlan vlan object to add
33 - */
34 - void addVlan(FabricVlan vlan);
35 -
36 - /**
37 - * Removes a vlan from all ports in the fabric.
38 - *
39 - * @param vlanId ID of vlan to remove
40 - */
41 - void removeVlan(VlanId vlanId);
42 -
43 - /**
44 - * Returns the vlan to port mapping for all vlans/ports configured in the
45 - * fabric.
46 - *
47 - * @return mapping of vlan to port
48 - */
49 - List<FabricVlan> getVlans();
50 -}
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 -package org.onosproject.cordfabric;
18 -
19 -import com.google.common.collect.ImmutableList;
20 -import org.onlab.packet.VlanId;
21 -import org.onosproject.net.ConnectPoint;
22 -
23 -import java.util.Collection;
24 -import java.util.List;
25 -
26 -import static com.google.common.base.Preconditions.checkNotNull;
27 -
28 -/**
29 - * Vlan which spans multiple fabric ports.
30 - */
31 -public class FabricVlan {
32 -
33 - private final VlanId vlan;
34 -
35 - private final List<ConnectPoint> ports;
36 - private final boolean iptv;
37 -
38 - public FabricVlan(VlanId vlan, Collection<ConnectPoint> ports, boolean iptv) {
39 - checkNotNull(vlan);
40 - checkNotNull(ports);
41 - this.vlan = vlan;
42 - this.ports = ImmutableList.copyOf(ports);
43 - this.iptv = iptv;
44 - }
45 -
46 - public VlanId vlan() {
47 - return vlan;
48 - }
49 -
50 - public List<ConnectPoint> ports() {
51 - return ports;
52 - }
53 -
54 - public boolean iptv() {
55 - return iptv;
56 - }
57 -}
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 -package org.onosproject.cordfabric;
18 -
19 -import com.fasterxml.jackson.databind.JsonNode;
20 -import com.fasterxml.jackson.databind.node.ArrayNode;
21 -import com.fasterxml.jackson.databind.node.ObjectNode;
22 -import org.onlab.packet.VlanId;
23 -import org.onosproject.codec.CodecContext;
24 -import org.onosproject.codec.JsonCodec;
25 -import org.onosproject.net.ConnectPoint;
26 -
27 -import java.util.ArrayList;
28 -import java.util.List;
29 -
30 -import static com.google.common.base.Preconditions.checkNotNull;
31 -
32 -/**
33 - * Codec for encoding/decoding a FabricVlan object to/from JSON.
34 - */
35 -public final class FabricVlanCodec extends JsonCodec<FabricVlan> {
36 -
37 - // JSON field names
38 - private static final String VLAN = "vlan";
39 - private static final String PORTS = "ports";
40 - private static final String IPTV = "iptv";
41 -
42 - @Override
43 - public ObjectNode encode(FabricVlan vlan, CodecContext context) {
44 - checkNotNull(vlan, "Vlan cannot be null");
45 - final ObjectNode result = context.mapper().createObjectNode()
46 - .put(VLAN, vlan.vlan().toShort());
47 -
48 - final ArrayNode jsonPorts = result.putArray(PORTS);
49 -
50 - vlan.ports().forEach(cp -> jsonPorts.add(context.codec(ConnectPoint.class).encode(cp, context)));
51 -
52 - return result;
53 - }
54 -
55 - @Override
56 - public FabricVlan decode(ObjectNode json, CodecContext context) {
57 - short vlan = json.path(VLAN).shortValue();
58 - boolean iptv = json.path(IPTV).booleanValue();
59 - List<ConnectPoint> ports = new ArrayList<>();
60 -
61 - ArrayNode portArray = (ArrayNode) json.path(PORTS);
62 - for (JsonNode o : portArray) {
63 - ports.add(context.codec(ConnectPoint.class).decode((ObjectNode) o, context));
64 - }
65 -
66 - return new FabricVlan(VlanId.vlanId(vlan), ports, iptv);
67 - }
68 -}
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 -package org.onosproject.cordfabric;
18 -
19 -import com.fasterxml.jackson.databind.ObjectMapper;
20 -import com.fasterxml.jackson.databind.node.ObjectNode;
21 -import org.onlab.packet.VlanId;
22 -import org.onosproject.rest.AbstractWebResource;
23 -
24 -import javax.ws.rs.Consumes;
25 -import javax.ws.rs.DELETE;
26 -import javax.ws.rs.GET;
27 -import javax.ws.rs.POST;
28 -import javax.ws.rs.Path;
29 -import javax.ws.rs.PathParam;
30 -import javax.ws.rs.Produces;
31 -import javax.ws.rs.core.MediaType;
32 -import javax.ws.rs.core.Response;
33 -import java.io.IOException;
34 -import java.io.InputStream;
35 -import java.util.List;
36 -
37 -/**
38 - * Web resource for interacting with the fabric.
39 - */
40 -@Path("vlans")
41 -public class FabricWebResource extends AbstractWebResource {
42 -
43 - private static final FabricVlanCodec VLAN_CODEC = new FabricVlanCodec();
44 -
45 - /**
46 - * Get all CORD fabric VLANs.
47 - *
48 - * @return array of cord VLANs in the system.
49 - */
50 - @GET
51 - @Produces(MediaType.APPLICATION_JSON)
52 - public Response getVlans() {
53 - FabricService fabricService = get(FabricService.class);
54 - List<FabricVlan> vlans = fabricService.getVlans();
55 - ObjectNode result = new ObjectMapper().createObjectNode();
56 - result.set("vlans", new FabricVlanCodec().encode(vlans, this));
57 -
58 - return ok(result.toString()).build();
59 - }
60 -
61 - /**
62 - * Create a CORD fabric VLAN.
63 - *
64 - * @param input JSON stream describing new VLAN
65 - * @return status of the request - CREATED if the JSON is correct,
66 - * INTERNAL_SERVER_ERROR if the JSON is invalid
67 - * @throws IOException if the JSON is invalid
68 - */
69 - @POST
70 - @Path("add")
71 - @Consumes(MediaType.APPLICATION_JSON)
72 - public Response addVlan(InputStream input) throws IOException {
73 - ObjectMapper mapper = new ObjectMapper();
74 - ObjectNode vlanJson = (ObjectNode) mapper.readTree(input);
75 - FabricService fabricService = get(FabricService.class);
76 -
77 - fabricService.addVlan(VLAN_CODEC.decode(vlanJson, this));
78 -
79 - return Response.ok().build();
80 - }
81 -
82 - /**
83 - * Delete a CORD fabric VLAN.
84 - *
85 - * @param vlan identifier of the VLAN to remove
86 - * @return status of the request - OK
87 - */
88 - @DELETE
89 - @Path("{vlan}")
90 - public Response deleteVlan(@PathParam("vlan") String vlan) {
91 - VlanId vlanId = VlanId.vlanId(Short.parseShort(vlan));
92 -
93 - FabricService fabricService = get(FabricService.class);
94 -
95 - fabricService.removeVlan(vlanId);
96 -
97 - return Response.ok().build();
98 - }
99 -}
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 -package org.onosproject.cordfabric.cli;
18 -
19 -import org.apache.karaf.shell.commands.Argument;
20 -import org.apache.karaf.shell.commands.Command;
21 -import org.onlab.packet.VlanId;
22 -import org.onosproject.cli.AbstractShellCommand;
23 -import org.onosproject.cordfabric.FabricService;
24 -import org.onosproject.cordfabric.FabricVlan;
25 -import org.onosproject.net.ConnectPoint;
26 -
27 -import java.util.ArrayList;
28 -import java.util.List;
29 -
30 -/**
31 - * Adds a vlan to the fabric.
32 - */
33 -@Command(scope = "onos", name = "add-fabric-vlan",
34 - description = "Adds a VLAN to the fabric")
35 -public class FabricAddCommand extends AbstractShellCommand {
36 -
37 - @Argument(index = 0, name = "vlanid", description = "VLAN ID",
38 - required = true, multiValued = false)
39 - private String vlanIdString = null;
40 -
41 - @Argument(index = 1, name = "ports",
42 - description = "List of ports in the VLAN",
43 - required = true, multiValued = true)
44 - private String[] portStrings = null;
45 -
46 - @Override
47 - protected void execute() {
48 - FabricService service = AbstractShellCommand.get(FabricService.class);
49 -
50 - VlanId vlan = VlanId.vlanId(Short.parseShort(vlanIdString));
51 -
52 - if (portStrings.length < 2) {
53 - throw new IllegalArgumentException("Must have at least 2 ports");
54 - }
55 -
56 - List<ConnectPoint> ports = new ArrayList<>(portStrings.length);
57 -
58 - for (String portString : portStrings) {
59 - ports.add(ConnectPoint.deviceConnectPoint(portString));
60 - }
61 -
62 - service.addVlan(new FabricVlan(vlan, ports, false));
63 - }
64 -}
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 -package org.onosproject.cordfabric.cli;
18 -
19 -import org.apache.karaf.shell.commands.Argument;
20 -import org.apache.karaf.shell.commands.Command;
21 -import org.onlab.packet.VlanId;
22 -import org.onosproject.cli.AbstractShellCommand;
23 -import org.onosproject.cordfabric.FabricService;
24 -
25 -/**
26 - * Removes a vlan from the fabric.
27 - */
28 -@Command(scope = "onos", name = "remove-fabric-vlan",
29 - description = "Removes a VLAN from the fabric")
30 -public class FabricRemoveCommand extends AbstractShellCommand {
31 -
32 - @Argument(index = 0, name = "vlanid", description = "VLAN ID",
33 - required = true, multiValued = false)
34 - private String vlanIdString = null;
35 -
36 - @Override
37 - protected void execute() {
38 - FabricService service = AbstractShellCommand.get(FabricService.class);
39 -
40 - VlanId vlan = VlanId.vlanId(Short.parseShort(vlanIdString));
41 -
42 - service.removeVlan(vlan);
43 - }
44 -}
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 -package org.onosproject.cordfabric.cli;
18 -
19 -import org.apache.karaf.shell.commands.Command;
20 -import org.onosproject.cli.AbstractShellCommand;
21 -import org.onosproject.cordfabric.FabricService;
22 -import org.onosproject.cordfabric.FabricVlan;
23 -
24 -import java.util.List;
25 -
26 -/**
27 - * Shows the vlans in the fabric.
28 - */
29 -@Command(scope = "onos", name = "fabric",
30 - description = "Shows the fabric vlans")
31 -public class FabricShowCommand extends AbstractShellCommand {
32 -
33 - private static final String VLAN_HEADER_LINE_FORMAT = "VLAN %s";
34 - private static final String PORT_LINE_FORMAT = "\t%s";
35 -
36 - @Override
37 - protected void execute() {
38 - FabricService service = AbstractShellCommand.get(FabricService.class);
39 -
40 - List<FabricVlan> vlans = service.getVlans();
41 -
42 - vlans.forEach(fabricVlan -> {
43 - print(VLAN_HEADER_LINE_FORMAT, fabricVlan.vlan());
44 - fabricVlan.ports().forEach(cp -> print(PORT_LINE_FORMAT, cp));
45 - });
46 - }
47 -}
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 - * Console commands for managing fabric of VLANs.
19 - */
20 -package org.onosproject.cordfabric.cli;
...\ 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 -
17 -/**
18 - * Service for managing fabric of VLANs.
19 - */
20 -package org.onosproject.cordfabric;
...\ 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 -<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.cordfabric.cli.FabricShowCommand"/>
21 - </command>
22 - <command>
23 - <action class="org.onosproject.cordfabric.cli.FabricAddCommand"/>
24 - <completers>
25 - <ref component-id="placeholderCompleter"/>
26 - <ref component-id="connectPointCompleter"/>
27 - </completers>
28 - </command>
29 - <command>
30 - <action class="org.onosproject.cordfabric.cli.FabricRemoveCommand"/>
31 - </command>
32 - </command-bundle>
33 -
34 - <bean id="connectPointCompleter" class="org.onosproject.cli.net.ConnectPointCompleter"/>
35 - <bean id="placeholderCompleter" class="org.onosproject.cli.PlaceholderCompleter"/>
36 -</blueprint>
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 -<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
18 - xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
19 - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
20 - id="ONOS" version="2.5">
21 - <display-name>CORD Fabric REST API v1.0</display-name>
22 -
23 - <servlet>
24 - <servlet-name>JAX-RS Service</servlet-name>
25 - <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
26 - <init-param>
27 - <param-name>jersey.config.server.provider.classnames</param-name>
28 - <param-value>
29 - org.onosproject.cordfabric.FabricWebResource
30 - </param-value>
31 - </init-param>
32 - <load-on-startup>1</load-on-startup>
33 - </servlet>
34 -
35 - <servlet-mapping>
36 - <servlet-name>JAX-RS Service</servlet-name>
37 - <url-pattern>/*</url-pattern>
38 - </servlet-mapping>
39 -
40 -</web-app>
...@@ -46,7 +46,6 @@ ...@@ -46,7 +46,6 @@
46 <module>bgprouter</module> 46 <module>bgprouter</module>
47 <module>test</module> 47 <module>test</module>
48 <module>segmentrouting</module> 48 <module>segmentrouting</module>
49 - <module>cordfabric</module>
50 <module>xos-integration</module> 49 <module>xos-integration</module>
51 <module>pcep-api</module> 50 <module>pcep-api</module>
52 <module>iptopology-api</module> 51 <module>iptopology-api</module>
......