blob: 95b5041b06a90578934b97fdfac63ac51b32c186 [file] [log] [blame]
weibitf32383b2014-10-22 10:17:31 -07001package org.onlab.onos.optical.provisioner;
2
3import java.util.Iterator;
4
5import java.util.Set;
6
7import org.apache.felix.scr.annotations.Activate;
8import org.apache.felix.scr.annotations.Component;
9import org.apache.felix.scr.annotations.Deactivate;
10import org.apache.felix.scr.annotations.Reference;
11import org.apache.felix.scr.annotations.ReferenceCardinality;
12
13import org.onlab.onos.ApplicationId;
14import org.onlab.onos.CoreService;
15import org.onlab.onos.net.ConnectPoint;
16
17import org.onlab.onos.net.Link;
18import org.onlab.onos.net.device.DeviceService;
19
20import org.onlab.onos.net.intent.IdGenerator;
21import org.onlab.onos.net.intent.Intent;
22
23import org.onlab.onos.net.intent.IntentEvent;
24import org.onlab.onos.net.intent.IntentExtensionService;
25import org.onlab.onos.net.intent.IntentId;
26import org.onlab.onos.net.intent.IntentListener;
27import org.onlab.onos.net.intent.IntentService;
28import org.onlab.onos.net.intent.OpticalConnectivityIntent;
29import org.onlab.onos.net.intent.PointToPointIntent;
30import org.onlab.onos.net.link.LinkService;
31import org.onlab.onos.net.topology.TopologyService;
32import org.slf4j.Logger;
33import org.slf4j.LoggerFactory;
34
35/**
36 * OpticalPathProvisioner listens event notifications from the Intent F/W.
37 * It generates one or more opticalConnectivityIntent(s) and submits (or withdraws) to Intent F/W
38 * for adding/releasing capacity at the packet layer.
39 *
40 */
41
42@Component(immediate = true)
43public class OpticalPathProvisioner {
44
45 protected static final Logger log = LoggerFactory
46 .getLogger(OpticalPathProvisioner.class);
47
48 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
49 private IntentService intentService;
50
51 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
52 private IntentExtensionService intentExtensionService;
53
54 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
55 protected LinkService linkService;
56
57 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 protected DeviceService deviceService;
59
60 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
61 protected TopologyService topologyService;
62
63 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
64 protected CoreService coreService;
65
66 // protected LinkResourceService resourceService;
67
68 private ApplicationId appId;
69 private static long intentId = 0x9000000;
70
71 protected IdGenerator<IntentId> intentIdGenerator;
72
73 private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner();
74
75 @Activate
76 protected void activate() {
77 intentService.addListener(pathProvisioner);
78 appId = coreService.registerApplication("org.onlab.onos.optical");
79 log.info("Starting optical path provisoning...");
80 }
81
82 @Deactivate
83 protected void deactivate() {
84 intentService.removeListener(pathProvisioner);
85 }
86
87 public class InternalOpticalPathProvisioner implements IntentListener {
88 @Override
89 public void event(IntentEvent event) {
90 switch (event.type()) {
91 case SUBMITTED:
92 break;
93 case INSTALLED:
94 break;
95 case FAILED:
96 log.info("intent {} failed, calling optical path provisioning APP.", event.subject());
97 setuplightpath(event.subject());
98 break;
99 case WITHDRAWN:
100 log.info("intent {} withdrawn.", event.subject());
101 teardownLightpath(event.subject());
102 break;
103 default:
104 break;
105 }
106 }
107
108 private void setuplightpath(Intent intent) {
109 // TODO: considering user policies and optical reach, may generate more OpticalConnectivityIntents
110 if (!intent.equals(PointToPointIntent.class)) {
111 return;
112 }
113
114 PointToPointIntent pktIntent = (PointToPointIntent) intent;
115 if (pktIntent.ingressPoint() == null || pktIntent.egressPoint() == null) {
116 return;
117 }
118
119 // Set<Port> port1 = deviceService.getPorts(pktIntent.ingressPoint().deviceId());
120
121 Set<Link> srcLink = linkService.getLinks(pktIntent.ingressPoint());
122 Set<Link> dstLink = linkService.getLinks(pktIntent.egressPoint());
123
124 if (srcLink.isEmpty() || dstLink.isEmpty()) {
125 return;
126 }
127
128 Iterator<Link> itrSrc = srcLink.iterator();
129 Iterator<Link> itrDst = dstLink.iterator();
130
131 if (!itrSrc.next().annotations().value("linkType").equals("PktOptLink")) {
132 return;
133 }
134 if (!itrDst.next().annotations().value("linkType").equals("PktOptLink")) {
135 return;
136 }
137
138 ConnectPoint srcWdmPoint = itrSrc.next().dst();
139 ConnectPoint dstWdmPoint = itrDst.next().dst();
140
141 OpticalConnectivityIntent opticalIntent =
142 new OpticalConnectivityIntent(new IntentId(intentId++),
143 srcWdmPoint,
144 dstWdmPoint);
145
146 log.info(opticalIntent.toString());
147 intentService.submit(opticalIntent);
148 }
149
150 private void teardownLightpath(Intent intent) {
151 // TODO: tear down the idle lightpath if the utilization is close to zero.
152 }
153
154 }
155
156}