weibit

optical intent module

Change-Id: Ifa405ab1d883b293d349f1b66d26a05a0724691f
1 package org.onlab.onos.optical.provisioner; 1 package org.onlab.onos.optical.provisioner;
2 2
3 +import java.util.ArrayList;
4 +import java.util.HashMap;
3 import java.util.Iterator; 5 import java.util.Iterator;
4 - 6 +import java.util.Map;
7 +import java.util.Map.Entry;
5 import java.util.Set; 8 import java.util.Set;
6 9
7 import org.apache.felix.scr.annotations.Activate; 10 import org.apache.felix.scr.annotations.Activate;
...@@ -9,25 +12,25 @@ import org.apache.felix.scr.annotations.Component; ...@@ -9,25 +12,25 @@ import org.apache.felix.scr.annotations.Component;
9 import org.apache.felix.scr.annotations.Deactivate; 12 import org.apache.felix.scr.annotations.Deactivate;
10 import org.apache.felix.scr.annotations.Reference; 13 import org.apache.felix.scr.annotations.Reference;
11 import org.apache.felix.scr.annotations.ReferenceCardinality; 14 import org.apache.felix.scr.annotations.ReferenceCardinality;
12 -
13 import org.onlab.onos.ApplicationId; 15 import org.onlab.onos.ApplicationId;
14 import org.onlab.onos.CoreService; 16 import org.onlab.onos.CoreService;
15 import org.onlab.onos.net.ConnectPoint; 17 import org.onlab.onos.net.ConnectPoint;
16 -
17 import org.onlab.onos.net.Link; 18 import org.onlab.onos.net.Link;
19 +import org.onlab.onos.net.Path;
18 import org.onlab.onos.net.device.DeviceService; 20 import org.onlab.onos.net.device.DeviceService;
19 -
20 -import org.onlab.onos.net.intent.IdGenerator;
21 import org.onlab.onos.net.intent.Intent; 21 import org.onlab.onos.net.intent.Intent;
22 -
23 import org.onlab.onos.net.intent.IntentEvent; 22 import org.onlab.onos.net.intent.IntentEvent;
24 import org.onlab.onos.net.intent.IntentExtensionService; 23 import org.onlab.onos.net.intent.IntentExtensionService;
25 -import org.onlab.onos.net.intent.IntentId;
26 import org.onlab.onos.net.intent.IntentListener; 24 import org.onlab.onos.net.intent.IntentListener;
27 import org.onlab.onos.net.intent.IntentService; 25 import org.onlab.onos.net.intent.IntentService;
28 import org.onlab.onos.net.intent.OpticalConnectivityIntent; 26 import org.onlab.onos.net.intent.OpticalConnectivityIntent;
29 import org.onlab.onos.net.intent.PointToPointIntent; 27 import org.onlab.onos.net.intent.PointToPointIntent;
30 import org.onlab.onos.net.link.LinkService; 28 import org.onlab.onos.net.link.LinkService;
29 +import org.onlab.onos.net.resource.LinkResourceService;
30 +import org.onlab.onos.net.topology.LinkWeight;
31 +import org.onlab.onos.net.topology.Topology;
32 +import org.onlab.onos.net.topology.TopologyEdge;
33 +import org.onlab.onos.net.topology.TopologyGraph;
31 import org.onlab.onos.net.topology.TopologyService; 34 import org.onlab.onos.net.topology.TopologyService;
32 import org.slf4j.Logger; 35 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory; 36 import org.slf4j.LoggerFactory;
...@@ -63,12 +66,12 @@ public class OpticalPathProvisioner { ...@@ -63,12 +66,12 @@ public class OpticalPathProvisioner {
63 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 66 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
64 protected CoreService coreService; 67 protected CoreService coreService;
65 68
66 - // protected LinkResourceService resourceService; 69 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
70 + protected LinkResourceService resourceService;
67 71
68 private ApplicationId appId; 72 private ApplicationId appId;
69 - private static long intentId = 0x9000000;
70 73
71 - protected IdGenerator<IntentId> intentIdGenerator; 74 + //protected <IntentId> intentIdGenerator;
72 75
73 private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner(); 76 private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner();
74 77
...@@ -106,7 +109,7 @@ public class OpticalPathProvisioner { ...@@ -106,7 +109,7 @@ public class OpticalPathProvisioner {
106 } 109 }
107 110
108 private void setuplightpath(Intent intent) { 111 private void setuplightpath(Intent intent) {
109 - // TODO: considering user policies and optical reach, may generate more OpticalConnectivityIntents 112 + // TODO: considering user policies and optical reach
110 if (!intent.equals(PointToPointIntent.class)) { 113 if (!intent.equals(PointToPointIntent.class)) {
111 return; 114 return;
112 } 115 }
...@@ -116,35 +119,103 @@ public class OpticalPathProvisioner { ...@@ -116,35 +119,103 @@ public class OpticalPathProvisioner {
116 return; 119 return;
117 } 120 }
118 121
119 - // Set<Port> port1 = deviceService.getPorts(pktIntent.ingressPoint().deviceId()); 122 + Topology topology = topologyService.currentTopology();
120 - 123 + TopologyGraph graph = topologyService.getGraph(topology);
121 - Set<Link> srcLink = linkService.getLinks(pktIntent.ingressPoint()); 124 +
122 - Set<Link> dstLink = linkService.getLinks(pktIntent.egressPoint()); 125 + LinkWeight weight = new LinkWeight() {
123 - 126 + @Override
124 - if (srcLink.isEmpty() || dstLink.isEmpty()) { 127 + public double weight(TopologyEdge edge) {
128 + boolean isOptical = false;
129 + String t = edge.link().annotations().value("linkType");
130 + if (t.equals("WDM")) {
131 + isOptical = true;
132 + }
133 + if (isOptical) {
134 + return 1000; // optical links
135 + } else {
136 + return 10; // packet links
137 + }
138 + }
139 + };
140 +
141 + Set<Path> paths = topologyService.getPaths(topology,
142 + pktIntent.ingressPoint().deviceId(),
143 + pktIntent.egressPoint().deviceId(),
144 + weight);
145 +
146 + if (paths.isEmpty()) {
125 return; 147 return;
126 } 148 }
127 149
128 - Iterator<Link> itrSrc = srcLink.iterator(); 150 + ConnectPoint srcWdmPoint = null;
129 - Iterator<Link> itrDst = dstLink.iterator(); 151 + ConnectPoint dstWdmPoint = null;
130 - 152 + Iterator<Path> itrPath = paths.iterator();
131 - if (!itrSrc.next().annotations().value("linkType").equals("PktOptLink")) { 153 + Path firstPath = itrPath.next();
132 - return; 154 + log.info(firstPath.toString());
133 - } 155 +
134 - if (!itrDst.next().annotations().value("linkType").equals("PktOptLink")) { 156 + ArrayList<Map<ConnectPoint, ConnectPoint>> connectionList = new ArrayList<>();
135 - return; 157 +
158 + Iterator<Link> itrLink = firstPath.links().iterator();
159 + while (itrLink.hasNext()) {
160 + Link link1 = itrLink.next();
161 + if (!isOpticalLink(link1)) {
162 + continue;
163 + } else {
164 + srcWdmPoint = link1.dst();
165 + dstWdmPoint = srcWdmPoint;
166 + }
167 +
168 + while (true) {
169 +
170 + if (itrLink.hasNext()) {
171 + Link link2 = itrLink.next();
172 + dstWdmPoint = link2.src();
173 + } else {
174 + break;
175 + }
176 +
177 + if (itrLink.hasNext()) {
178 + Link link3 = itrLink.next();
179 + if (!isOpticalLink(link3)) {
180 + break;
181 + }
182 + } else {
183 + break;
184 + }
185 + }
186 +
187 + Map<ConnectPoint, ConnectPoint> pair =
188 + new HashMap<ConnectPoint, ConnectPoint>();
189 + pair.put(srcWdmPoint, dstWdmPoint);
190 +
191 + connectionList.add(pair);
136 } 192 }
137 193
138 - ConnectPoint srcWdmPoint = itrSrc.next().dst(); 194 + for (Map<ConnectPoint, ConnectPoint> map : connectionList) {
139 - ConnectPoint dstWdmPoint = itrDst.next().dst(); 195 + for (Entry<ConnectPoint, ConnectPoint> entry : map.entrySet()) {
196 +
197 + ConnectPoint src = entry.getKey();
198 + ConnectPoint dst = entry.getValue();
140 199
141 - OpticalConnectivityIntent opticalIntent = 200 + Intent opticalIntent = new OpticalConnectivityIntent(appId,
142 - new OpticalConnectivityIntent(new IntentId(intentId++), 201 + srcWdmPoint,
143 - srcWdmPoint, 202 + dstWdmPoint);
144 - dstWdmPoint);
145 203
146 - log.info(opticalIntent.toString()); 204 + intentService.submit(opticalIntent);
147 - intentService.submit(opticalIntent); 205 +
206 + log.info(opticalIntent.toString());
207 + }
208 + }
209 +
210 + }
211 +
212 + private boolean isOpticalLink(Link link) {
213 + boolean isOptical = false;
214 + String t = link.annotations().value("linkType");
215 + if (t.equals("WDM") || t.equals("PktOptLink")) {
216 + isOptical = true;
217 + }
218 + return isOptical;
148 } 219 }
149 220
150 private void teardownLightpath(Intent intent) { 221 private void teardownLightpath(Intent intent) {
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 +import org.onlab.onos.ApplicationId;
3 import org.onlab.onos.net.ConnectPoint; 4 import org.onlab.onos.net.ConnectPoint;
4 5
5 /** 6 /**
6 - * An optical layer Intent for a connectivity from a Transponder port to another 7 + * An optical layer Intent for a connectivity from one Transponder port to another
7 * Transponder port. No trafficSelector as well as trafficTreament are needed. 8 * Transponder port. No trafficSelector as well as trafficTreament are needed.
8 * 9 *
9 */ 10 */
10 -public class OpticalConnectivityIntent extends AbstractIntent { 11 +public class OpticalConnectivityIntent extends Intent {
11 protected ConnectPoint src; 12 protected ConnectPoint src;
12 protected ConnectPoint dst; 13 protected ConnectPoint dst;
13 14
...@@ -18,8 +19,9 @@ public class OpticalConnectivityIntent extends AbstractIntent { ...@@ -18,8 +19,9 @@ public class OpticalConnectivityIntent extends AbstractIntent {
18 * @param src The source transponder port. 19 * @param src The source transponder port.
19 * @param dst The destination transponder port. 20 * @param dst The destination transponder port.
20 */ 21 */
21 - public OpticalConnectivityIntent(IntentId id, ConnectPoint src, ConnectPoint dst) { 22 + public OpticalConnectivityIntent(ApplicationId appId, ConnectPoint src, ConnectPoint dst) {
22 - super(id); 23 + super(id(OpticalConnectivityIntent.class, src, dst),
24 + appId, null);
23 this.src = src; 25 this.src = src;
24 this.dst = dst; 26 this.dst = dst;
25 } 27 }
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 import java.util.Collection; 3 import java.util.Collection;
4 -import java.util.Objects;
5 4
5 +import org.onlab.onos.ApplicationId;
6 import org.onlab.onos.net.ConnectPoint; 6 import org.onlab.onos.net.ConnectPoint;
7 import org.onlab.onos.net.Link; 7 import org.onlab.onos.net.Link;
8 import org.onlab.onos.net.Path; 8 import org.onlab.onos.net.Path;
...@@ -11,15 +11,18 @@ import org.onlab.onos.net.flow.TrafficTreatment; ...@@ -11,15 +11,18 @@ import org.onlab.onos.net.flow.TrafficTreatment;
11 11
12 import com.google.common.base.MoreObjects; 12 import com.google.common.base.MoreObjects;
13 13
14 -public class OpticalPathIntent extends OpticalConnectivityIntent implements InstallableIntent { 14 +public class OpticalPathIntent extends OpticalConnectivityIntent {
15 -
16 private final Path path; 15 private final Path path;
17 private final TrafficSelector opticalMatch; 16 private final TrafficSelector opticalMatch;
18 private final TrafficTreatment opticalAction; 17 private final TrafficTreatment opticalAction;
19 18
20 - public OpticalPathIntent(IntentId id, TrafficSelector match, TrafficTreatment action, 19 + public OpticalPathIntent(ApplicationId appId,
21 - ConnectPoint ingressPort, ConnectPoint egressPort, 20 + ConnectPoint src,
22 - Path path) { 21 + ConnectPoint dst,
22 + TrafficSelector match,
23 + TrafficTreatment action,
24 + Path path) {
25 + super(appId, src, dst);
23 this.opticalMatch = match; 26 this.opticalMatch = match;
24 this.opticalAction = action; 27 this.opticalAction = action;
25 this.path = path; 28 this.path = path;
...@@ -44,32 +47,11 @@ public class OpticalPathIntent extends OpticalConnectivityIntent implements Inst ...@@ -44,32 +47,11 @@ public class OpticalPathIntent extends OpticalConnectivityIntent implements Inst
44 } 47 }
45 48
46 @Override 49 @Override
47 - public boolean equals(Object o) { 50 + public boolean isInstallable() {
48 - if (this == o) {
49 - return true;
50 - }
51 - if (o == null || getClass() != o.getClass()) {
52 - return false;
53 - }
54 - if (!super.equals(o)) {
55 - return false;
56 - }
57 -
58 - OpticalPathIntent that = (OpticalPathIntent) o;
59 -
60 - if (!path.equals(that.path)) {
61 - return false;
62 - }
63 -
64 return true; 51 return true;
65 } 52 }
66 53
67 @Override 54 @Override
68 - public int hashCode() {
69 - return Objects.hash(super.hashCode(), path);
70 - }
71 -
72 - @Override
73 public String toString() { 55 public String toString() {
74 return MoreObjects.toStringHelper(getClass()) 56 return MoreObjects.toStringHelper(getClass())
75 .add("id", id()) 57 .add("id", id())
...@@ -81,7 +63,6 @@ public class OpticalPathIntent extends OpticalConnectivityIntent implements Inst ...@@ -81,7 +63,6 @@ public class OpticalPathIntent extends OpticalConnectivityIntent implements Inst
81 .toString(); 63 .toString();
82 } 64 }
83 65
84 - @Override
85 public Collection<Link> requiredLinks() { 66 public Collection<Link> requiredLinks() {
86 return path.links(); 67 return path.links();
87 } 68 }
......
...@@ -3,7 +3,7 @@ package org.onlab.onos.net.intent.impl; ...@@ -3,7 +3,7 @@ package org.onlab.onos.net.intent.impl;
3 import static org.slf4j.LoggerFactory.getLogger; 3 import static org.slf4j.LoggerFactory.getLogger;
4 4
5 import java.util.ArrayList; 5 import java.util.ArrayList;
6 - 6 +import java.util.Iterator;
7 import java.util.List; 7 import java.util.List;
8 import java.util.Set; 8 import java.util.Set;
9 9
...@@ -12,24 +12,28 @@ import org.apache.felix.scr.annotations.Component; ...@@ -12,24 +12,28 @@ import org.apache.felix.scr.annotations.Component;
12 import org.apache.felix.scr.annotations.Deactivate; 12 import org.apache.felix.scr.annotations.Deactivate;
13 import org.apache.felix.scr.annotations.Reference; 13 import org.apache.felix.scr.annotations.Reference;
14 import org.apache.felix.scr.annotations.ReferenceCardinality; 14 import org.apache.felix.scr.annotations.ReferenceCardinality;
15 +import org.onlab.onos.CoreService;
15 import org.onlab.onos.net.ConnectPoint; 16 import org.onlab.onos.net.ConnectPoint;
16 import org.onlab.onos.net.DefaultEdgeLink; 17 import org.onlab.onos.net.DefaultEdgeLink;
17 -
18 import org.onlab.onos.net.Link; 18 import org.onlab.onos.net.Link;
19 import org.onlab.onos.net.Path; 19 import org.onlab.onos.net.Path;
20 import org.onlab.onos.net.flow.TrafficSelector; 20 import org.onlab.onos.net.flow.TrafficSelector;
21 import org.onlab.onos.net.flow.TrafficTreatment; 21 import org.onlab.onos.net.flow.TrafficTreatment;
22 22
23 -import org.onlab.onos.net.intent.IdGenerator;
24 import org.onlab.onos.net.intent.Intent; 23 import org.onlab.onos.net.intent.Intent;
25 import org.onlab.onos.net.intent.IntentCompiler; 24 import org.onlab.onos.net.intent.IntentCompiler;
26 import org.onlab.onos.net.intent.IntentExtensionService; 25 import org.onlab.onos.net.intent.IntentExtensionService;
27 -import org.onlab.onos.net.intent.IntentId; 26 +
28 import org.onlab.onos.net.intent.OpticalConnectivityIntent; 27 import org.onlab.onos.net.intent.OpticalConnectivityIntent;
29 import org.onlab.onos.net.intent.OpticalPathIntent; 28 import org.onlab.onos.net.intent.OpticalPathIntent;
30 -
31 import org.onlab.onos.net.provider.ProviderId; 29 import org.onlab.onos.net.provider.ProviderId;
30 +import org.onlab.onos.net.resource.LinkResourceService;
31 +import org.onlab.onos.net.topology.LinkWeight;
32 import org.onlab.onos.net.topology.PathService; 32 import org.onlab.onos.net.topology.PathService;
33 +import org.onlab.onos.net.topology.Topology;
34 +import org.onlab.onos.net.topology.TopologyEdge;
35 +
36 +import org.onlab.onos.net.topology.TopologyService;
33 import org.slf4j.Logger; 37 import org.slf4j.Logger;
34 38
35 /** 39 /**
...@@ -49,14 +53,17 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -49,14 +53,17 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
49 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 53 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
50 protected PathService pathService; 54 protected PathService pathService;
51 55
52 - // protected LinkResourceService resourceService; 56 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
57 + protected TopologyService topologyService;
53 58
54 - protected IdGenerator<IntentId> intentIdGenerator; 59 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 + protected LinkResourceService resourceService;
61 +
62 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 + protected CoreService coreService;
55 64
56 @Activate 65 @Activate
57 public void activate() { 66 public void activate() {
58 - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
59 - intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
60 intentManager.registerCompiler(OpticalConnectivityIntent.class, this); 67 intentManager.registerCompiler(OpticalConnectivityIntent.class, this);
61 } 68 }
62 69
...@@ -67,29 +74,29 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -67,29 +74,29 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
67 74
68 @Override 75 @Override
69 public List<Intent> compile(OpticalConnectivityIntent intent) { 76 public List<Intent> compile(OpticalConnectivityIntent intent) {
70 - // TO DO: compute multiple paths using the K-shortest path algorithm 77 + // TODO: compute multiple paths using the K-shortest path algorithm
78 + List<Intent> retList = new ArrayList<>();
71 Path path = calculatePath(intent.getSrcConnectPoint(), intent.getDst()); 79 Path path = calculatePath(intent.getSrcConnectPoint(), intent.getDst());
72 - log.info("calculate the lightpath: {}.", path.toString()); 80 + if (path == null) {
81 + return retList;
82 + } else {
83 + log.info("the computed lightpath is : {}.", path.toString());
84 + }
73 85
74 List<Link> links = new ArrayList<>(); 86 List<Link> links = new ArrayList<>();
75 links.add(DefaultEdgeLink.createEdgeLink(intent.getSrcConnectPoint(), true)); 87 links.add(DefaultEdgeLink.createEdgeLink(intent.getSrcConnectPoint(), true));
76 links.addAll(path.links()); 88 links.addAll(path.links());
77 links.add(DefaultEdgeLink.createEdgeLink(intent.getDst(), false)); 89 links.add(DefaultEdgeLink.createEdgeLink(intent.getDst(), false));
78 90
79 - // TO DO: choose a wavelength using the first-fit algorithm
80 TrafficSelector opticalSelector = null; 91 TrafficSelector opticalSelector = null;
81 TrafficTreatment opticalTreatment = null; 92 TrafficTreatment opticalTreatment = null;
82 93
83 - List<Intent> retList = new ArrayList<>();
84 - int wavelength = assignWavelength(path);
85 - log.info("assign the wavelength: {}.", wavelength);
86 -
87 // create a new opticalPathIntent 94 // create a new opticalPathIntent
88 - Intent newIntent = new OpticalPathIntent(intentIdGenerator.getNewId(), 95 + Intent newIntent = new OpticalPathIntent(intent.appId(),
89 - opticalSelector,
90 - opticalTreatment,
91 path.src(), 96 path.src(),
92 path.dst(), 97 path.dst(),
98 + opticalSelector,
99 + opticalTreatment,
93 path); 100 path);
94 101
95 retList.add(newIntent); 102 retList.add(newIntent);
...@@ -97,18 +104,45 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -97,18 +104,45 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
97 return retList; 104 return retList;
98 } 105 }
99 106
100 - private Path calculatePath(ConnectPoint one, ConnectPoint two) { 107 + private Path calculatePath(ConnectPoint start, ConnectPoint end) {
101 - // TODO: K-shortest path computation algorithm 108 + // TODO: support user policies
102 - Set<Path> paths = pathService.getPaths(one.deviceId(), two.deviceId()); 109 + Topology topology = topologyService.currentTopology();
110 + LinkWeight weight = new LinkWeight() {
111 + @Override
112 + public double weight(TopologyEdge edge) {
113 + boolean isOptical = false;
114 + String t = edge.link().annotations().value("linkType");
115 + if (t.equals("WDM")) {
116 + isOptical = true;
117 + }
118 + if (isOptical) {
119 + return 1; // optical links
120 + } else {
121 + return 10000; // packet links
122 + }
123 + }
124 + };
125 +
126 + Set<Path> paths = topologyService.getPaths(topology,
127 + start.deviceId(),
128 + end.deviceId(),
129 + weight);
130 +
131 + Iterator<Path> itr = paths.iterator();
132 + while (itr.hasNext()) {
133 + Path path = itr.next();
134 + if (path.cost() >= 10000) {
135 + itr.remove();
136 + }
137 + }
138 +
103 if (paths.isEmpty()) { 139 if (paths.isEmpty()) {
104 - throw new PathNotFoundException("No optical path from " + one + " to " + two); 140 + log.info("No optical path found from " + start + " to " + end);
141 + return null;
142 + } else {
143 + return paths.iterator().next();
105 } 144 }
106 - return paths.iterator().next();
107 - }
108 145
109 - private int assignWavelength(Path path) {
110 - // TODO: wavelength assignment
111 - return 1;
112 } 146 }
113 147
114 } 148 }
......
...@@ -19,6 +19,7 @@ import org.onlab.onos.net.Link; ...@@ -19,6 +19,7 @@ import org.onlab.onos.net.Link;
19 import org.onlab.onos.net.flow.CompletedBatchOperation; 19 import org.onlab.onos.net.flow.CompletedBatchOperation;
20 import org.onlab.onos.net.flow.DefaultFlowRule; 20 import org.onlab.onos.net.flow.DefaultFlowRule;
21 import org.onlab.onos.net.flow.DefaultTrafficSelector; 21 import org.onlab.onos.net.flow.DefaultTrafficSelector;
22 +import org.onlab.onos.net.flow.DefaultTrafficTreatment;
22 import org.onlab.onos.net.flow.FlowRule; 23 import org.onlab.onos.net.flow.FlowRule;
23 import org.onlab.onos.net.flow.FlowRuleBatchEntry; 24 import org.onlab.onos.net.flow.FlowRuleBatchEntry;
24 import org.onlab.onos.net.flow.FlowRuleBatchOperation; 25 import org.onlab.onos.net.flow.FlowRuleBatchOperation;
...@@ -29,6 +30,12 @@ import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation; ...@@ -29,6 +30,12 @@ import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
29 import org.onlab.onos.net.intent.IntentExtensionService; 30 import org.onlab.onos.net.intent.IntentExtensionService;
30 import org.onlab.onos.net.intent.IntentInstaller; 31 import org.onlab.onos.net.intent.IntentInstaller;
31 import org.onlab.onos.net.intent.OpticalPathIntent; 32 import org.onlab.onos.net.intent.OpticalPathIntent;
33 +import org.onlab.onos.net.resource.Lambda;
34 +import org.onlab.onos.net.resource.LinkResourceAllocations;
35 +import org.onlab.onos.net.resource.LinkResourceRequest;
36 +import org.onlab.onos.net.resource.LinkResourceService;
37 +import org.onlab.onos.net.resource.ResourceRequest;
38 +import org.onlab.onos.net.topology.TopologyService;
32 import org.slf4j.Logger; 39 import org.slf4j.Logger;
33 40
34 import com.google.common.collect.Lists; 41 import com.google.common.collect.Lists;
...@@ -41,7 +48,6 @@ import com.google.common.collect.Lists; ...@@ -41,7 +48,6 @@ import com.google.common.collect.Lists;
41 48
42 @Component(immediate = true) 49 @Component(immediate = true)
43 public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIntent> { 50 public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIntent> {
44 -
45 private final Logger log = getLogger(getClass()); 51 private final Logger log = getLogger(getClass());
46 52
47 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 53 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -53,8 +59,16 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn ...@@ -53,8 +59,16 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
53 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
54 protected CoreService coreService; 60 protected CoreService coreService;
55 61
62 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 + protected TopologyService topologyService;
64 +
65 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 + protected LinkResourceService resourceService;
67 +
56 private ApplicationId appId; 68 private ApplicationId appId;
57 69
70 + final static short WAVELENGTH = 80;
71 +
58 @Activate 72 @Activate
59 public void activate() { 73 public void activate() {
60 appId = coreService.registerApplication("org.onlab.onos.net.intent"); 74 appId = coreService.registerApplication("org.onlab.onos.net.intent");
...@@ -67,12 +81,25 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn ...@@ -67,12 +81,25 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
67 } 81 }
68 82
69 @Override 83 @Override
70 - public Future<CompletedBatchOperation> install(OpticalPathIntent intent) { 84 + public List<FlowRuleBatchOperation> install(OpticalPathIntent intent) {
85 + Lambda la = assignWavelength(intent.path().links());
86 + if (la == null) {
87 + return null;
88 + }
89 + // resourceService.requestResources(la);
90 + // la.toInt();
91 + //intent.selector().criteria();
92 +
93 + //TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
94 + //builder.matchLambdaType(la.toInt())
95 + // .matchInport(intent.getSrcConnectPoint().port());
96 +
71 TrafficSelector.Builder builder = 97 TrafficSelector.Builder builder =
72 DefaultTrafficSelector.builder(intent.selector()); 98 DefaultTrafficSelector.builder(intent.selector());
73 Iterator<Link> links = intent.path().links().iterator(); 99 Iterator<Link> links = intent.path().links().iterator();
74 ConnectPoint prev = links.next().dst(); 100 ConnectPoint prev = links.next().dst();
75 List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); 101 List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
102 + // TODO Generate multiple batches
76 while (links.hasNext()) { 103 while (links.hasNext()) {
77 builder.matchInport(prev.port()); 104 builder.matchInport(prev.port());
78 Link link = links.next(); 105 Link link = links.next();
...@@ -82,47 +109,77 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn ...@@ -82,47 +109,77 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
82 FlowRule rule = new DefaultFlowRule(link.src().deviceId(), 109 FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
83 builder.build(), 110 builder.build(),
84 treatment, 111 treatment,
85 - 100, // priority is set to 100 112 + 100,
86 appId, 113 appId,
87 - 100); // ROADM may need longer cross-connect time, here it is assumed 100ms. 114 + 100,
88 - 115 + true);
89 rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule)); 116 rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule));
90 prev = link.dst(); 117 prev = link.dst();
91 } 118 }
119 + return Lists.newArrayList(new FlowRuleBatchOperation(rules));
120 + }
92 121
93 - FlowRuleBatchOperation batch = new FlowRuleBatchOperation(rules); 122 + private Lambda assignWavelength(List<Link> links) {
94 - Future<CompletedBatchOperation> future = flowRuleService.applyBatch(batch); 123 + // TODO More wavelength assignment algorithm
95 - return future; 124 + int wavenum = 0;
125 + Iterator<Link> itrlink = links.iterator();
126 + for (int i = 1; i <= WAVELENGTH; i++) {
127 + wavenum = i;
128 + boolean found = true;
129 + while (itrlink.hasNext()) {
130 + Link link = itrlink.next();
131 + if (isWavelengthUsed(link, i)) {
132 + found = false;
133 + break;
134 + }
135 + }
136 + // First-Fit wavelength assignment algorithm
137 + if (found) {
138 + break;
139 + }
140 + }
141 +
142 + if (wavenum == 0) {
143 + return null;
144 + }
145 +
146 + Lambda wave = Lambda.valueOf(wavenum);
147 + return wave;
148 + }
149 +
150 + private boolean isWavelengthUsed(Link link, int i) {
151 + Iterable<LinkResourceAllocations> wave = resourceService.getAllocations(link);
152 + for (LinkResourceAllocations ir : wave) {
153 + //if ir.resources().contains(i) {
154 + //}
155 + }
156 + return false;
96 } 157 }
97 158
98 @Override 159 @Override
99 - public Future<CompletedBatchOperation> uninstall(OpticalPathIntent intent) { 160 + public List<FlowRuleBatchOperation> uninstall(OpticalPathIntent intent) {
100 TrafficSelector.Builder builder = 161 TrafficSelector.Builder builder =
101 DefaultTrafficSelector.builder(intent.selector()); 162 DefaultTrafficSelector.builder(intent.selector());
102 Iterator<Link> links = intent.path().links().iterator(); 163 Iterator<Link> links = intent.path().links().iterator();
103 ConnectPoint prev = links.next().dst(); 164 ConnectPoint prev = links.next().dst();
104 List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); 165 List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
105 - 166 + // TODO Generate multiple batches
106 while (links.hasNext()) { 167 while (links.hasNext()) {
107 builder.matchInport(prev.port()); 168 builder.matchInport(prev.port());
108 Link link = links.next(); 169 Link link = links.next();
109 TrafficTreatment treatment = builder() 170 TrafficTreatment treatment = builder()
110 .setOutput(link.src().port()).build(); 171 .setOutput(link.src().port()).build();
111 -
112 FlowRule rule = new DefaultFlowRule(link.src().deviceId(), 172 FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
113 builder.build(), 173 builder.build(),
114 treatment, 174 treatment,
115 100, 175 100,
116 appId, 176 appId,
117 - 100); 177 + 100,
118 - 178 + true);
119 rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, rule)); 179 rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, rule));
120 prev = link.dst(); 180 prev = link.dst();
121 } 181 }
122 - 182 + return Lists.newArrayList(new FlowRuleBatchOperation(rules));
123 - FlowRuleBatchOperation batch = new FlowRuleBatchOperation(rules);
124 - Future<CompletedBatchOperation> future = flowRuleService.applyBatch(batch);
125 - return future;
126 } 183 }
127 184
128 } 185 }
......