alshabib
Committed by Gerrit Code Review

Added an OLT application which pushes vlan circuits when ports are up.

Added a driver for the OLT

Change-Id: I13085d4a5a05e92a1640eff3f10ff75c2188e0d3
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 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/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-apps</artifactId>
25 + <version>1.2.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-app-olt</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>OLT application</description>
33 +
34 + <properties>
35 + <onos.app.name>org.onosproject.olt</onos.app.name>
36 + </properties>
37 +
38 + <dependencies>
39 + <dependency>
40 + <groupId>com.google.guava</groupId>
41 + <artifactId>guava</artifactId>
42 + </dependency>
43 + <dependency>
44 + <groupId>org.onosproject</groupId>
45 + <artifactId>onlab-misc</artifactId>
46 + </dependency>
47 + <dependency>
48 + <groupId>org.apache.felix</groupId>
49 + <artifactId>org.apache.felix.scr</artifactId>
50 + <version>1.8.2</version>
51 + </dependency>
52 + <dependency>
53 + <groupId>org.osgi</groupId>
54 + <artifactId>org.osgi.compendium</artifactId>
55 + <version>5.0.0</version>
56 + </dependency>
57 + </dependencies>
58 +</project>
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.olt;
17 +
18 +
19 +import com.google.common.base.Strings;
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.Modified;
24 +import org.apache.felix.scr.annotations.Property;
25 +import org.apache.felix.scr.annotations.Reference;
26 +import org.apache.felix.scr.annotations.ReferenceCardinality;
27 +import org.onlab.packet.VlanId;
28 +import org.onlab.util.Tools;
29 +import org.onosproject.core.ApplicationId;
30 +import org.onosproject.core.CoreService;
31 +import org.onosproject.net.DeviceId;
32 +import org.onosproject.net.PortNumber;
33 +import org.onosproject.net.device.DeviceEvent;
34 +import org.onosproject.net.device.DeviceListener;
35 +import org.onosproject.net.device.DeviceService;
36 +import org.onosproject.net.flow.DefaultTrafficSelector;
37 +import org.onosproject.net.flow.DefaultTrafficTreatment;
38 +import org.onosproject.net.flow.TrafficSelector;
39 +import org.onosproject.net.flow.TrafficTreatment;
40 +import org.onosproject.net.flowobjective.DefaultForwardingObjective;
41 +import org.onosproject.net.flowobjective.FlowObjectiveService;
42 +import org.onosproject.net.flowobjective.ForwardingObjective;
43 +import org.osgi.service.component.ComponentContext;
44 +import org.slf4j.Logger;
45 +
46 +import java.util.Dictionary;
47 +
48 +import static org.slf4j.LoggerFactory.getLogger;
49 +
50 +/**
51 + * Sample mobility application. Cleans up flowmods when a host moves.
52 + */
53 +@Component(immediate = true)
54 +public class OLT {
55 +
56 + private final Logger log = getLogger(getClass());
57 +
58 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
59 + protected FlowObjectiveService flowObjectiveService;
60 +
61 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 + protected DeviceService deviceService;
63 +
64 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
65 + protected CoreService coreService;
66 +
67 + private final DeviceListener deviceListener = new InternalDeviceListener();
68 +
69 + private ApplicationId appId;
70 +
71 + public static final int UPLINK_PORT = 129;
72 +
73 + public static final String OLT_DEVICE = "of:90e2ba82f97791e9";
74 +
75 + @Property(name = "uplinkPort", intValue = UPLINK_PORT,
76 + label = "The OLT's uplink port number")
77 + private int uplinkPort = UPLINK_PORT;
78 +
79 + //TODO: replace this with an annotation lookup
80 + @Property(name = "oltDevice", value = OLT_DEVICE,
81 + label = "The OLT device id")
82 + private String oltDevice = OLT_DEVICE;
83 +
84 +
85 + @Activate
86 + public void activate() {
87 + appId = coreService.registerApplication("org.onosproject.mobility");
88 + deviceService.getPorts(DeviceId.deviceId(oltDevice)).stream().forEach(
89 + port -> {
90 + if (port.isEnabled()) {
91 + provisionVlanOnPort(port.number());
92 + }
93 + }
94 + );
95 + log.info("Started with Application ID {}", appId.id());
96 + }
97 +
98 + @Deactivate
99 + public void deactivate() {
100 + log.info("Stopped");
101 + }
102 +
103 + @Modified
104 + public void modified(ComponentContext context) {
105 + Dictionary<?, ?> properties = context.getProperties();
106 +
107 +
108 + String s = Tools.get(properties, "uplinkPort");
109 + uplinkPort = Strings.isNullOrEmpty(s) ? UPLINK_PORT : Integer.parseInt(s);
110 +
111 + s = Tools.get(properties, "oltDevice");
112 + oltDevice = Strings.isNullOrEmpty(s) ? OLT_DEVICE : s;
113 +
114 + }
115 +
116 + private void provisionVlanOnPort(PortNumber p) {
117 + long port = p.toLong();
118 + if (port > 4095) {
119 + log.warn("Port Number {} exceeds vlan max", port);
120 + return;
121 + }
122 +
123 + TrafficSelector upstream = DefaultTrafficSelector.builder()
124 + .matchVlanId(
125 + VlanId.vlanId((short) port))
126 + .matchInPort(p)
127 + .build();
128 +
129 + TrafficSelector downStream = DefaultTrafficSelector.builder()
130 + .matchVlanId(
131 + VlanId.vlanId((short) port))
132 + .matchInPort(PortNumber.portNumber(uplinkPort))
133 + .build();
134 +
135 + TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder()
136 + .setOutput(PortNumber.portNumber(uplinkPort))
137 + .build();
138 +
139 + TrafficTreatment downStreamTreatment = DefaultTrafficTreatment.builder()
140 + .setOutput(p)
141 + .build();
142 +
143 +
144 + ForwardingObjective upFwd = DefaultForwardingObjective.builder()
145 + .withFlag(ForwardingObjective.Flag.VERSATILE)
146 + .withPriority(1000)
147 + .makePermanent()
148 + .withSelector(upstream)
149 + .fromApp(appId)
150 + .withTreatment(upstreamTreatment)
151 + .add();
152 +
153 + ForwardingObjective downFwd = DefaultForwardingObjective.builder()
154 + .withFlag(ForwardingObjective.Flag.VERSATILE)
155 + .withPriority(1000)
156 + .makePermanent()
157 + .withSelector(downStream)
158 + .fromApp(appId)
159 + .withTreatment(downStreamTreatment)
160 + .add();
161 +
162 + flowObjectiveService.forward(DeviceId.deviceId(oltDevice), upFwd);
163 + flowObjectiveService.forward(DeviceId.deviceId(oltDevice), downFwd);
164 +
165 + }
166 +
167 + private class InternalDeviceListener implements DeviceListener {
168 + @Override
169 + public void event(DeviceEvent event) {
170 + DeviceId devId = DeviceId.deviceId(oltDevice);
171 + switch (event.type()) {
172 + case PORT_ADDED:
173 + case PORT_UPDATED:
174 + if (devId.equals(event.subject().id()) && event.port().isEnabled()) {
175 + provisionVlanOnPort(event.port().number());
176 + }
177 + break;
178 + case DEVICE_ADDED:
179 + case DEVICE_UPDATED:
180 + case DEVICE_REMOVED:
181 + case DEVICE_SUSPENDED:
182 + case DEVICE_AVAILABILITY_CHANGED:
183 + case PORT_REMOVED:
184 + case PORT_STATS_UPDATED:
185 + default:
186 + return;
187 + }
188 + }
189 + }
190 +
191 +
192 +}
193 +
194 +
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 +
17 +/**
18 + * OLT application handling PMC OLT hardware.
19 + */
20 +package org.onosproject.olt;
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
50 <module>cordfabric</module> 50 <module>cordfabric</module>
51 <module>xos-integration</module> 51 <module>xos-integration</module>
52 <module>pcep-api</module> 52 <module>pcep-api</module>
53 + <module>olt</module>
53 </modules> 54 </modules>
54 55
55 <properties> 56 <properties>
......
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.driver.pipeline;
17 +
18 +import org.onlab.osgi.ServiceDirectory;
19 +import org.onosproject.net.DeviceId;
20 +import org.onosproject.net.PortNumber;
21 +import org.onosproject.net.behaviour.Pipeliner;
22 +import org.onosproject.net.behaviour.PipelinerContext;
23 +import org.onosproject.net.driver.AbstractHandlerBehaviour;
24 +import org.onosproject.net.flow.DefaultFlowRule;
25 +import org.onosproject.net.flow.DefaultTrafficTreatment;
26 +import org.onosproject.net.flow.FlowRule;
27 +import org.onosproject.net.flow.FlowRuleOperations;
28 +import org.onosproject.net.flow.FlowRuleOperationsContext;
29 +import org.onosproject.net.flow.FlowRuleService;
30 +import org.onosproject.net.flow.TrafficSelector;
31 +import org.onosproject.net.flow.TrafficTreatment;
32 +import org.onosproject.net.flow.instructions.Instructions;
33 +import org.onosproject.net.flowobjective.FilteringObjective;
34 +import org.onosproject.net.flowobjective.ForwardingObjective;
35 +import org.onosproject.net.flowobjective.NextObjective;
36 +import org.onosproject.net.flowobjective.ObjectiveError;
37 +import org.slf4j.Logger;
38 +
39 +import static org.slf4j.LoggerFactory.getLogger;
40 +
41 +/**
42 + * Simple single table pipeline abstraction.
43 + */
44 +public class OLTPipeline extends AbstractHandlerBehaviour implements Pipeliner {
45 +
46 + private final Logger log = getLogger(getClass());
47 +
48 + private ServiceDirectory serviceDirectory;
49 + private FlowRuleService flowRuleService;
50 + private DeviceId deviceId;
51 +
52 + @Override
53 + public void init(DeviceId deviceId, PipelinerContext context) {
54 + this.serviceDirectory = context.directory();
55 + this.deviceId = deviceId;
56 +
57 + flowRuleService = serviceDirectory.get(FlowRuleService.class);
58 + }
59 +
60 + @Override
61 + public void filter(FilteringObjective filter) {
62 + throw new UnsupportedOperationException("Single table does not filter.");
63 + }
64 +
65 + @Override
66 + public void forward(ForwardingObjective fwd) {
67 + FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder();
68 +
69 + if (fwd.flag() != ForwardingObjective.Flag.VERSATILE) {
70 + throw new UnsupportedOperationException(
71 + "Only VERSATILE is supported.");
72 + }
73 +
74 + boolean isPunt = fwd.treatment().immediate().stream().anyMatch(i -> {
75 + if (i instanceof Instructions.OutputInstruction) {
76 + Instructions.OutputInstruction out = (Instructions.OutputInstruction) i;
77 + return out.port().equals(PortNumber.CONTROLLER);
78 + }
79 + return false;
80 + });
81 +
82 + if (isPunt) {
83 + return;
84 + }
85 +
86 + TrafficSelector selector = fwd.selector();
87 + TrafficTreatment treatment = fwd.treatment();
88 + if ((fwd.treatment().deferred().size() == 0) &&
89 + (fwd.treatment().immediate().size() == 0) &&
90 + (fwd.treatment().tableTransition() == null) &&
91 + (!fwd.treatment().clearedDeferred())) {
92 + TrafficTreatment.Builder flowTreatment = DefaultTrafficTreatment.builder();
93 + flowTreatment.add(Instructions.createDrop());
94 + treatment = flowTreatment.build();
95 + }
96 +
97 + FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
98 + .forDevice(deviceId)
99 + .withSelector(selector)
100 + .withTreatment(fwd.treatment())
101 + .fromApp(fwd.appId())
102 + .withPriority(fwd.priority());
103 +
104 + if (fwd.permanent()) {
105 + ruleBuilder.makePermanent();
106 + } else {
107 + ruleBuilder.makeTemporary(fwd.timeout());
108 + }
109 +
110 +
111 + switch (fwd.op()) {
112 +
113 + case ADD:
114 + flowBuilder.add(ruleBuilder.build());
115 + break;
116 + case REMOVE:
117 + flowBuilder.remove(ruleBuilder.build());
118 + break;
119 + default:
120 + log.warn("Unknown operation {}", fwd.op());
121 + }
122 +
123 + flowRuleService.apply(flowBuilder.build(new FlowRuleOperationsContext() {
124 + @Override
125 + public void onSuccess(FlowRuleOperations ops) {
126 + if (fwd.context().isPresent()) {
127 + fwd.context().get().onSuccess(fwd);
128 + }
129 + }
130 +
131 + @Override
132 + public void onError(FlowRuleOperations ops) {
133 + if (fwd.context().isPresent()) {
134 + fwd.context().get().onError(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
135 + }
136 + }
137 + }));
138 +
139 + }
140 +
141 + @Override
142 + public void next(NextObjective nextObjective) {
143 + throw new UnsupportedOperationException("Single table does not next hop.");
144 + }
145 +
146 +}
...@@ -62,6 +62,11 @@ ...@@ -62,6 +62,11 @@
62 <behaviour api="org.onosproject.net.behaviour.Pipeliner" 62 <behaviour api="org.onosproject.net.behaviour.Pipeliner"
63 impl="org.onosproject.driver.pipeline.OFDPA1Pipeline"/> 63 impl="org.onosproject.driver.pipeline.OFDPA1Pipeline"/>
64 </driver> 64 </driver>
65 + <driver name="pmc-olt" extends="default"
66 + manufacturer="Big Switch Networks" hwVersion="ivs 0.5" swVersion="ivs 0.5">
67 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
68 + impl="org.onosproject.driver.pipeline.OLTPipeline"/>
69 + </driver>
65 <!-- The SoftRouter driver is meant to be used by any software/NPU based 70 <!-- The SoftRouter driver is meant to be used by any software/NPU based
66 ~ switch that wishes to implement a simple 2-table router. To use this 71 ~ switch that wishes to implement a simple 2-table router. To use this
67 ~ driver, configure ONOS with the dpid of the device, or extend the 72 ~ driver, configure ONOS with the dpid of the device, or extend the
......