Naoki Shiota
Committed by Yuta HIGUCHI

Moved ecord.metro app to onos repo. (ONOS-4441)

Change-Id: I9a5d2935012eee433a4f63c672c16bdcb8d6b6b8
...@@ -122,6 +122,7 @@ APPS = [ ...@@ -122,6 +122,7 @@ APPS = [
122 '//apps/openstacknetworking/openstackswitching:onos-apps-openstacknetworking-openstackswitching-oar', 122 '//apps/openstacknetworking/openstackswitching:onos-apps-openstacknetworking-openstackswitching-oar',
123 '//apps/mobility:onos-apps-mobility-oar', 123 '//apps/mobility:onos-apps-mobility-oar',
124 '//apps/optical:onos-apps-optical-oar', 124 '//apps/optical:onos-apps-optical-oar',
125 + '//apps/newoptical:onos-apps-newoptical-oar',
125 '//apps/pathpainter:onos-apps-pathpainter-oar', 126 '//apps/pathpainter:onos-apps-pathpainter-oar',
126 '//apps/pcep-api:onos-apps-pcep-api-oar', 127 '//apps/pcep-api:onos-apps-pcep-api-oar',
127 '//apps/pim:onos-apps-pim-oar', 128 '//apps/pim:onos-apps-pim-oar',
......
1 +COMPILE_DEPS = [
2 + '//lib:CORE_DEPS',
3 + '//lib:org.apache.karaf.shell.console',
4 + '//cli:onos-cli',
5 +]
6 +
7 +osgi_jar_with_tests (
8 + deps = COMPILE_DEPS,
9 +)
10 +
11 +onos_app (
12 + title = 'Packet/Optical Use-Case App',
13 + category = 'Traffic Steering',
14 + url = 'http://onosproject.org',
15 + description = 'Packet/Optical use-case application.',
16 +)
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18 + <modelVersion>4.0.0</modelVersion>
19 +
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 +
27 + <artifactId>onos-app-newoptical</artifactId>
28 + <packaging>bundle</packaging>
29 +
30 + <description>Application for setup optical network</description>
31 + <url>http://onosproject.org</url>
32 +
33 + <properties>
34 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
35 + <onos.app.name>org.onosproject.newoptical</onos.app.name>
36 + <onos.app.category>Traffic Steering</onos.app.category>
37 + <onos.app.url>http://onosproject.org</onos.app.url>
38 + <onos.app.origin>Open Networking Lab</onos.app.origin>
39 + </properties>
40 +
41 + <dependencies>
42 + <dependency>
43 + <groupId>org.onosproject</groupId>
44 + <artifactId>onos-api</artifactId>
45 + <version>${project.version}</version>
46 + </dependency>
47 +
48 + <dependency>
49 + <groupId>org.onosproject</groupId>
50 + <artifactId>onos-core-dist</artifactId>
51 + <version>${project.version}</version>
52 + </dependency>
53 +
54 + <dependency>
55 + <groupId>junit</groupId>
56 + <artifactId>junit</artifactId>
57 + <scope>test</scope>
58 + </dependency>
59 +
60 + <dependency>
61 + <groupId>org.onosproject</groupId>
62 + <artifactId>onos-api</artifactId>
63 + <version>${project.version}</version>
64 + <scope>test</scope>
65 + <classifier>tests</classifier>
66 + </dependency>
67 +
68 + <dependency>
69 + <groupId>org.apache.felix</groupId>
70 + <artifactId>org.apache.felix.scr.annotations</artifactId>
71 + <scope>provided</scope>
72 + </dependency>
73 +
74 + <dependency>
75 + <groupId>org.osgi</groupId>
76 + <artifactId>org.osgi.compendium</artifactId>
77 + <scope>provided</scope>
78 + </dependency>
79 +
80 + <dependency>
81 + <groupId>org.apache.karaf.shell</groupId>
82 + <artifactId>org.apache.karaf.shell.console</artifactId>
83 + <scope>provided</scope>
84 + </dependency>
85 +
86 + <dependency>
87 + <groupId>org.onosproject</groupId>
88 + <artifactId>onos-cli</artifactId>
89 + <version>${project.version}</version>
90 + </dependency>
91 +
92 + </dependencies>
93 +
94 + <build>
95 + <pluginManagement>
96 + <plugins>
97 + <plugin>
98 + <groupId>org.apache.karaf.tooling</groupId>
99 + <artifactId>karaf-maven-plugin</artifactId>
100 + <extensions>true</extensions>
101 + </plugin>
102 + </plugins>
103 + </pluginManagement>
104 + <plugins>
105 + <plugin>
106 + <groupId>org.apache.felix</groupId>
107 + <artifactId>maven-bundle-plugin</artifactId>
108 + <extensions>true</extensions>
109 + </plugin>
110 + <plugin>
111 + <groupId>org.apache.maven.plugins</groupId>
112 + <artifactId>maven-compiler-plugin</artifactId>
113 + <configuration>
114 + <source>1.8</source>
115 + <target>1.8</target>
116 + </configuration>
117 + </plugin>
118 + <plugin>
119 + <groupId>org.apache.felix</groupId>
120 + <artifactId>maven-scr-plugin</artifactId>
121 + <executions>
122 + <execution>
123 + <id>generate-scr-srcdescriptor</id>
124 + <goals>
125 + <goal>scr</goal>
126 + </goals>
127 + </execution>
128 + </executions>
129 + <configuration>
130 + <supportedProjectTypes>
131 + <supportedProjectType>bundle</supportedProjectType>
132 + <supportedProjectType>war</supportedProjectType>
133 + </supportedProjectTypes>
134 + </configuration>
135 + </plugin>
136 + <plugin>
137 + <groupId>org.onosproject</groupId>
138 + <artifactId>onos-maven-plugin</artifactId>
139 + <executions>
140 + <execution>
141 + <id>cfg</id>
142 + <phase>generate-resources</phase>
143 + <goals>
144 + <goal>cfg</goal>
145 + </goals>
146 + </execution>
147 + <execution>
148 + <id>swagger</id>
149 + <phase>generate-sources</phase>
150 + <goals>
151 + <goal>swagger</goal>
152 + </goals>
153 + </execution>
154 + <execution>
155 + <id>app</id>
156 + <phase>package</phase>
157 + <goals>
158 + <goal>app</goal>
159 + </goals>
160 + </execution>
161 + </executions>
162 + </plugin>
163 + </plugins>
164 + </build>
165 +
166 +</project>
1 +/*
2 + * Copyright 2016 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.newoptical;
17 +
18 +import com.google.common.annotations.Beta;
19 +import com.google.common.collect.ImmutableList;
20 +import com.google.common.collect.ImmutableSet;
21 +import org.onlab.util.Bandwidth;
22 +import org.onosproject.newoptical.api.OpticalConnectivityId;
23 +import org.onosproject.net.ConnectPoint;
24 +import org.onosproject.net.Link;
25 +import org.onosproject.net.Path;
26 +import org.onosproject.net.intent.IntentId;
27 +
28 +import java.time.Duration;
29 +import java.util.HashSet;
30 +import java.util.List;
31 +import java.util.Set;
32 +
33 +import static com.google.common.base.Preconditions.checkNotNull;
34 +
35 +/**
36 + * Entity to store optical connectivity request and related information.
37 + */
38 +@Beta
39 +public class OpticalConnectivity {
40 +
41 + private final OpticalConnectivityId id;
42 + private final List<Link> links;
43 + private final Bandwidth requestBandwidth;
44 + private final Duration requestLatency;
45 +
46 + // Bandwidth capacity of optical layer
47 + private Bandwidth opticalCapacity;
48 +
49 + private final Set<PacketLinkRealizedByOptical> realizingLinks = new HashSet<>();
50 +
51 + // TODO: This IntentId is used only to reserve bandwidth resource.
52 + // After ResourceManager is made to accept app-defined ResourceConsumer,
53 + // this Intent should be replaced with OpticalConnectivityId.
54 + private IntentId intentId;
55 +
56 + private State state = State.CREATED;
57 +
58 + public enum State {
59 + CREATED,
60 + INSTALLING,
61 + INSTALLED,
62 + WITHDRAWING,
63 + WITHDRAWN,
64 + FAILED
65 + }
66 +
67 + public OpticalConnectivity(OpticalConnectivityId id, Path path, Bandwidth requestBandwidth,
68 + Duration requestLatency) {
69 + this.id = id;
70 + this.links = ImmutableList.copyOf(path.links());
71 + this.requestBandwidth = requestBandwidth;
72 + this.requestLatency = requestLatency;
73 + }
74 +
75 + public void setLinkEstablished(ConnectPoint src, ConnectPoint dst) {
76 + realizingLinks.stream().filter(l -> l.isBetween(src, dst))
77 + .findAny()
78 + .ifPresent(l -> l.setEstablished(true));
79 + }
80 +
81 + public void setLinkRemoved(ConnectPoint src, ConnectPoint dst) {
82 + realizingLinks.stream().filter(l -> l.isBetween(src, dst))
83 + .findAny()
84 + .ifPresent(l -> l.setEstablished(false));
85 + }
86 +
87 + public boolean isAllRealizingLinkEstablished() {
88 + return realizingLinks.stream().allMatch(PacketLinkRealizedByOptical::isEstablished);
89 + }
90 +
91 + public boolean isAllRealizingLinkNotEstablished() {
92 + return !realizingLinks.stream().anyMatch(PacketLinkRealizedByOptical::isEstablished);
93 + }
94 +
95 + public OpticalConnectivityId id() {
96 + return id;
97 + }
98 +
99 + public List<Link> links() {
100 + return links;
101 + }
102 +
103 + public Bandwidth bandwidth() {
104 + return requestBandwidth;
105 + }
106 +
107 + public Duration latency() {
108 + return requestLatency;
109 + }
110 +
111 + public State state() {
112 + return state;
113 + }
114 +
115 + public boolean state(State state) {
116 + boolean valid = true;
117 + // reject invalid state transition
118 + switch (this.state) {
119 + case CREATED:
120 + valid = (state == State.INSTALLING || state == State.FAILED);
121 + break;
122 + case INSTALLING:
123 + valid = (state == State.INSTALLED || state == State.FAILED);
124 + break;
125 + case INSTALLED:
126 + valid = (state == State.WITHDRAWING || state == State.FAILED);
127 + break;
128 + case WITHDRAWING:
129 + valid = (state == State.WITHDRAWN || state == State.FAILED);
130 + break;
131 + case FAILED:
132 + valid = (state == State.INSTALLING || state == State.WITHDRAWING || state == State.FAILED);
133 + break;
134 + default:
135 + break;
136 + }
137 +
138 + if (valid) {
139 + this.state = state;
140 + }
141 +
142 + return valid;
143 + }
144 +
145 + public Bandwidth getOpticalCapacity() {
146 + return opticalCapacity;
147 + }
148 +
149 + public void setOpticalCapacity(Bandwidth opticalCapacity) {
150 + this.opticalCapacity = opticalCapacity;
151 + }
152 +
153 + public void addRealizingLink(PacketLinkRealizedByOptical link) {
154 + checkNotNull(link);
155 + realizingLinks.add(link);
156 + }
157 +
158 + public void removeRealizingLink(PacketLinkRealizedByOptical link) {
159 + checkNotNull(link);
160 + realizingLinks.remove(link);
161 + }
162 +
163 + public Set<PacketLinkRealizedByOptical> getRealizingLinks() {
164 + return ImmutableSet.copyOf(realizingLinks);
165 + }
166 +
167 + public IntentId getIntentId() {
168 + return intentId;
169 + }
170 +
171 + public void setIntentId(IntentId intentId) {
172 + this.intentId = intentId;
173 + }
174 +}
1 +/*
2 + * Copyright 2016 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.newoptical;
17 +
18 +import com.google.common.annotations.Beta;
19 +import com.google.common.collect.ImmutableList;
20 +import com.google.common.collect.Sets;
21 +
22 +import org.apache.commons.lang3.tuple.Pair;
23 +import org.apache.felix.scr.annotations.Activate;
24 +import org.apache.felix.scr.annotations.Component;
25 +import org.apache.felix.scr.annotations.Deactivate;
26 +import org.apache.felix.scr.annotations.Reference;
27 +import org.apache.felix.scr.annotations.ReferenceCardinality;
28 +import org.apache.felix.scr.annotations.Service;
29 +import org.onlab.util.Bandwidth;
30 +import org.onosproject.cluster.ClusterService;
31 +import org.onosproject.cluster.NodeId;
32 +import org.onosproject.core.ApplicationId;
33 +import org.onosproject.core.CoreService;
34 +import org.onosproject.newoptical.api.OpticalConnectivityId;
35 +import org.onosproject.newoptical.api.OpticalPathEvent;
36 +import org.onosproject.newoptical.api.OpticalPathListener;
37 +import org.onosproject.newoptical.api.OpticalPathService;
38 +import org.onosproject.event.AbstractListenerManager;
39 +import org.onosproject.mastership.MastershipService;
40 +import org.onosproject.net.CltSignalType;
41 +import org.onosproject.net.ConnectPoint;
42 +import org.onosproject.net.Device;
43 +import org.onosproject.net.DeviceId;
44 +import org.onosproject.net.Link;
45 +import org.onosproject.net.OchPort;
46 +import org.onosproject.net.OduCltPort;
47 +import org.onosproject.net.OduSignalType;
48 +import org.onosproject.net.Path;
49 +import org.onosproject.net.Port;
50 +import org.onosproject.net.config.NetworkConfigService;
51 +import org.onosproject.net.device.DeviceService;
52 +import org.onosproject.net.intent.Intent;
53 +import org.onosproject.net.intent.IntentEvent;
54 +import org.onosproject.net.intent.IntentId;
55 +import org.onosproject.net.intent.IntentListener;
56 +import org.onosproject.net.intent.IntentService;
57 +import org.onosproject.net.intent.Key;
58 +import org.onosproject.net.intent.OpticalCircuitIntent;
59 +import org.onosproject.net.intent.OpticalConnectivityIntent;
60 +import org.onosproject.net.intent.PointToPointIntent;
61 +import org.onosproject.net.link.LinkEvent;
62 +import org.onosproject.net.link.LinkListener;
63 +import org.onosproject.net.link.LinkService;
64 +import org.onosproject.net.resource.BandwidthCapacity;
65 +import org.onosproject.net.resource.ContinuousResource;
66 +import org.onosproject.net.resource.Resource;
67 +import org.onosproject.net.resource.ResourceAllocation;
68 +import org.onosproject.net.resource.ResourceService;
69 +import org.onosproject.net.resource.Resources;
70 +import org.onosproject.net.topology.LinkWeight;
71 +import org.onosproject.net.topology.PathService;
72 +import org.onosproject.net.topology.TopologyEdge;
73 +import org.onosproject.store.service.AtomicCounter;
74 +import org.onosproject.store.service.StorageService;
75 +import org.slf4j.Logger;
76 +import org.slf4j.LoggerFactory;
77 +
78 +import java.time.Duration;
79 +import java.util.Collections;
80 +import java.util.Iterator;
81 +import java.util.LinkedList;
82 +import java.util.List;
83 +import java.util.Map;
84 +import java.util.Optional;
85 +import java.util.Set;
86 +import java.util.concurrent.ConcurrentHashMap;
87 +import java.util.stream.Collectors;
88 +import java.util.stream.Stream;
89 +
90 +import static com.google.common.base.Preconditions.checkArgument;
91 +import static com.google.common.base.Preconditions.checkNotNull;
92 +
93 +/**
94 + * Main component to configure optical connectivity.
95 + */
96 +@Beta
97 +@Service
98 +@Component(immediate = true)
99 +public class OpticalPathProvisioner
100 + extends AbstractListenerManager<OpticalPathEvent, OpticalPathListener>
101 + implements OpticalPathService {
102 + protected static final Logger log = LoggerFactory.getLogger(OpticalPathProvisioner.class);
103 +
104 + private static final String OPTICAL_CONNECTIVITY_ID_COUNTER = "optical-connectivity-id";
105 +
106 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
107 + protected IntentService intentService;
108 +
109 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
110 + protected PathService pathService;
111 +
112 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
113 + protected CoreService coreService;
114 +
115 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
116 + protected LinkService linkService;
117 +
118 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
119 + protected MastershipService mastershipService;
120 +
121 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
122 + protected ClusterService clusterService;
123 +
124 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
125 + protected DeviceService deviceService;
126 +
127 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
128 + protected StorageService storageService;
129 +
130 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
131 + protected NetworkConfigService networkConfigService;
132 +
133 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
134 + protected ResourceService resourceService;
135 +
136 +
137 + private ApplicationId appId;
138 +
139 + private AtomicCounter idCounter;
140 +
141 + private LinkListener linkListener = new InternalLinkListener();
142 + private IntentListener intentListener = new InternalIntentListener();
143 +
144 + private Map<PacketLinkRealizedByOptical, OpticalConnectivity> linkPathMap = new ConcurrentHashMap<>();
145 +
146 + // TODO this should be stored to distributed store
147 + private Map<OpticalConnectivityId, OpticalConnectivity> connectivities = new ConcurrentHashMap<>();
148 +
149 + // TODO this should be stored to distributed store
150 + // Map of cross connect link and installed path which uses the link
151 + private Set<Link> usedCrossConnectLinks = Sets.newConcurrentHashSet();
152 +
153 + @Activate
154 + protected void activate() {
155 + appId = coreService.registerApplication("org.onosproject.newoptical");
156 +
157 + idCounter = storageService.atomicCounterBuilder()
158 + .withName(OPTICAL_CONNECTIVITY_ID_COUNTER)
159 + .withMeteringDisabled()
160 + .build()
161 + .asAtomicCounter();
162 +
163 + eventDispatcher.addSink(OpticalPathEvent.class, listenerRegistry);
164 + linkService.addListener(linkListener);
165 + intentService.addListener(intentListener);
166 +
167 + log.info("Started");
168 + }
169 +
170 + @Deactivate
171 + protected void deactivate() {
172 + intentService.removeListener(intentListener);
173 + linkService.removeListener(linkListener);
174 +
175 + log.info("Stopped");
176 + }
177 +
178 + @Override
179 + public OpticalConnectivityId setupConnectivity(ConnectPoint ingress, ConnectPoint egress,
180 + Bandwidth bandwidth, Duration latency) {
181 + checkNotNull(ingress);
182 + checkNotNull(egress);
183 + log.info("setupConnectivity({}, {}, {}, {})", ingress, egress, bandwidth, latency);
184 +
185 + bandwidth = (bandwidth == null) ? Bandwidth.bps(0) : bandwidth;
186 +
187 + Set<Path> paths = pathService.getPaths(ingress.deviceId(), egress.deviceId(),
188 + new BandwidthLinkWeight(bandwidth));
189 + if (paths.isEmpty()) {
190 + log.warn("Unable to find multi-layer path.");
191 + return null;
192 + }
193 +
194 + // Search path with available cross connect points
195 + for (Path path : paths) {
196 + OpticalConnectivityId id = setupPath(path, bandwidth, latency);
197 + if (id != null) {
198 + log.info("Assigned OpticalConnectivityId: {}", id);
199 + return id;
200 + }
201 + }
202 +
203 + return null;
204 + }
205 +
206 + @Override
207 + public OpticalConnectivityId setupPath(Path path, Bandwidth bandwidth, Duration latency) {
208 + checkNotNull(path);
209 + log.info("setupPath({}, {}, {})", path, bandwidth, latency);
210 +
211 + // validate optical path
212 + List<Pair<ConnectPoint, ConnectPoint>> xcPointPairs = getCrossConnectPoints(path);
213 + if (!checkXcPoints(xcPointPairs)) {
214 + // Can't setup path if cross connect points are mismatched
215 + return null;
216 + }
217 +
218 + OpticalConnectivity connectivity = createConnectivity(path, bandwidth, latency);
219 +
220 + // create intents from cross connect points and set connectivity information
221 + List<Intent> intents = createIntents(xcPointPairs, connectivity);
222 +
223 + // store cross connect port usage
224 + path.links().stream().filter(this::isCrossConnectLink)
225 + .forEach(usedCrossConnectLinks::add);
226 +
227 + // Submit the intents
228 + for (Intent i : intents) {
229 + intentService.submit(i);
230 + log.debug("Submitted an intent: {}", i);
231 + }
232 +
233 + return connectivity.id();
234 + }
235 +
236 + private OpticalConnectivity createConnectivity(Path path, Bandwidth bandwidth, Duration latency) {
237 + OpticalConnectivityId id = OpticalConnectivityId.of(idCounter.getAndIncrement());
238 + OpticalConnectivity connectivity = new OpticalConnectivity(id, path, bandwidth, latency);
239 +
240 + ConnectPoint ingress = path.src();
241 + ConnectPoint egress = path.dst();
242 +
243 + Intent pktIntent = PointToPointIntent.builder()
244 + .appId(appId)
245 + .ingressPoint(ingress)
246 + .egressPoint(egress)
247 + .key(Key.of(id.id(), appId))
248 + .build();
249 +
250 + connectivity.setIntentId(pktIntent.id());
251 +
252 + // store connectivity information
253 + connectivities.put(connectivity.id(), connectivity);
254 +
255 + return connectivity;
256 + }
257 +
258 + @Override
259 + public boolean removeConnectivity(OpticalConnectivityId id) {
260 + log.info("removeConnectivity({})", id);
261 + OpticalConnectivity connectivity = connectivities.remove(id);
262 +
263 + if (connectivity == null) {
264 + return false;
265 + }
266 +
267 + // TODO withdraw intent only if all of connectivities that use the optical path are withdrawn
268 + connectivity.getRealizingLinks().forEach(l -> {
269 + Intent intent = intentService.getIntent(l.realizingIntentKey());
270 + intentService.withdraw(intent);
271 + });
272 +
273 + return true;
274 + }
275 +
276 + @Override
277 + public List<Link> getPath(OpticalConnectivityId id) {
278 + OpticalConnectivity connectivity = connectivities.get(id);
279 + if (connectivity == null) {
280 + return null;
281 + }
282 +
283 + return ImmutableList.copyOf(connectivity.links());
284 + }
285 +
286 + /**
287 + * Returns list of (optical, packet) pairs of cross connection points of missing optical path sections.
288 + *
289 + * Scans the given multi-layer path and looks for sections that use cross connect links.
290 + * The ingress and egress points in the optical layer are combined to the packet layer ports, and
291 + * are returned in a list.
292 + *
293 + * @param path the multi-layer path
294 + * @return List of cross connect link's (packet port, optical port) pairs
295 + */
296 + private List<Pair<ConnectPoint, ConnectPoint>> getCrossConnectPoints(Path path) {
297 + List<Pair<ConnectPoint, ConnectPoint>> xcPointPairs = new LinkedList<>();
298 + boolean scanning = false;
299 +
300 + for (Link link : path.links()) {
301 + if (!isCrossConnectLink(link)) {
302 + continue;
303 + }
304 +
305 + if (scanning) {
306 + // link.src() is packet, link.dst() is optical
307 + xcPointPairs.add(Pair.of(checkNotNull(link.src()), checkNotNull(link.dst())));
308 + scanning = false;
309 + } else {
310 + // link.src() is optical, link.dst() is packet
311 + xcPointPairs.add(Pair.of(checkNotNull(link.dst()), checkNotNull(link.src())));
312 + scanning = true;
313 + }
314 + }
315 +
316 + return xcPointPairs;
317 + }
318 +
319 + /**
320 + * Checks if optical cross connect points are of same type.
321 + *
322 + * @param xcPointPairs list of cross connection points
323 + * @return true if cross connect point pairs are of same type, false otherwise
324 + */
325 + private boolean checkXcPoints(List<Pair<ConnectPoint, ConnectPoint>> xcPointPairs) {
326 + checkArgument(xcPointPairs.size() % 2 == 0);
327 +
328 + Iterator<Pair<ConnectPoint, ConnectPoint>> itr = xcPointPairs.iterator();
329 +
330 + while (itr.hasNext()) {
331 + // checkArgument at start ensures we'll always have pairs of connect points
332 + Pair<ConnectPoint, ConnectPoint> src = itr.next();
333 + Pair<ConnectPoint, ConnectPoint> dst = itr.next();
334 +
335 + Device.Type srcType = deviceService.getDevice(src.getKey().deviceId()).type();
336 + Device.Type dstType = deviceService.getDevice(dst.getKey().deviceId()).type();
337 +
338 + // Only support connections between identical port types
339 + if (srcType != dstType) {
340 + log.warn("Unsupported mix of cross connect points");
341 + return false;
342 + }
343 + }
344 +
345 + return true;
346 + }
347 +
348 + /**
349 + * Scans the list of cross connection points and returns a list of optical connectivity intents.
350 + * During the process, store intent ID and its realizing link information to given connectivity object.
351 + *
352 + * @param xcPointPairs list of cross connection points
353 + * @return list of optical connectivity intents
354 + */
355 + private List<Intent> createIntents(List<Pair<ConnectPoint, ConnectPoint>> xcPointPairs,
356 + OpticalConnectivity connectivity) {
357 + checkArgument(xcPointPairs.size() % 2 == 0);
358 +
359 + List<Intent> intents = new LinkedList<>();
360 + Iterator<Pair<ConnectPoint, ConnectPoint>> itr = xcPointPairs.iterator();
361 +
362 + while (itr.hasNext()) {
363 + // checkArgument at start ensures we'll always have pairs of connect points
364 + Pair<ConnectPoint, ConnectPoint> src = itr.next();
365 + Pair<ConnectPoint, ConnectPoint> dst = itr.next();
366 +
367 + Port srcPort = deviceService.getPort(src.getKey().deviceId(), src.getKey().port());
368 + Port dstPort = deviceService.getPort(dst.getKey().deviceId(), dst.getKey().port());
369 +
370 + if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
371 + // Create OTN circuit
372 + OpticalCircuitIntent circuitIntent = OpticalCircuitIntent.builder()
373 + .appId(appId)
374 + .src(src.getKey())
375 + .dst(dst.getKey())
376 + .signalType(CltSignalType.CLT_10GBE)
377 + .bidirectional(true)
378 + .build();
379 + intents.add(circuitIntent);
380 + PacketLinkRealizedByOptical pLink = PacketLinkRealizedByOptical.create(src.getValue(), dst.getValue(),
381 + circuitIntent);
382 + connectivity.addRealizingLink(pLink);
383 + linkPathMap.put(pLink, connectivity);
384 + } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
385 + // Create lightpath
386 + // FIXME: hardcoded ODU signal type
387 + OpticalConnectivityIntent opticalIntent = OpticalConnectivityIntent.builder()
388 + .appId(appId)
389 + .src(src.getKey())
390 + .dst(dst.getKey())
391 + .signalType(OduSignalType.ODU4)
392 + .bidirectional(true)
393 + .build();
394 + intents.add(opticalIntent);
395 + PacketLinkRealizedByOptical pLink = PacketLinkRealizedByOptical.create(src.getValue(), dst.getValue(),
396 + opticalIntent);
397 + connectivity.addRealizingLink(pLink);
398 + linkPathMap.put(pLink, connectivity);
399 + } else {
400 + log.warn("Unsupported cross connect point types {} {}", srcPort.type(), dstPort.type());
401 + return Collections.emptyList();
402 + }
403 + }
404 +
405 + return intents;
406 + }
407 +
408 + /**
409 + * Verifies if given device type is in packet layer, i.e., ROADM, OTN or ROADM_OTN device.
410 + *
411 + * @param type device type
412 + * @return true if in packet layer, false otherwise
413 + */
414 + private boolean isPacketLayer(Device.Type type) {
415 + return type == Device.Type.SWITCH || type == Device.Type.ROUTER || type == Device.Type.VIRTUAL;
416 + }
417 +
418 + /**
419 + * Verifies if given device type is in packet layer, i.e., switch or router device.
420 + *
421 + * @param type device type
422 + * @return true if in packet layer, false otherwise
423 + */
424 + private boolean isTransportLayer(Device.Type type) {
425 + return type == Device.Type.ROADM || type == Device.Type.OTN || type == Device.Type.ROADM_OTN;
426 + }
427 +
428 + /**
429 + * Verifies if given link forms a cross-connection between packet and optical layer.
430 + *
431 + * @param link the link
432 + * @return true if the link is a cross-connect link, false otherwise
433 + */
434 + private boolean isCrossConnectLink(Link link) {
435 + if (link.type() != Link.Type.OPTICAL) {
436 + return false;
437 + }
438 +
439 + Device.Type src = deviceService.getDevice(link.src().deviceId()).type();
440 + Device.Type dst = deviceService.getDevice(link.dst().deviceId()).type();
441 +
442 + return src != dst &&
443 + ((isPacketLayer(src) && isTransportLayer(dst)) || (isPacketLayer(dst) && isTransportLayer(src)));
444 + }
445 +
446 + /**
447 + * Updates bandwidth resource of given connect point.
448 + * @param cp Connect point
449 + * @param bandwidth New bandwidth
450 + */
451 + private void updatePortBandwidth(ConnectPoint cp, Bandwidth bandwidth) {
452 + NodeId localNode = clusterService.getLocalNode().id();
453 + NodeId sourceMaster = mastershipService.getMasterFor(cp.deviceId());
454 + if (localNode.equals(sourceMaster)) {
455 + log.debug("update Port {} Bandwidth {}", cp, bandwidth);
456 + BandwidthCapacity bwCapacity = networkConfigService.addConfig(cp, BandwidthCapacity.class);
457 + bwCapacity.capacity(bandwidth).apply();
458 + }
459 + }
460 +
461 + /**
462 + * Updates usage information of bandwidth based on connectivity which is established.
463 + * @param connectivity Optical connectivity
464 + */
465 + private void updateBandwidthUsage(OpticalConnectivity connectivity) {
466 + IntentId intentId = connectivity.getIntentId();
467 + if (intentId == null) {
468 + return;
469 + }
470 +
471 + List<Link> links = connectivity.links();
472 +
473 + List<Resource> resources = links.stream().flatMap(l -> Stream.of(l.src(), l.dst()))
474 + .filter(cp -> !isTransportLayer(deviceService.getDevice(cp.deviceId()).type()))
475 + .map(cp -> Resources.continuous(cp.deviceId(), cp.port(),
476 + Bandwidth.class).resource(connectivity.bandwidth().bps()))
477 + .collect(Collectors.toList());
478 +
479 + log.debug("allocating bandwidth for {} : {}", connectivity.getIntentId(), resources);
480 + List<ResourceAllocation> allocations = resourceService.allocate(intentId, resources);
481 + if (allocations.isEmpty()) {
482 + log.warn("Failed to allocate bandwidth {} to {}",
483 + connectivity.bandwidth().bps(), resources);
484 + // TODO any recovery?
485 + }
486 + log.debug("Done allocating bandwidth for {}", connectivity.getIntentId());
487 + }
488 +
489 + /**
490 + * Release bandwidth allocated by given connectivity.
491 + * @param connectivity Optical connectivity
492 + */
493 + private void releaseBandwidthUsage(OpticalConnectivity connectivity) {
494 + IntentId intentId = connectivity.getIntentId();
495 + if (intentId == null) {
496 + return;
497 + }
498 +
499 + log.debug("releasing bandwidth allocated to {}", connectivity.getIntentId());
500 + if (!resourceService.release(connectivity.getIntentId())) {
501 + log.warn("Failed to release bandwidth allocated to {}",
502 + connectivity.getIntentId());
503 + // TODO any recovery?
504 + }
505 + log.debug("DONE releasing bandwidth for {}", connectivity.getIntentId());
506 + }
507 +
508 + private class BandwidthLinkWeight implements LinkWeight {
509 + private Bandwidth bandwidth = null;
510 +
511 + public BandwidthLinkWeight(Bandwidth bandwidth) {
512 + this.bandwidth = bandwidth;
513 + }
514 +
515 + @Override
516 + public double weight(TopologyEdge edge) {
517 + Link l = edge.link();
518 +
519 + // Ignore inactive links
520 + if (l.state() == Link.State.INACTIVE) {
521 + return -1.0;
522 + }
523 +
524 + // Ignore cross connect links with used ports
525 + if (isCrossConnectLink(l) && usedCrossConnectLinks.contains(l)) {
526 + return -1.0;
527 + }
528 +
529 + // Check availability of bandwidth
530 + if (bandwidth != null) {
531 + if (hasEnoughBandwidth(l.src()) && hasEnoughBandwidth(l.dst())) {
532 + return 1.0;
533 + } else {
534 + return -1.0;
535 + }
536 + } else {
537 + // TODO needs to differentiate optical and packet?
538 + if (l.type() == Link.Type.OPTICAL) {
539 + // Transport links
540 + return 1.0;
541 + } else {
542 + // Packet links
543 + return 1.0;
544 + }
545 + }
546 + }
547 +
548 + private boolean hasEnoughBandwidth(ConnectPoint cp) {
549 + if (cp.elementId() instanceof DeviceId) {
550 + Device.Type type = deviceService.getDevice(cp.deviceId()).type();
551 + if (isTransportLayer(type)) {
552 + // Optical ports are assumed to have enough bandwidth
553 + // TODO should look up physical limit?
554 + return true;
555 + }
556 +
557 + ContinuousResource resource = Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class)
558 + .resource(bandwidth.bps());
559 +
560 + return resourceService.isAvailable(resource);
561 + }
562 + return false;
563 + }
564 + }
565 +
566 +
567 + public class InternalIntentListener implements IntentListener {
568 + @Override
569 + public void event(IntentEvent event) {
570 + switch (event.type()) {
571 + case INSTALLED:
572 + log.info("Intent {} installed.", event.subject());
573 + updateCrossConnectLink(event.subject());
574 + break;
575 + case WITHDRAWN:
576 + log.info("Intent {} withdrawn.", event.subject());
577 + removeCrossConnectLinks(event.subject());
578 + break;
579 + case FAILED:
580 + log.info("Intent {} failed.", event.subject());
581 + break;
582 + default:
583 + break;
584 + }
585 + }
586 +
587 + private void updateCrossConnectLink(Intent intent) {
588 + linkPathMap.entrySet().stream()
589 + .filter(e -> e.getKey().realizingIntentKey().equals(intent.key()))
590 + .forEach(e -> {
591 + ConnectPoint packetSrc = e.getKey().src();
592 + ConnectPoint packetDst = e.getKey().dst();
593 + Bandwidth bw = e.getKey().bandwidth();
594 + // Updates bandwidth of packet ports
595 + updatePortBandwidth(packetSrc, bw);
596 + updatePortBandwidth(packetDst, bw);
597 +
598 + OpticalConnectivity connectivity = e.getValue();
599 + connectivity.setLinkEstablished(packetSrc, packetDst);
600 +
601 + if (e.getValue().isAllRealizingLinkEstablished()) {
602 + updateBandwidthUsage(connectivity);
603 +
604 + // Notifies listeners if all links are established
605 + post(new OpticalPathEvent(OpticalPathEvent.Type.PATH_INSTALLED, e.getValue().id()));
606 + }
607 + });
608 + }
609 +
610 + private void removeCrossConnectLinks(Intent intent) {
611 + ConnectPoint src, dst;
612 +
613 + if (intent instanceof OpticalCircuitIntent) {
614 + OpticalCircuitIntent circuit = (OpticalCircuitIntent) intent;
615 + src = circuit.getSrc();
616 + dst = circuit.getDst();
617 + } else if (intent instanceof OpticalConnectivityIntent) {
618 + OpticalConnectivityIntent conn = (OpticalConnectivityIntent) intent;
619 + src = conn.getSrc();
620 + dst = conn.getDst();
621 + } else {
622 + return;
623 + }
624 +
625 + removeXcLinkUsage(src);
626 + removeXcLinkUsage(dst);
627 +
628 + // Set bandwidth of 0 to cross connect ports
629 + Bandwidth bw = Bandwidth.bps(0);
630 + linkPathMap.entrySet().stream()
631 + .filter(e -> e.getKey().realizingIntentKey().equals(intent.key()))
632 + .forEach(e -> {
633 + ConnectPoint packetSrc = e.getKey().src();
634 + ConnectPoint packetDst = e.getKey().dst();
635 + // Updates bandwidth of packet ports
636 + updatePortBandwidth(packetSrc, bw);
637 + updatePortBandwidth(packetDst, bw);
638 + OpticalConnectivity connectivity = e.getValue();
639 + connectivity.setLinkRemoved(packetSrc, packetDst);
640 +
641 + // Notifies listeners if all links are gone
642 + if (e.getValue().isAllRealizingLinkNotEstablished()) {
643 + releaseBandwidthUsage(connectivity);
644 + post(new OpticalPathEvent(OpticalPathEvent.Type.PATH_REMOVED, e.getValue().id()));
645 + }
646 + });
647 + }
648 +
649 + private void removeXcLinkUsage(ConnectPoint cp) {
650 + Optional<Link> link = linkService.getLinks(cp).stream()
651 + .filter(usedCrossConnectLinks::contains)
652 + .findAny();
653 +
654 + if (!link.isPresent()) {
655 + log.warn("Cross connect point {} has no cross connect link.", cp);
656 + return;
657 + }
658 +
659 + usedCrossConnectLinks.remove(link.get());
660 + }
661 + }
662 +
663 +
664 + private class InternalLinkListener implements LinkListener {
665 +
666 + @Override
667 + public void event(LinkEvent event) {
668 + switch (event.type()) {
669 + case LINK_REMOVED:
670 + Link link = event.subject();
671 + Set<PacketLinkRealizedByOptical> pLinks = linkPathMap.keySet().stream()
672 + .filter(l -> l.isBetween(link.src(), link.dst()) || l.isBetween(link.dst(), link.src()))
673 + .collect(Collectors.toSet());
674 +
675 + pLinks.forEach(l -> {
676 + OpticalConnectivity c = linkPathMap.get(l);
677 + // Notifies listeners if all links are gone
678 + if (c.isAllRealizingLinkNotEstablished()) {
679 + post(new OpticalPathEvent(OpticalPathEvent.Type.PATH_REMOVED, c.id()));
680 + }
681 + linkPathMap.remove(l);
682 + });
683 + default:
684 + break;
685 + }
686 + }
687 + }
688 +}
689 +
1 +/*
2 + * Copyright 2016 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.newoptical;
17 +
18 +import com.google.common.annotations.Beta;
19 +import org.onlab.util.Bandwidth;
20 +import org.onosproject.net.ConnectPoint;
21 +import org.onosproject.net.intent.Key;
22 +import org.onosproject.net.intent.OpticalCircuitIntent;
23 +import org.onosproject.net.intent.OpticalConnectivityIntent;
24 +
25 +import static com.google.common.base.Preconditions.checkNotNull;
26 +
27 +/**
28 + * Entity to represent packet link realized by optical intent.
29 + */
30 +@Beta
31 +public class PacketLinkRealizedByOptical {
32 + private final ConnectPoint src, dst;
33 + private final Bandwidth bandwidth;
34 + // TODO should be list of Intent Key?
35 + private final Key realizingIntentKey;
36 + // established=false represents that this (packet) link is expected to be
37 + // discovered after underlying (optical) path has been provisioned.
38 + private boolean established;
39 +
40 + /**
41 + * Creates instance with specified parameters.
42 + *
43 + * @param src source connect point
44 + * @param dst destination connect point
45 + * @param realizingIntentKey key of Optical*Intent that realizes packet link between src and dst
46 + * @param bandwidth assigned bandwidth
47 + */
48 + public PacketLinkRealizedByOptical(ConnectPoint src, ConnectPoint dst,
49 + Key realizingIntentKey, Bandwidth bandwidth) {
50 + this.src = src;
51 + this.dst = dst;
52 + this.realizingIntentKey = realizingIntentKey;
53 + this.bandwidth = bandwidth;
54 + this.established = false;
55 + }
56 +
57 + /**
58 + * Creates PacketLinkRealizedByOptical instance with specified connect points and OpticalCircuitIntent.
59 + * Assigned bandwidth is taken from physical limit of optical link.
60 + *
61 + * @param src source connect point
62 + * @param dst destination connect point
63 + * @param intent OpticalCircuitIntent that realizes packet link between src and dst
64 + * @return
65 + */
66 + public static PacketLinkRealizedByOptical create(ConnectPoint src, ConnectPoint dst,
67 + OpticalCircuitIntent intent) {
68 + checkNotNull(src);
69 + checkNotNull(dst);
70 + checkNotNull(intent);
71 +
72 + long rate = intent.getSignalType().bitRate();
73 + return new PacketLinkRealizedByOptical(src, dst, intent.key(), Bandwidth.bps(rate));
74 + }
75 +
76 + /**
77 + * Creates PacketLinkRealizedByOptical instance with specified connect points and OpticalConnectivityIntent.
78 + * Assigned bandwidth is taken from physical limit of optical link.
79 + *
80 + * @param src source connect point
81 + * @param dst destination connect point
82 + * @param intent OpticalConnectivityIntent that realizes packet link between src and dst
83 + * @return
84 + */
85 + public static PacketLinkRealizedByOptical create(ConnectPoint src, ConnectPoint dst,
86 + OpticalConnectivityIntent intent) {
87 + checkNotNull(src);
88 + checkNotNull(dst);
89 + checkNotNull(intent);
90 +
91 + long rate = intent.getSignalType().bitRate();
92 + return new PacketLinkRealizedByOptical(src, dst, intent.key(), Bandwidth.bps(rate));
93 + }
94 +
95 + /**
96 + * Returns source connect point.
97 + *
98 + * @return source connect point
99 + */
100 + public ConnectPoint src() {
101 + return src;
102 + }
103 +
104 + /**
105 + * Returns destination connect point.
106 + *
107 + * @return destination connect point
108 + */
109 + public ConnectPoint dst() {
110 + return dst;
111 + }
112 +
113 + /**
114 + * Returns assigned bandwidth.
115 + *
116 + * @return assigned bandwidth
117 + */
118 + public Bandwidth bandwidth() {
119 + return bandwidth;
120 + }
121 +
122 + /**
123 + * Returns intent key.
124 + *
125 + * @return intent key
126 + */
127 + public Key realizingIntentKey() {
128 + return realizingIntentKey;
129 + }
130 +
131 + /**
132 + * Returns whether packet link is realized or not.
133 + *
134 + * @return true if packet link is realized. false if not.
135 + */
136 + public boolean isEstablished() {
137 + return established;
138 + }
139 +
140 + /**
141 + * Sets packet link to be established.
142 + *
143 + * @param established status of packet link
144 + */
145 + public void setEstablished(boolean established) {
146 + this.established = established;
147 + }
148 +
149 + /**
150 + * Check if packet link is between specified two connect points.
151 + *
152 + * @param src source connect point
153 + * @param dst destination connect point
154 + * @return true if this link is between src and dst. false if not.
155 + */
156 + public boolean isBetween(ConnectPoint src, ConnectPoint dst) {
157 + return (this.src.equals(src) && this.dst.equals(dst));
158 + }
159 +
160 +}
1 +/*
2 + * Copyright 2016 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.newoptical.api;
17 +
18 +import com.google.common.annotations.Beta;
19 +import com.google.common.base.MoreObjects;
20 +import org.onlab.util.Identifier;
21 +
22 +// TODO: After ResourceManager is made to accept app-defined ResourceConsumer,
23 +// this class should be implemented as ResourceConsumer.
24 +/**
25 + * ID for optical connectivity.
26 + */
27 +@Beta
28 +public final class OpticalConnectivityId extends Identifier<Long> {
29 +
30 + public static OpticalConnectivityId of(long value) {
31 + return new OpticalConnectivityId(value);
32 + }
33 +
34 + OpticalConnectivityId(long value) {
35 + super(value);
36 + }
37 +
38 + @Override
39 + public String toString() {
40 + return MoreObjects.toStringHelper(this)
41 + .add("value", id())
42 + .toString();
43 + }
44 +}
1 +/*
2 + * Copyright 2016 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.newoptical.api;
17 +
18 +import com.google.common.annotations.Beta;
19 +import org.onosproject.event.AbstractEvent;
20 +
21 +/**
22 + * Event related to optical domain path setup.
23 + */
24 +@Beta
25 +public class OpticalPathEvent extends AbstractEvent<OpticalPathEvent.Type, OpticalConnectivityId> {
26 + public enum Type {
27 + PATH_INSTALLED,
28 + PATH_REMOVED
29 + }
30 +
31 + /**
32 + * Creates OpticalPathEvent object with specified type and subject.
33 + * @param type
34 + * @param subject
35 + */
36 + public OpticalPathEvent(Type type, OpticalConnectivityId subject) {
37 + super(type, subject);
38 + }
39 +
40 +}
1 +/*
2 + * Copyright 2016 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.newoptical.api;
17 +
18 +import org.onosproject.event.EventListener;
19 +
20 +/**
21 + * Entity capable of receiving optical path related events.
22 + */
23 +public interface OpticalPathListener extends EventListener<OpticalPathEvent> {
24 +}
1 +/*
2 + * Copyright 2016 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.newoptical.api;
17 +
18 +import com.google.common.annotations.Beta;
19 +import org.onlab.util.Bandwidth;
20 +import org.onosproject.event.ListenerService;
21 +import org.onosproject.net.ConnectPoint;
22 +import org.onosproject.net.Link;
23 +import org.onosproject.net.Path;
24 +
25 +import java.time.Duration;
26 +import java.util.List;
27 +
28 +/**
29 + * Service to setup optical domain connectivity.
30 + */
31 +@Beta
32 +public interface OpticalPathService extends ListenerService<OpticalPathEvent, OpticalPathListener> {
33 +
34 + /**
35 + * Calculates optical path between connect points and sets up connectivity.
36 + *
37 + * @param ingress ingress port
38 + * @param egress egress port
39 + * @param bandwidth required bandwidth. No bandwidth is assured if null.
40 + * @param latency required latency. No latency is assured if null.
41 + * @return ID of created connectivity if successful. null otherwise.
42 + */
43 + OpticalConnectivityId setupConnectivity(ConnectPoint ingress, ConnectPoint egress,
44 + Bandwidth bandwidth, Duration latency);
45 +
46 + /**
47 + * Sets up connectivity along given optical path.
48 + *
49 + * @param path path along which connectivity will be set up
50 + * @param bandwidth required bandwidth. No bandwidth is assured if null.
51 + * @param latency required latency. No latency is assured if null.
52 + * @return true if successful. false otherwise.
53 + */
54 + OpticalConnectivityId setupPath(Path path, Bandwidth bandwidth, Duration latency);
55 +
56 + /**
57 + * Removes connectivity with given ID.
58 + *
59 + * @param id ID of connectivity
60 + * @return true if succeed. false if failed.
61 + */
62 + boolean removeConnectivity(OpticalConnectivityId id);
63 +
64 + /**
65 + * Returns path assigned to given ID.
66 + * @param id ID of connectivity
67 + * @return list of link that compose a path. null if ID is invalid.
68 + */
69 + List<Link> getPath(OpticalConnectivityId id);
70 +}
1 +/*
2 + * Copyright 2016 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 + * API to optical path service.
18 + */
19 +package org.onosproject.newoptical.api;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.newoptical.cli;
17 +
18 +import org.apache.karaf.shell.commands.Argument;
19 +import org.apache.karaf.shell.commands.Command;
20 +import org.onlab.util.Bandwidth;
21 +import org.onosproject.cli.AbstractShellCommand;
22 +import org.onosproject.newoptical.api.OpticalConnectivityId;
23 +import org.onosproject.newoptical.api.OpticalPathService;
24 +import org.onosproject.net.ConnectPoint;
25 +import org.onosproject.net.DeviceId;
26 +import org.onosproject.net.PortNumber;
27 +
28 +@Command(scope = "onos", name = "add-optical-connectivity",
29 + description = "Configure optical domain connectivity")
30 +public class AddOpticalConnectivityCommand extends AbstractShellCommand {
31 +
32 + @Argument(index = 0, name = "ingress", description = "Ingress connect point",
33 + required = true, multiValued = false)
34 + String ingressStr = null;
35 +
36 + @Argument(index = 1, name = "egress", description = "Egress connect point",
37 + required = true, multiValued = false)
38 + String egressStr = null;
39 +
40 + @Argument(index = 2, name = "bandwidth", description = "Bandwidth",
41 + required = false, multiValued = false)
42 + String bandwidthStr = null;
43 +
44 + @Argument(index = 3, name = "latency", description = "Latency",
45 + required = true, multiValued = false)
46 + String latencyStr = null;
47 +
48 +
49 + @Override
50 + protected void execute() {
51 + OpticalPathService opticalPathService = get(OpticalPathService.class);
52 +
53 + ConnectPoint ingress = readConnectPoint(ingressStr);
54 + ConnectPoint egress = readConnectPoint(egressStr);
55 + if (ingress == null || egress == null) {
56 + print("Invalid connect points: %s, %s", ingressStr, egressStr);
57 + return;
58 + }
59 +
60 + Bandwidth bandwidth = (bandwidthStr == null || bandwidthStr.isEmpty()) ? null :
61 + Bandwidth.bps(Long.valueOf(bandwidthStr));
62 +
63 + print("Trying to setup connectivity between %s and %s.", ingress, egress);
64 + OpticalConnectivityId id = opticalPathService.setupConnectivity(ingress, egress, bandwidth, null);
65 + if (id == null) {
66 + print("Failed.");
67 + return;
68 + }
69 + print("Optical path ID : %s", id.id());
70 + }
71 +
72 + private ConnectPoint readConnectPoint(String str) {
73 + String[] strings = str.split("/");
74 + if (strings.length != 2) {
75 + return null;
76 + }
77 +
78 + DeviceId devId = DeviceId.deviceId(strings[0]);
79 + PortNumber port = PortNumber.portNumber(strings[1]);
80 +
81 + return new ConnectPoint(devId, port);
82 + }
83 +
84 +}
1 +/*
2 + * Copyright 2016 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.newoptical.cli;
17 +
18 +import org.apache.karaf.shell.commands.Argument;
19 +import org.apache.karaf.shell.commands.Command;
20 +import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.newoptical.api.OpticalConnectivityId;
22 +import org.onosproject.newoptical.api.OpticalPathService;
23 +
24 +@Command(scope = "onos", name = "remove-optical-connectivity",
25 + description = "Remove optical domain connectivity")
26 +public class RemoveOpticalConnectivityCommand extends AbstractShellCommand {
27 + @Argument(index = 0, name = "id", description = "ID of optical connectivity",
28 + required = true, multiValued = false)
29 + String idStr = null;
30 +
31 + @Override
32 + protected void execute() {
33 + OpticalPathService opticalPathService = get(OpticalPathService.class);
34 +
35 + OpticalConnectivityId id = OpticalConnectivityId.of(Long.valueOf(idStr));
36 +
37 + print("Trying to remove connectivity with id %s.", idStr);
38 + if (opticalPathService.removeConnectivity(id)) {
39 + print(" -- success");
40 + } else {
41 + print(" -- failed");
42 + }
43 +
44 + }
45 +}
1 +/*
2 + * Copyright 2016 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 + * CLI to control optical path service.
18 + */
19 +package org.onosproject.newoptical.cli;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 + * Module to control optical path.
19 + */
20 +package org.onosproject.newoptical;
...\ No newline at end of file ...\ No newline at end of file
1 +<!--
2 + ~ Copyright 2016 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.newoptical.cli.AddOpticalConnectivityCommand"/>
21 + </command>
22 + <command>
23 + <action class="org.onosproject.newoptical.cli.RemoveOpticalConnectivityCommand"/>
24 + </command>
25 + </command-bundle>
26 +
27 +</blueprint>
...@@ -66,8 +66,11 @@ import static org.onosproject.net.optical.device.OpticalDeviceServiceView.optica ...@@ -66,8 +66,11 @@ import static org.onosproject.net.optical.device.OpticalDeviceServiceView.optica
66 * OpticalPathProvisioner listens for event notifications from the Intent F/W. 66 * OpticalPathProvisioner listens for event notifications from the Intent F/W.
67 * It generates one or more opticalConnectivityIntent(s) and submits (or withdraws) to Intent F/W 67 * It generates one or more opticalConnectivityIntent(s) and submits (or withdraws) to Intent F/W
68 * for adding/releasing capacity at the packet layer. 68 * for adding/releasing capacity at the packet layer.
69 + *
70 + * @deprecated in Goldeneye (1.6.0)
69 */ 71 */
70 72
73 +@Deprecated
71 @Component(immediate = true) 74 @Component(immediate = true)
72 public class OpticalPathProvisioner { 75 public class OpticalPathProvisioner {
73 76
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
37 <module>proxyarp</module> 37 <module>proxyarp</module>
38 <module>sdnip</module> 38 <module>sdnip</module>
39 <module>optical</module> 39 <module>optical</module>
40 + <module>newoptical</module>
40 <module>metrics</module> 41 <module>metrics</module>
41 <module>routing</module> 42 <module>routing</module>
42 <module>routing-api</module> 43 <module>routing-api</module>
......