Madan Jampani

Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next

Showing 88 changed files with 1165 additions and 1537 deletions
1 package org.onlab.onos.ifwd; 1 package org.onlab.onos.ifwd;
2 2
3 -import static org.slf4j.LoggerFactory.getLogger;
4 -
5 import org.apache.felix.scr.annotations.Activate; 3 import org.apache.felix.scr.annotations.Activate;
6 import org.apache.felix.scr.annotations.Component; 4 import org.apache.felix.scr.annotations.Component;
7 import org.apache.felix.scr.annotations.Deactivate; 5 import org.apache.felix.scr.annotations.Deactivate;
8 import org.apache.felix.scr.annotations.Reference; 6 import org.apache.felix.scr.annotations.Reference;
9 import org.apache.felix.scr.annotations.ReferenceCardinality; 7 import org.apache.felix.scr.annotations.ReferenceCardinality;
8 +import org.onlab.onos.ApplicationId;
9 +import org.onlab.onos.CoreService;
10 import org.onlab.onos.net.Host; 10 import org.onlab.onos.net.Host;
11 import org.onlab.onos.net.HostId; 11 import org.onlab.onos.net.HostId;
12 import org.onlab.onos.net.PortNumber; 12 import org.onlab.onos.net.PortNumber;
...@@ -16,7 +16,6 @@ import org.onlab.onos.net.flow.TrafficSelector; ...@@ -16,7 +16,6 @@ import org.onlab.onos.net.flow.TrafficSelector;
16 import org.onlab.onos.net.flow.TrafficTreatment; 16 import org.onlab.onos.net.flow.TrafficTreatment;
17 import org.onlab.onos.net.host.HostService; 17 import org.onlab.onos.net.host.HostService;
18 import org.onlab.onos.net.intent.HostToHostIntent; 18 import org.onlab.onos.net.intent.HostToHostIntent;
19 -import org.onlab.onos.net.intent.IntentId;
20 import org.onlab.onos.net.intent.IntentService; 19 import org.onlab.onos.net.intent.IntentService;
21 import org.onlab.onos.net.packet.DefaultOutboundPacket; 20 import org.onlab.onos.net.packet.DefaultOutboundPacket;
22 import org.onlab.onos.net.packet.InboundPacket; 21 import org.onlab.onos.net.packet.InboundPacket;
...@@ -28,6 +27,8 @@ import org.onlab.onos.net.topology.TopologyService; ...@@ -28,6 +27,8 @@ import org.onlab.onos.net.topology.TopologyService;
28 import org.onlab.packet.Ethernet; 27 import org.onlab.packet.Ethernet;
29 import org.slf4j.Logger; 28 import org.slf4j.Logger;
30 29
30 +import static org.slf4j.LoggerFactory.getLogger;
31 +
31 /** 32 /**
32 * WORK-IN-PROGRESS: Sample reactive forwarding application using intent framework. 33 * WORK-IN-PROGRESS: Sample reactive forwarding application using intent framework.
33 */ 34 */
...@@ -37,6 +38,9 @@ public class IntentReactiveForwarding { ...@@ -37,6 +38,9 @@ public class IntentReactiveForwarding {
37 private final Logger log = getLogger(getClass()); 38 private final Logger log = getLogger(getClass());
38 39
39 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 40 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
41 + protected CoreService coreService;
42 +
43 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
40 protected TopologyService topologyService; 44 protected TopologyService topologyService;
41 45
42 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 46 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -49,11 +53,11 @@ public class IntentReactiveForwarding { ...@@ -49,11 +53,11 @@ public class IntentReactiveForwarding {
49 protected HostService hostService; 53 protected HostService hostService;
50 54
51 private ReactivePacketProcessor processor = new ReactivePacketProcessor(); 55 private ReactivePacketProcessor processor = new ReactivePacketProcessor();
52 - 56 + private ApplicationId appId;
53 - private static long intentId = 0x123000;
54 57
55 @Activate 58 @Activate
56 public void activate() { 59 public void activate() {
60 + appId = coreService.registerApplication("org.onlab.onos.ifwd");
57 packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); 61 packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2);
58 log.info("Started"); 62 log.info("Started");
59 } 63 }
...@@ -126,9 +130,8 @@ public class IntentReactiveForwarding { ...@@ -126,9 +130,8 @@ public class IntentReactiveForwarding {
126 TrafficSelector selector = DefaultTrafficSelector.builder().build(); 130 TrafficSelector selector = DefaultTrafficSelector.builder().build();
127 TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); 131 TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
128 132
129 - HostToHostIntent intent = 133 + HostToHostIntent intent = new HostToHostIntent(appId, srcId, dstId,
130 - new HostToHostIntent(new IntentId(intentId++), srcId, dstId, 134 + selector, treatment);
131 - selector, treatment);
132 135
133 intentService.submit(intent); 136 intentService.submit(intent);
134 } 137 }
......
1 package org.onlab.onos.sdnip; 1 package org.onlab.onos.sdnip;
2 2
3 -import java.util.List; 3 +import org.onlab.onos.ApplicationId;
4 -
5 import org.onlab.onos.net.ConnectPoint; 4 import org.onlab.onos.net.ConnectPoint;
6 import org.onlab.onos.net.flow.DefaultTrafficSelector; 5 import org.onlab.onos.net.flow.DefaultTrafficSelector;
7 import org.onlab.onos.net.flow.DefaultTrafficTreatment; 6 import org.onlab.onos.net.flow.DefaultTrafficTreatment;
8 import org.onlab.onos.net.flow.TrafficSelector; 7 import org.onlab.onos.net.flow.TrafficSelector;
9 import org.onlab.onos.net.flow.TrafficTreatment; 8 import org.onlab.onos.net.flow.TrafficTreatment;
10 -import org.onlab.onos.net.intent.IntentId;
11 import org.onlab.onos.net.intent.IntentService; 9 import org.onlab.onos.net.intent.IntentService;
12 import org.onlab.onos.net.intent.PointToPointIntent; 10 import org.onlab.onos.net.intent.PointToPointIntent;
13 import org.onlab.onos.sdnip.config.BgpPeer; 11 import org.onlab.onos.sdnip.config.BgpPeer;
...@@ -22,6 +20,8 @@ import org.onlab.packet.IpPrefix; ...@@ -22,6 +20,8 @@ import org.onlab.packet.IpPrefix;
22 import org.slf4j.Logger; 20 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory; 21 import org.slf4j.LoggerFactory;
24 22
23 +import java.util.List;
24 +
25 /** 25 /**
26 * Manages the connectivity requirements between peers. 26 * Manages the connectivity requirements between peers.
27 */ 27 */
...@@ -38,11 +38,13 @@ public class PeerConnectivityManager { ...@@ -38,11 +38,13 @@ public class PeerConnectivityManager {
38 private final InterfaceService interfaceService; 38 private final InterfaceService interfaceService;
39 private final IntentService intentService; 39 private final IntentService intentService;
40 40
41 - // TODO this sucks. 41 + private final ApplicationId appId;
42 - private int intentId = 0;
43 42
44 - public PeerConnectivityManager(SdnIpConfigService configInfoService, 43 + public PeerConnectivityManager(ApplicationId appId,
45 - InterfaceService interfaceService, IntentService intentService) { 44 + SdnIpConfigService configInfoService,
45 + InterfaceService interfaceService,
46 + IntentService intentService) {
47 + this.appId = appId;
46 this.configInfoService = configInfoService; 48 this.configInfoService = configInfoService;
47 this.interfaceService = interfaceService; 49 this.interfaceService = interfaceService;
48 this.intentService = intentService; 50 this.intentService = intentService;
...@@ -53,15 +55,15 @@ public class PeerConnectivityManager { ...@@ -53,15 +55,15 @@ public class PeerConnectivityManager {
53 if (interfaceService.getInterfaces().isEmpty()) { 55 if (interfaceService.getInterfaces().isEmpty()) {
54 56
55 log.warn("The interface in configuration file is empty. " 57 log.warn("The interface in configuration file is empty. "
56 - + "Thus, the SDN-IP application can not be started."); 58 + + "Thus, the SDN-IP application can not be started.");
57 } else if (configInfoService.getBgpPeers().isEmpty()) { 59 } else if (configInfoService.getBgpPeers().isEmpty()) {
58 60
59 log.warn("The BGP peer in configuration file is empty." 61 log.warn("The BGP peer in configuration file is empty."
60 - + "Thus, the SDN-IP application can not be started."); 62 + + "Thus, the SDN-IP application can not be started.");
61 } else if (configInfoService.getBgpSpeakers() == null) { 63 } else if (configInfoService.getBgpSpeakers() == null) {
62 64
63 log.error("The BGP speaker in configuration file is empty. " 65 log.error("The BGP speaker in configuration file is empty. "
64 - + "Thus, the SDN-IP application can not be started."); 66 + + "Thus, the SDN-IP application can not be started.");
65 return; 67 return;
66 } 68 }
67 69
...@@ -80,7 +82,7 @@ public class PeerConnectivityManager { ...@@ -80,7 +82,7 @@ public class PeerConnectivityManager {
80 for (BgpSpeaker bgpSpeaker : configInfoService.getBgpSpeakers() 82 for (BgpSpeaker bgpSpeaker : configInfoService.getBgpSpeakers()
81 .values()) { 83 .values()) {
82 log.debug("Start to set up BGP paths for BGP speaker: {}", 84 log.debug("Start to set up BGP paths for BGP speaker: {}",
83 - bgpSpeaker); 85 + bgpSpeaker);
84 ConnectPoint bgpdConnectPoint = bgpSpeaker.connectPoint(); 86 ConnectPoint bgpdConnectPoint = bgpSpeaker.connectPoint();
85 87
86 List<InterfaceAddress> interfaceAddresses = 88 List<InterfaceAddress> interfaceAddresses =
...@@ -89,14 +91,14 @@ public class PeerConnectivityManager { ...@@ -89,14 +91,14 @@ public class PeerConnectivityManager {
89 for (BgpPeer bgpPeer : configInfoService.getBgpPeers().values()) { 91 for (BgpPeer bgpPeer : configInfoService.getBgpPeers().values()) {
90 92
91 log.debug("Start to set up BGP paths between BGP speaker: {} " 93 log.debug("Start to set up BGP paths between BGP speaker: {} "
92 - + "to BGP peer: {}", bgpSpeaker, bgpPeer); 94 + + "to BGP peer: {}", bgpSpeaker, bgpPeer);
93 95
94 Interface peerInterface = interfaceService.getInterface( 96 Interface peerInterface = interfaceService.getInterface(
95 bgpPeer.connectPoint()); 97 bgpPeer.connectPoint());
96 if (peerInterface == null) { 98 if (peerInterface == null) {
97 log.error("Can not find the corresponding Interface from " 99 log.error("Can not find the corresponding Interface from "
98 - + "configuration for BGP peer {}", 100 + + "configuration for BGP peer {}",
99 - bgpPeer.ipAddress()); 101 + bgpPeer.ipAddress());
100 continue; 102 continue;
101 } 103 }
102 104
...@@ -110,7 +112,7 @@ public class PeerConnectivityManager { ...@@ -110,7 +112,7 @@ public class PeerConnectivityManager {
110 } 112 }
111 if (bgpdAddress == null) { 113 if (bgpdAddress == null) {
112 log.debug("There is no interface IP address for bgpPeer: {}" 114 log.debug("There is no interface IP address for bgpPeer: {}"
113 - + " on interface {}", bgpPeer, bgpPeer.connectPoint()); 115 + + " on interface {}", bgpPeer, bgpPeer.connectPoint());
114 return; 116 return;
115 } 117 }
116 118
...@@ -123,7 +125,7 @@ public class PeerConnectivityManager { ...@@ -123,7 +125,7 @@ public class PeerConnectivityManager {
123 // TODO: The usage of PacketMatchBuilder will be improved, then we 125 // TODO: The usage of PacketMatchBuilder will be improved, then we
124 // only need to new the PacketMatchBuilder once. 126 // only need to new the PacketMatchBuilder once.
125 // By then, the code here will be improved accordingly. 127 // By then, the code here will be improved accordingly.
126 - TrafficSelector selector = DefaultTrafficSelector.builder() 128 + TrafficSelector selector = DefaultTrafficSelector.builder()
127 .matchEthType(Ethernet.TYPE_IPV4) 129 .matchEthType(Ethernet.TYPE_IPV4)
128 .matchIPProtocol(IPv4.PROTOCOL_TCP) 130 .matchIPProtocol(IPv4.PROTOCOL_TCP)
129 .matchIPSrc(IpPrefix.valueOf(bgpdAddress.toInt(), IPV4_BIT_LENGTH)) 131 .matchIPSrc(IpPrefix.valueOf(bgpdAddress.toInt(), IPV4_BIT_LENGTH))
...@@ -134,13 +136,13 @@ public class PeerConnectivityManager { ...@@ -134,13 +136,13 @@ public class PeerConnectivityManager {
134 TrafficTreatment treatment = DefaultTrafficTreatment.builder() 136 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
135 .build(); 137 .build();
136 138
137 - PointToPointIntent intentMatchDstTcpPort = new PointToPointIntent( 139 + PointToPointIntent intentMatchDstTcpPort =
138 - nextIntentId(), selector, treatment, 140 + new PointToPointIntent(appId, selector, treatment,
139 - bgpdConnectPoint, bgpdPeerConnectPoint); 141 + bgpdConnectPoint, bgpdPeerConnectPoint);
140 intentService.submit(intentMatchDstTcpPort); 142 intentService.submit(intentMatchDstTcpPort);
141 log.debug("Submitted BGP path intent matching dst TCP port 179 " 143 log.debug("Submitted BGP path intent matching dst TCP port 179 "
142 - + "from BGPd {} to peer {}: {}", 144 + + "from BGPd {} to peer {}: {}",
143 - bgpdAddress, bgpdPeerAddress, intentMatchDstTcpPort); 145 + bgpdAddress, bgpdPeerAddress, intentMatchDstTcpPort);
144 146
145 // install intent for BGP path from BGPd to BGP peer matching 147 // install intent for BGP path from BGPd to BGP peer matching
146 // source TCP port 179 148 // source TCP port 179
...@@ -152,13 +154,13 @@ public class PeerConnectivityManager { ...@@ -152,13 +154,13 @@ public class PeerConnectivityManager {
152 .matchTcpSrc(BGP_PORT) 154 .matchTcpSrc(BGP_PORT)
153 .build(); 155 .build();
154 156
155 - PointToPointIntent intentMatchSrcTcpPort = new PointToPointIntent( 157 + PointToPointIntent intentMatchSrcTcpPort =
156 - nextIntentId(), selector, treatment, 158 + new PointToPointIntent(appId, selector, treatment,
157 - bgpdConnectPoint, bgpdPeerConnectPoint); 159 + bgpdConnectPoint, bgpdPeerConnectPoint);
158 intentService.submit(intentMatchSrcTcpPort); 160 intentService.submit(intentMatchSrcTcpPort);
159 log.debug("Submitted BGP path intent matching src TCP port 179" 161 log.debug("Submitted BGP path intent matching src TCP port 179"
160 - + "from BGPd {} to peer {}: {}", 162 + + "from BGPd {} to peer {}: {}",
161 - bgpdAddress, bgpdPeerAddress, intentMatchSrcTcpPort); 163 + bgpdAddress, bgpdPeerAddress, intentMatchSrcTcpPort);
162 164
163 // install intent for reversed BGP path from BGP peer to BGPd 165 // install intent for reversed BGP path from BGP peer to BGPd
164 // matching destination TCP port 179 166 // matching destination TCP port 179
...@@ -170,13 +172,13 @@ public class PeerConnectivityManager { ...@@ -170,13 +172,13 @@ public class PeerConnectivityManager {
170 .matchTcpDst(BGP_PORT) 172 .matchTcpDst(BGP_PORT)
171 .build(); 173 .build();
172 174
173 - PointToPointIntent reversedIntentMatchDstTcpPort = new PointToPointIntent( 175 + PointToPointIntent reversedIntentMatchDstTcpPort =
174 - nextIntentId(), selector, treatment, 176 + new PointToPointIntent(appId, selector, treatment,
175 - bgpdPeerConnectPoint, bgpdConnectPoint); 177 + bgpdPeerConnectPoint, bgpdConnectPoint);
176 intentService.submit(reversedIntentMatchDstTcpPort); 178 intentService.submit(reversedIntentMatchDstTcpPort);
177 log.debug("Submitted BGP path intent matching dst TCP port 179" 179 log.debug("Submitted BGP path intent matching dst TCP port 179"
178 - + "from BGP peer {} to BGPd {} : {}", 180 + + "from BGP peer {} to BGPd {} : {}",
179 - bgpdPeerAddress, bgpdAddress, reversedIntentMatchDstTcpPort); 181 + bgpdPeerAddress, bgpdAddress, reversedIntentMatchDstTcpPort);
180 182
181 // install intent for reversed BGP path from BGP peer to BGPd 183 // install intent for reversed BGP path from BGP peer to BGPd
182 // matching source TCP port 179 184 // matching source TCP port 179
...@@ -188,13 +190,13 @@ public class PeerConnectivityManager { ...@@ -188,13 +190,13 @@ public class PeerConnectivityManager {
188 .matchTcpSrc(BGP_PORT) 190 .matchTcpSrc(BGP_PORT)
189 .build(); 191 .build();
190 192
191 - PointToPointIntent reversedIntentMatchSrcTcpPort = new PointToPointIntent( 193 + PointToPointIntent reversedIntentMatchSrcTcpPort =
192 - nextIntentId(), selector, treatment, 194 + new PointToPointIntent(appId, selector, treatment,
193 - bgpdPeerConnectPoint, bgpdConnectPoint); 195 + bgpdPeerConnectPoint, bgpdConnectPoint);
194 intentService.submit(reversedIntentMatchSrcTcpPort); 196 intentService.submit(reversedIntentMatchSrcTcpPort);
195 log.debug("Submitted BGP path intent matching src TCP port 179" 197 log.debug("Submitted BGP path intent matching src TCP port 179"
196 - + "from BGP peer {} to BGPd {} : {}", 198 + + "from BGP peer {} to BGPd {} : {}",
197 - bgpdPeerAddress, bgpdAddress, reversedIntentMatchSrcTcpPort); 199 + bgpdPeerAddress, bgpdAddress, reversedIntentMatchSrcTcpPort);
198 200
199 } 201 }
200 } 202 }
...@@ -212,7 +214,7 @@ public class PeerConnectivityManager { ...@@ -212,7 +214,7 @@ public class PeerConnectivityManager {
212 for (BgpSpeaker bgpSpeaker : configInfoService.getBgpSpeakers() 214 for (BgpSpeaker bgpSpeaker : configInfoService.getBgpSpeakers()
213 .values()) { 215 .values()) {
214 log.debug("Start to set up ICMP paths for BGP speaker: {}", 216 log.debug("Start to set up ICMP paths for BGP speaker: {}",
215 - bgpSpeaker); 217 + bgpSpeaker);
216 ConnectPoint bgpdConnectPoint = bgpSpeaker.connectPoint(); 218 ConnectPoint bgpdConnectPoint = bgpSpeaker.connectPoint();
217 List<InterfaceAddress> interfaceAddresses = bgpSpeaker 219 List<InterfaceAddress> interfaceAddresses = bgpSpeaker
218 .interfaceAddresses(); 220 .interfaceAddresses();
...@@ -224,8 +226,8 @@ public class PeerConnectivityManager { ...@@ -224,8 +226,8 @@ public class PeerConnectivityManager {
224 226
225 if (peerInterface == null) { 227 if (peerInterface == null) {
226 log.error("Can not find the corresponding Interface from " 228 log.error("Can not find the corresponding Interface from "
227 - + "configuration for BGP peer {}", 229 + + "configuration for BGP peer {}",
228 - bgpPeer.ipAddress()); 230 + bgpPeer.ipAddress());
229 continue; 231 continue;
230 } 232 }
231 IpAddress bgpdAddress = null; 233 IpAddress bgpdAddress = null;
...@@ -239,8 +241,8 @@ public class PeerConnectivityManager { ...@@ -239,8 +241,8 @@ public class PeerConnectivityManager {
239 } 241 }
240 if (bgpdAddress == null) { 242 if (bgpdAddress == null) {
241 log.debug("There is no IP address for bgpPeer: {} on " 243 log.debug("There is no IP address for bgpPeer: {} on "
242 - + "interface port: {}", bgpPeer, 244 + + "interface port: {}", bgpPeer,
243 - bgpPeer.connectPoint()); 245 + bgpPeer.connectPoint());
244 return; 246 return;
245 } 247 }
246 248
...@@ -258,12 +260,12 @@ public class PeerConnectivityManager { ...@@ -258,12 +260,12 @@ public class PeerConnectivityManager {
258 TrafficTreatment treatment = DefaultTrafficTreatment.builder() 260 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
259 .build(); 261 .build();
260 262
261 - PointToPointIntent intent = new PointToPointIntent( 263 + PointToPointIntent intent =
262 - nextIntentId(), selector, treatment, 264 + new PointToPointIntent(appId, selector, treatment,
263 - bgpdConnectPoint, bgpdPeerConnectPoint); 265 + bgpdConnectPoint, bgpdPeerConnectPoint);
264 intentService.submit(intent); 266 intentService.submit(intent);
265 log.debug("Submitted ICMP path intent from BGPd {} to peer {} :" 267 log.debug("Submitted ICMP path intent from BGPd {} to peer {} :"
266 - + " {}", bgpdAddress, bgpdPeerAddress, intent); 268 + + " {}", bgpdAddress, bgpdPeerAddress, intent);
267 269
268 // install intent for reversed ICMP path from BGP peer to BGPd 270 // install intent for reversed ICMP path from BGP peer to BGPd
269 selector = DefaultTrafficSelector.builder() 271 selector = DefaultTrafficSelector.builder()
...@@ -273,18 +275,15 @@ public class PeerConnectivityManager { ...@@ -273,18 +275,15 @@ public class PeerConnectivityManager {
273 .matchIPDst(IpPrefix.valueOf(bgpdAddress.toInt(), IPV4_BIT_LENGTH)) 275 .matchIPDst(IpPrefix.valueOf(bgpdAddress.toInt(), IPV4_BIT_LENGTH))
274 .build(); 276 .build();
275 277
276 - PointToPointIntent reversedIntent = new PointToPointIntent( 278 + PointToPointIntent reversedIntent =
277 - nextIntentId(), selector, treatment, 279 + new PointToPointIntent(appId, selector, treatment,
278 - bgpdPeerConnectPoint, bgpdConnectPoint); 280 + bgpdPeerConnectPoint, bgpdConnectPoint);
279 intentService.submit(reversedIntent); 281 intentService.submit(reversedIntent);
280 log.debug("Submitted ICMP path intent from BGP peer {} to BGPd" 282 log.debug("Submitted ICMP path intent from BGP peer {} to BGPd"
281 - + " {} : {}", 283 + + " {} : {}",
282 - bgpdPeerAddress, bgpdAddress, reversedIntent); 284 + bgpdPeerAddress, bgpdAddress, reversedIntent);
283 } 285 }
284 } 286 }
285 } 287 }
286 288
287 - private IntentId nextIntentId() {
288 - return new IntentId(intentId++);
289 - }
290 } 289 }
......
1 package org.onlab.onos.sdnip; 1 package org.onlab.onos.sdnip;
2 2
3 -import java.util.Collection; 3 +import com.google.common.base.Objects;
4 -import java.util.HashMap; 4 +import com.google.common.collect.HashMultimap;
5 -import java.util.HashSet; 5 +import com.google.common.collect.Multimaps;
6 -import java.util.Iterator; 6 +import com.google.common.collect.SetMultimap;
7 -import java.util.LinkedList; 7 +import com.google.common.util.concurrent.ThreadFactoryBuilder;
8 -import java.util.List; 8 +import com.googlecode.concurrenttrees.common.KeyValuePair;
9 -import java.util.Map; 9 +import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory;
10 -import java.util.Set; 10 +import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
11 -import java.util.concurrent.BlockingQueue; 11 +import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
12 -import java.util.concurrent.ConcurrentHashMap;
13 -import java.util.concurrent.ExecutorService;
14 -import java.util.concurrent.Executors;
15 -import java.util.concurrent.LinkedBlockingQueue;
16 -import java.util.concurrent.Semaphore;
17 -
18 import org.apache.commons.lang3.tuple.Pair; 12 import org.apache.commons.lang3.tuple.Pair;
13 +import org.onlab.onos.ApplicationId;
19 import org.onlab.onos.net.ConnectPoint; 14 import org.onlab.onos.net.ConnectPoint;
20 import org.onlab.onos.net.Host; 15 import org.onlab.onos.net.Host;
21 import org.onlab.onos.net.flow.DefaultTrafficSelector; 16 import org.onlab.onos.net.flow.DefaultTrafficSelector;
...@@ -29,7 +24,6 @@ import org.onlab.onos.net.host.HostEvent; ...@@ -29,7 +24,6 @@ import org.onlab.onos.net.host.HostEvent;
29 import org.onlab.onos.net.host.HostListener; 24 import org.onlab.onos.net.host.HostListener;
30 import org.onlab.onos.net.host.HostService; 25 import org.onlab.onos.net.host.HostService;
31 import org.onlab.onos.net.intent.Intent; 26 import org.onlab.onos.net.intent.Intent;
32 -import org.onlab.onos.net.intent.IntentId;
33 import org.onlab.onos.net.intent.IntentService; 27 import org.onlab.onos.net.intent.IntentService;
34 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; 28 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
35 import org.onlab.onos.sdnip.config.BgpPeer; 29 import org.onlab.onos.sdnip.config.BgpPeer;
...@@ -42,20 +36,25 @@ import org.onlab.packet.MacAddress; ...@@ -42,20 +36,25 @@ import org.onlab.packet.MacAddress;
42 import org.slf4j.Logger; 36 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory; 37 import org.slf4j.LoggerFactory;
44 38
45 -import com.google.common.base.Objects; 39 +import java.util.Collection;
46 -import com.google.common.collect.HashMultimap; 40 +import java.util.HashMap;
47 -import com.google.common.collect.Multimaps; 41 +import java.util.HashSet;
48 -import com.google.common.collect.SetMultimap; 42 +import java.util.Iterator;
49 -import com.google.common.util.concurrent.ThreadFactoryBuilder; 43 +import java.util.LinkedList;
50 -import com.googlecode.concurrenttrees.common.KeyValuePair; 44 +import java.util.List;
51 -import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; 45 +import java.util.Map;
52 -import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; 46 +import java.util.Set;
53 -import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; 47 +import java.util.concurrent.BlockingQueue;
48 +import java.util.concurrent.ConcurrentHashMap;
49 +import java.util.concurrent.ExecutorService;
50 +import java.util.concurrent.Executors;
51 +import java.util.concurrent.LinkedBlockingQueue;
52 +import java.util.concurrent.Semaphore;
54 53
55 /** 54 /**
56 * This class processes BGP route update, translates each update into a intent 55 * This class processes BGP route update, translates each update into a intent
57 * and submits the intent. 56 * and submits the intent.
58 - * 57 + * <p/>
59 * TODO: Make it thread-safe. 58 * TODO: Make it thread-safe.
60 */ 59 */
61 public class Router implements RouteListener { 60 public class Router implements RouteListener {
...@@ -82,8 +81,7 @@ public class Router implements RouteListener { ...@@ -82,8 +81,7 @@ public class Router implements RouteListener {
82 private ExecutorService bgpUpdatesExecutor; 81 private ExecutorService bgpUpdatesExecutor;
83 private ExecutorService bgpIntentsSynchronizerExecutor; 82 private ExecutorService bgpIntentsSynchronizerExecutor;
84 83
85 - // TODO temporary 84 + private final ApplicationId appId;
86 - private int intentId = Integer.MAX_VALUE / 2;
87 85
88 // 86 //
89 // State to deal with SDN-IP Leader election and pushing Intents 87 // State to deal with SDN-IP Leader election and pushing Intents
...@@ -99,14 +97,15 @@ public class Router implements RouteListener { ...@@ -99,14 +97,15 @@ public class Router implements RouteListener {
99 /** 97 /**
100 * Class constructor. 98 * Class constructor.
101 * 99 *
102 - * @param intentService the intent service 100 + * @param intentService the intent service
103 - * @param hostService the host service 101 + * @param hostService the host service
104 * @param configInfoService the configuration service 102 * @param configInfoService the configuration service
105 - * @param interfaceService the interface service 103 + * @param interfaceService the interface service
106 */ 104 */
107 - public Router(IntentService intentService, HostService hostService, 105 + public Router(ApplicationId appId, IntentService intentService,
108 - SdnIpConfigService configInfoService, InterfaceService interfaceService) { 106 + HostService hostService, SdnIpConfigService configInfoService,
109 - 107 + InterfaceService interfaceService) {
108 + this.appId = appId;
110 this.intentService = intentService; 109 this.intentService = intentService;
111 this.hostService = hostService; 110 this.hostService = hostService;
112 this.configInfoService = configInfoService; 111 this.configInfoService = configInfoService;
...@@ -123,7 +122,7 @@ public class Router implements RouteListener { ...@@ -123,7 +122,7 @@ public class Router implements RouteListener {
123 new ThreadFactoryBuilder().setNameFormat("bgp-updates-%d").build()); 122 new ThreadFactoryBuilder().setNameFormat("bgp-updates-%d").build());
124 bgpIntentsSynchronizerExecutor = Executors.newSingleThreadExecutor( 123 bgpIntentsSynchronizerExecutor = Executors.newSingleThreadExecutor(
125 new ThreadFactoryBuilder() 124 new ThreadFactoryBuilder()
126 - .setNameFormat("bgp-intents-synchronizer-%d").build()); 125 + .setNameFormat("bgp-intents-synchronizer-%d").build());
127 126
128 this.hostService.addListener(new InternalHostListener()); 127 this.hostService.addListener(new InternalHostListener());
129 } 128 }
...@@ -198,7 +197,7 @@ public class Router implements RouteListener { ...@@ -198,7 +197,7 @@ public class Router implements RouteListener {
198 intentsSynchronizerSemaphore.drainPermits(); 197 intentsSynchronizerSemaphore.drainPermits();
199 } catch (InterruptedException e) { 198 } catch (InterruptedException e) {
200 log.debug("Interrupted while waiting to become " + 199 log.debug("Interrupted while waiting to become " +
201 - "Intent Synchronization leader"); 200 + "Intent Synchronization leader");
202 interrupted = true; 201 interrupted = true;
203 break; 202 break;
204 } 203 }
...@@ -221,15 +220,15 @@ public class Router implements RouteListener { ...@@ -221,15 +220,15 @@ public class Router implements RouteListener {
221 try { 220 try {
222 RouteUpdate update = routeUpdates.take(); 221 RouteUpdate update = routeUpdates.take();
223 switch (update.type()) { 222 switch (update.type()) {
224 - case UPDATE: 223 + case UPDATE:
225 - processRouteAdd(update.routeEntry()); 224 + processRouteAdd(update.routeEntry());
226 - break; 225 + break;
227 - case DELETE: 226 + case DELETE:
228 - processRouteDelete(update.routeEntry()); 227 + processRouteDelete(update.routeEntry());
229 - break; 228 + break;
230 - default: 229 + default:
231 - log.error("Unknown update Type: {}", update.type()); 230 + log.error("Unknown update Type: {}", update.type());
232 - break; 231 + break;
233 } 232 }
234 } catch (InterruptedException e) { 233 } catch (InterruptedException e) {
235 log.debug("Interrupted while taking from updates queue", e); 234 log.debug("Interrupted while taking from updates queue", e);
...@@ -257,7 +256,7 @@ public class Router implements RouteListener { ...@@ -257,7 +256,7 @@ public class Router implements RouteListener {
257 log.debug("Syncing SDN-IP Route Intents..."); 256 log.debug("Syncing SDN-IP Route Intents...");
258 257
259 Map<IpPrefix, MultiPointToSinglePointIntent> fetchedIntents = 258 Map<IpPrefix, MultiPointToSinglePointIntent> fetchedIntents =
260 - new HashMap<>(); 259 + new HashMap<>();
261 260
262 // 261 //
263 // Fetch all intents, and classify the Multi-Point-to-Point Intents 262 // Fetch all intents, and classify the Multi-Point-to-Point Intents
...@@ -272,7 +271,7 @@ public class Router implements RouteListener { ...@@ -272,7 +271,7 @@ public class Router implements RouteListener {
272 continue; 271 continue;
273 } 272 }
274 MultiPointToSinglePointIntent mp2pIntent = 273 MultiPointToSinglePointIntent mp2pIntent =
275 - (MultiPointToSinglePointIntent) intent; 274 + (MultiPointToSinglePointIntent) intent;
276 /*Match match = mp2pIntent.getMatch(); 275 /*Match match = mp2pIntent.getMatch();
277 if (!(match instanceof PacketMatch)) { 276 if (!(match instanceof PacketMatch)) {
278 continue; 277 continue;
...@@ -309,18 +308,18 @@ public class Router implements RouteListener { ...@@ -309,18 +308,18 @@ public class Router implements RouteListener {
309 // Intent. 308 // Intent.
310 // 309 //
311 Collection<Pair<IpPrefix, MultiPointToSinglePointIntent>> 310 Collection<Pair<IpPrefix, MultiPointToSinglePointIntent>>
312 - storeInMemoryIntents = new LinkedList<>(); 311 + storeInMemoryIntents = new LinkedList<>();
313 Collection<Pair<IpPrefix, MultiPointToSinglePointIntent>> 312 Collection<Pair<IpPrefix, MultiPointToSinglePointIntent>>
314 - addIntents = new LinkedList<>(); 313 + addIntents = new LinkedList<>();
315 Collection<Pair<IpPrefix, MultiPointToSinglePointIntent>> 314 Collection<Pair<IpPrefix, MultiPointToSinglePointIntent>>
316 - deleteIntents = new LinkedList<>(); 315 + deleteIntents = new LinkedList<>();
317 for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : 316 for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry :
318 - pushedRouteIntents.entrySet()) { 317 + pushedRouteIntents.entrySet()) {
319 IpPrefix prefix = entry.getKey(); 318 IpPrefix prefix = entry.getKey();
320 MultiPointToSinglePointIntent inMemoryIntent = 319 MultiPointToSinglePointIntent inMemoryIntent =
321 - entry.getValue(); 320 + entry.getValue();
322 MultiPointToSinglePointIntent fetchedIntent = 321 MultiPointToSinglePointIntent fetchedIntent =
323 - fetchedIntents.get(prefix); 322 + fetchedIntents.get(prefix);
324 323
325 if (fetchedIntent == null) { 324 if (fetchedIntent == null) {
326 // 325 //
...@@ -354,7 +353,7 @@ public class Router implements RouteListener { ...@@ -354,7 +353,7 @@ public class Router implements RouteListener {
354 // Any remaining FETCHED Intents have to be deleted/withdrawn 353 // Any remaining FETCHED Intents have to be deleted/withdrawn
355 // 354 //
356 for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : 355 for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry :
357 - fetchedIntents.entrySet()) { 356 + fetchedIntents.entrySet()) {
358 IpPrefix prefix = entry.getKey(); 357 IpPrefix prefix = entry.getKey();
359 MultiPointToSinglePointIntent fetchedIntent = entry.getValue(); 358 MultiPointToSinglePointIntent fetchedIntent = entry.getValue();
360 deleteIntents.add(Pair.of(prefix, fetchedIntent)); 359 deleteIntents.add(Pair.of(prefix, fetchedIntent));
...@@ -368,17 +367,17 @@ public class Router implements RouteListener { ...@@ -368,17 +367,17 @@ public class Router implements RouteListener {
368 // 3. Add intents: check if the leader before each operation 367 // 3. Add intents: check if the leader before each operation
369 // 368 //
370 for (Pair<IpPrefix, MultiPointToSinglePointIntent> pair : 369 for (Pair<IpPrefix, MultiPointToSinglePointIntent> pair :
371 - storeInMemoryIntents) { 370 + storeInMemoryIntents) {
372 IpPrefix prefix = pair.getLeft(); 371 IpPrefix prefix = pair.getLeft();
373 MultiPointToSinglePointIntent intent = pair.getRight(); 372 MultiPointToSinglePointIntent intent = pair.getRight();
374 log.debug("Intent synchronization: updating in-memory " + 373 log.debug("Intent synchronization: updating in-memory " +
375 - "Intent for prefix: {}", prefix); 374 + "Intent for prefix: {}", prefix);
376 pushedRouteIntents.put(prefix, intent); 375 pushedRouteIntents.put(prefix, intent);
377 } 376 }
378 // 377 //
379 isActivatedLeader = true; // Allow push of Intents 378 isActivatedLeader = true; // Allow push of Intents
380 for (Pair<IpPrefix, MultiPointToSinglePointIntent> pair : 379 for (Pair<IpPrefix, MultiPointToSinglePointIntent> pair :
381 - deleteIntents) { 380 + deleteIntents) {
382 IpPrefix prefix = pair.getLeft(); 381 IpPrefix prefix = pair.getLeft();
383 MultiPointToSinglePointIntent intent = pair.getRight(); 382 MultiPointToSinglePointIntent intent = pair.getRight();
384 if (!isElectedLeader) { 383 if (!isElectedLeader) {
...@@ -386,12 +385,12 @@ public class Router implements RouteListener { ...@@ -386,12 +385,12 @@ public class Router implements RouteListener {
386 return; 385 return;
387 } 386 }
388 log.debug("Intent synchronization: deleting Intent for " + 387 log.debug("Intent synchronization: deleting Intent for " +
389 - "prefix: {}", prefix); 388 + "prefix: {}", prefix);
390 intentService.withdraw(intent); 389 intentService.withdraw(intent);
391 } 390 }
392 // 391 //
393 for (Pair<IpPrefix, MultiPointToSinglePointIntent> pair : 392 for (Pair<IpPrefix, MultiPointToSinglePointIntent> pair :
394 - addIntents) { 393 + addIntents) {
395 IpPrefix prefix = pair.getLeft(); 394 IpPrefix prefix = pair.getLeft();
396 MultiPointToSinglePointIntent intent = pair.getRight(); 395 MultiPointToSinglePointIntent intent = pair.getRight();
397 if (!isElectedLeader) { 396 if (!isElectedLeader) {
...@@ -399,7 +398,7 @@ public class Router implements RouteListener { ...@@ -399,7 +398,7 @@ public class Router implements RouteListener {
399 return; 398 return;
400 } 399 }
401 log.debug("Intent synchronization: adding Intent for " + 400 log.debug("Intent synchronization: adding Intent for " +
402 - "prefix: {}", prefix); 401 + "prefix: {}", prefix);
403 intentService.submit(intent); 402 intentService.submit(intent);
404 } 403 }
405 if (!isElectedLeader) { 404 if (!isElectedLeader) {
...@@ -419,8 +418,8 @@ public class Router implements RouteListener { ...@@ -419,8 +418,8 @@ public class Router implements RouteListener {
419 * false 418 * false
420 */ 419 */
421 private boolean compareMultiPointToSinglePointIntents( 420 private boolean compareMultiPointToSinglePointIntents(
422 - MultiPointToSinglePointIntent intent1, 421 + MultiPointToSinglePointIntent intent1,
423 - MultiPointToSinglePointIntent intent2) { 422 + MultiPointToSinglePointIntent intent2) {
424 /*Match match1 = intent1.getMatch(); 423 /*Match match1 = intent1.getMatch();
425 Match match2 = intent2.getMatch(); 424 Match match2 = intent2.getMatch();
426 Action action1 = intent1.getAction(); 425 Action action1 = intent1.getAction();
...@@ -457,8 +456,8 @@ public class Router implements RouteListener { ...@@ -457,8 +456,8 @@ public class Router implements RouteListener {
457 IpPrefix prefix = routeEntry.prefix(); 456 IpPrefix prefix = routeEntry.prefix();
458 IpAddress nextHop = null; 457 IpAddress nextHop = null;
459 RouteEntry foundRouteEntry = 458 RouteEntry foundRouteEntry =
460 - bgpRoutes.put(RouteEntry.createBinaryString(prefix), 459 + bgpRoutes.put(RouteEntry.createBinaryString(prefix),
461 - routeEntry); 460 + routeEntry);
462 if (foundRouteEntry != null) { 461 if (foundRouteEntry != null) {
463 nextHop = foundRouteEntry.nextHop(); 462 nextHop = foundRouteEntry.nextHop();
464 } 463 }
...@@ -500,7 +499,7 @@ public class Router implements RouteListener { ...@@ -500,7 +499,7 @@ public class Router implements RouteListener {
500 499
501 // See if we know the MAC address of the next hop 500 // See if we know the MAC address of the next hop
502 //MacAddress nextHopMacAddress = 501 //MacAddress nextHopMacAddress =
503 - //proxyArp.getMacAddress(routeEntry.getNextHop()); 502 + //proxyArp.getMacAddress(routeEntry.getNextHop());
504 MacAddress nextHopMacAddress = null; 503 MacAddress nextHopMacAddress = null;
505 Set<Host> hosts = hostService.getHostsByIp( 504 Set<Host> hosts = hostService.getHostsByIp(
506 routeEntry.nextHop().toPrefix()); 505 routeEntry.nextHop().toPrefix());
...@@ -526,8 +525,8 @@ public class Router implements RouteListener { ...@@ -526,8 +525,8 @@ public class Router implements RouteListener {
526 * Adds a route intent given a prefix and a next hop IP address. This 525 * Adds a route intent given a prefix and a next hop IP address. This
527 * method will find the egress interface for the intent. 526 * method will find the egress interface for the intent.
528 * 527 *
529 - * @param prefix IP prefix of the route to add 528 + * @param prefix IP prefix of the route to add
530 - * @param nextHopIpAddress IP address of the next hop 529 + * @param nextHopIpAddress IP address of the next hop
531 * @param nextHopMacAddress MAC address of the next hop 530 * @param nextHopMacAddress MAC address of the next hop
532 */ 531 */
533 private void addRouteIntentToNextHop(IpPrefix prefix, 532 private void addRouteIntentToNextHop(IpPrefix prefix,
...@@ -540,14 +539,14 @@ public class Router implements RouteListener { ...@@ -540,14 +539,14 @@ public class Router implements RouteListener {
540 // Route to a peer 539 // Route to a peer
541 log.debug("Route to peer {}", nextHopIpAddress); 540 log.debug("Route to peer {}", nextHopIpAddress);
542 BgpPeer peer = 541 BgpPeer peer =
543 - configInfoService.getBgpPeers().get(nextHopIpAddress); 542 + configInfoService.getBgpPeers().get(nextHopIpAddress);
544 egressInterface = 543 egressInterface =
545 - interfaceService.getInterface(peer.connectPoint()); 544 + interfaceService.getInterface(peer.connectPoint());
546 } else { 545 } else {
547 // Route to non-peer 546 // Route to non-peer
548 log.debug("Route to non-peer {}", nextHopIpAddress); 547 log.debug("Route to non-peer {}", nextHopIpAddress);
549 egressInterface = 548 egressInterface =
550 - interfaceService.getMatchingInterface(nextHopIpAddress); 549 + interfaceService.getMatchingInterface(nextHopIpAddress);
551 if (egressInterface == null) { 550 if (egressInterface == null) {
552 log.warn("No outgoing interface found for {}", 551 log.warn("No outgoing interface found for {}",
553 nextHopIpAddress); 552 nextHopIpAddress);
...@@ -564,17 +563,17 @@ public class Router implements RouteListener { ...@@ -564,17 +563,17 @@ public class Router implements RouteListener {
564 * Intent will match dst IP prefix and rewrite dst MAC address at all other 563 * Intent will match dst IP prefix and rewrite dst MAC address at all other
565 * border switches, then forward packets according to dst MAC address. 564 * border switches, then forward packets according to dst MAC address.
566 * 565 *
567 - * @param prefix IP prefix from route 566 + * @param prefix IP prefix from route
568 - * @param egressInterface egress Interface connected to next hop router 567 + * @param egressInterface egress Interface connected to next hop router
569 * @param nextHopMacAddress MAC address of next hop router 568 * @param nextHopMacAddress MAC address of next hop router
570 */ 569 */
571 private void doAddRouteIntent(IpPrefix prefix, Interface egressInterface, 570 private void doAddRouteIntent(IpPrefix prefix, Interface egressInterface,
572 - MacAddress nextHopMacAddress) { 571 + MacAddress nextHopMacAddress) {
573 log.debug("Adding intent for prefix {}, next hop mac {}", 572 log.debug("Adding intent for prefix {}, next hop mac {}",
574 prefix, nextHopMacAddress); 573 prefix, nextHopMacAddress);
575 574
576 MultiPointToSinglePointIntent pushedIntent = 575 MultiPointToSinglePointIntent pushedIntent =
577 - pushedRouteIntents.get(prefix); 576 + pushedRouteIntents.get(prefix);
578 577
579 // Just for testing. 578 // Just for testing.
580 if (pushedIntent != null) { 579 if (pushedIntent != null) {
...@@ -603,14 +602,14 @@ public class Router implements RouteListener { ...@@ -603,14 +602,14 @@ public class Router implements RouteListener {
603 602
604 // Rewrite the destination MAC address 603 // Rewrite the destination MAC address
605 //ModifyDstMacAction modifyDstMacAction = 604 //ModifyDstMacAction modifyDstMacAction =
606 - //new ModifyDstMacAction(nextHopMacAddress); 605 + //new ModifyDstMacAction(nextHopMacAddress);
607 TrafficTreatment treatment = DefaultTrafficTreatment.builder() 606 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
608 .setEthDst(nextHopMacAddress) 607 .setEthDst(nextHopMacAddress)
609 .build(); 608 .build();
610 609
611 MultiPointToSinglePointIntent intent = 610 MultiPointToSinglePointIntent intent =
612 - new MultiPointToSinglePointIntent(nextIntentId(), 611 + new MultiPointToSinglePointIntent(appId, selector, treatment,
613 - selector, treatment, ingressPorts, egressPort); 612 + ingressPorts, egressPort);
614 613
615 if (isElectedLeader && isActivatedLeader) { 614 if (isElectedLeader && isActivatedLeader) {
616 log.debug("Intent installation: adding Intent for prefix: {}", 615 log.debug("Intent installation: adding Intent for prefix: {}",
...@@ -665,11 +664,11 @@ public class Router implements RouteListener { ...@@ -665,11 +664,11 @@ public class Router implements RouteListener {
665 IpPrefix prefix = routeEntry.prefix(); 664 IpPrefix prefix = routeEntry.prefix();
666 665
667 MultiPointToSinglePointIntent intent = 666 MultiPointToSinglePointIntent intent =
668 - pushedRouteIntents.remove(prefix); 667 + pushedRouteIntents.remove(prefix);
669 668
670 if (intent == null) { 669 if (intent == null) {
671 log.debug("There is no intent in pushedRouteIntents to delete " + 670 log.debug("There is no intent in pushedRouteIntents to delete " +
672 - "for prefix: {}", prefix); 671 + "for prefix: {}", prefix);
673 } else { 672 } else {
674 if (isElectedLeader && isActivatedLeader) { 673 if (isElectedLeader && isActivatedLeader) {
675 log.debug("Intent installation: deleting Intent for prefix: {}", 674 log.debug("Intent installation: deleting Intent for prefix: {}",
...@@ -683,8 +682,8 @@ public class Router implements RouteListener { ...@@ -683,8 +682,8 @@ public class Router implements RouteListener {
683 * This method handles the prefixes which are waiting for ARP replies for 682 * This method handles the prefixes which are waiting for ARP replies for
684 * MAC addresses of next hops. 683 * MAC addresses of next hops.
685 * 684 *
686 - * @param ipAddress next hop router IP address, for which we sent ARP 685 + * @param ipAddress next hop router IP address, for which we sent ARP
687 - * request out 686 + * request out
688 * @param macAddress MAC address which is relative to the ipAddress 687 * @param macAddress MAC address which is relative to the ipAddress
689 */ 688 */
690 //@Override 689 //@Override
...@@ -692,22 +691,22 @@ public class Router implements RouteListener { ...@@ -692,22 +691,22 @@ public class Router implements RouteListener {
692 public void arpResponse(IpAddress ipAddress, MacAddress macAddress) { 691 public void arpResponse(IpAddress ipAddress, MacAddress macAddress) {
693 log.debug("Received ARP response: {} => {}", ipAddress, macAddress); 692 log.debug("Received ARP response: {} => {}", ipAddress, macAddress);
694 693
695 - // We synchronize on this to prevent changes to the radix tree 694 + // We synchronize on this to prevent changes to the radix tree
696 - // while we're pushing intents. If the tree changes, the 695 + // while we're pushing intents. If the tree changes, the
697 - // tree and intents could get out of sync. 696 + // tree and intents could get out of sync.
698 synchronized (this) { 697 synchronized (this) {
699 698
700 Set<RouteEntry> routesToPush = 699 Set<RouteEntry> routesToPush =
701 - routesWaitingOnArp.removeAll(ipAddress); 700 + routesWaitingOnArp.removeAll(ipAddress);
702 701
703 for (RouteEntry routeEntry : routesToPush) { 702 for (RouteEntry routeEntry : routesToPush) {
704 // These will always be adds 703 // These will always be adds
705 IpPrefix prefix = routeEntry.prefix(); 704 IpPrefix prefix = routeEntry.prefix();
706 String binaryString = RouteEntry.createBinaryString(prefix); 705 String binaryString = RouteEntry.createBinaryString(prefix);
707 RouteEntry foundRouteEntry = 706 RouteEntry foundRouteEntry =
708 - bgpRoutes.getValueForExactKey(binaryString); 707 + bgpRoutes.getValueForExactKey(binaryString);
709 if (foundRouteEntry != null && 708 if (foundRouteEntry != null &&
710 - foundRouteEntry.nextHop().equals(routeEntry.nextHop())) { 709 + foundRouteEntry.nextHop().equals(routeEntry.nextHop())) {
711 log.debug("Pushing prefix {} next hop {}", 710 log.debug("Pushing prefix {} next hop {}",
712 routeEntry.prefix(), routeEntry.nextHop()); 711 routeEntry.prefix(), routeEntry.nextHop());
713 // We only push prefix flows if the prefix is still in the 712 // We only push prefix flows if the prefix is still in the
...@@ -718,8 +717,8 @@ public class Router implements RouteListener { ...@@ -718,8 +717,8 @@ public class Router implements RouteListener {
718 addRouteIntentToNextHop(prefix, ipAddress, macAddress); 717 addRouteIntentToNextHop(prefix, ipAddress, macAddress);
719 } else { 718 } else {
720 log.debug("Received ARP response, but {}/{} is no longer in" 719 log.debug("Received ARP response, but {}/{} is no longer in"
721 - + " the radix tree", routeEntry.prefix(), 720 + + " the radix tree", routeEntry.prefix(),
722 - routeEntry.nextHop()); 721 + routeEntry.nextHop());
723 } 722 }
724 } 723 }
725 } 724 }
...@@ -745,15 +744,6 @@ public class Router implements RouteListener { ...@@ -745,15 +744,6 @@ public class Router implements RouteListener {
745 } 744 }
746 745
747 /** 746 /**
748 - * Generates a new unique intent ID.
749 - *
750 - * @return the new intent ID.
751 - */
752 - private IntentId nextIntentId() {
753 - return new IntentId(intentId++);
754 - }
755 -
756 - /**
757 * Listener for host events. 747 * Listener for host events.
758 */ 748 */
759 class InternalHostListener implements HostListener { 749 class InternalHostListener implements HostListener {
......
...@@ -10,6 +10,8 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -10,6 +10,8 @@ import org.apache.felix.scr.annotations.Deactivate;
10 import org.apache.felix.scr.annotations.Reference; 10 import org.apache.felix.scr.annotations.Reference;
11 import org.apache.felix.scr.annotations.ReferenceCardinality; 11 import org.apache.felix.scr.annotations.ReferenceCardinality;
12 import org.apache.felix.scr.annotations.Service; 12 import org.apache.felix.scr.annotations.Service;
13 +import org.onlab.onos.ApplicationId;
14 +import org.onlab.onos.CoreService;
13 import org.onlab.onos.net.host.HostService; 15 import org.onlab.onos.net.host.HostService;
14 import org.onlab.onos.net.intent.IntentService; 16 import org.onlab.onos.net.intent.IntentService;
15 import org.onlab.onos.sdnip.bgp.BgpRouteEntry; 17 import org.onlab.onos.sdnip.bgp.BgpRouteEntry;
...@@ -24,9 +26,14 @@ import org.slf4j.Logger; ...@@ -24,9 +26,14 @@ import org.slf4j.Logger;
24 @Service 26 @Service
25 public class SdnIp implements SdnIpService { 27 public class SdnIp implements SdnIpService {
26 28
29 + private static final String SDN_ID_APP = "org.onlab.onos.sdnip";
30 +
27 private final Logger log = getLogger(getClass()); 31 private final Logger log = getLogger(getClass());
28 32
29 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 33 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
34 + protected CoreService coreService;
35 +
36 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
30 protected IntentService intentService; 37 protected IntentService intentService;
31 38
32 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 39 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -46,10 +53,11 @@ public class SdnIp implements SdnIpService { ...@@ -46,10 +53,11 @@ public class SdnIp implements SdnIpService {
46 53
47 InterfaceService interfaceService = new HostToInterfaceAdaptor(hostService); 54 InterfaceService interfaceService = new HostToInterfaceAdaptor(hostService);
48 55
49 - peerConnectivity = new PeerConnectivityManager(config, interfaceService, intentService); 56 + ApplicationId appId = coreService.registerApplication(SDN_ID_APP);
57 + peerConnectivity = new PeerConnectivityManager(appId, config, interfaceService, intentService);
50 peerConnectivity.start(); 58 peerConnectivity.start();
51 59
52 - router = new Router(intentService, hostService, config, interfaceService); 60 + router = new Router(appId, intentService, hostService, config, interfaceService);
53 router.start(); 61 router.start();
54 62
55 bgpSessionManager = new BgpSessionManager(router); 63 bgpSessionManager = new BgpSessionManager(router);
......
1 package org.onlab.onos.sdnip; 1 package org.onlab.onos.sdnip;
2 2
3 -import static org.easymock.EasyMock.createMock; 3 +import com.google.common.collect.Sets;
4 -import static org.easymock.EasyMock.expect;
5 -import static org.easymock.EasyMock.replay;
6 -import static org.easymock.EasyMock.reportMatcher;
7 -import static org.easymock.EasyMock.reset;
8 -import static org.easymock.EasyMock.verify;
9 -
10 -import java.util.ArrayList;
11 -import java.util.Collections;
12 -import java.util.HashMap;
13 -import java.util.LinkedList;
14 -import java.util.List;
15 -import java.util.Map;
16 -
17 import org.easymock.IArgumentMatcher; 4 import org.easymock.IArgumentMatcher;
18 import org.junit.Before; 5 import org.junit.Before;
19 import org.junit.Ignore; 6 import org.junit.Ignore;
20 import org.junit.Test; 7 import org.junit.Test;
8 +import org.onlab.onos.ApplicationId;
21 import org.onlab.onos.net.ConnectPoint; 9 import org.onlab.onos.net.ConnectPoint;
22 import org.onlab.onos.net.DeviceId; 10 import org.onlab.onos.net.DeviceId;
23 import org.onlab.onos.net.PortNumber; 11 import org.onlab.onos.net.PortNumber;
...@@ -25,7 +13,6 @@ import org.onlab.onos.net.flow.DefaultTrafficSelector; ...@@ -25,7 +13,6 @@ import org.onlab.onos.net.flow.DefaultTrafficSelector;
25 import org.onlab.onos.net.flow.DefaultTrafficTreatment; 13 import org.onlab.onos.net.flow.DefaultTrafficTreatment;
26 import org.onlab.onos.net.flow.TrafficSelector; 14 import org.onlab.onos.net.flow.TrafficSelector;
27 import org.onlab.onos.net.flow.TrafficTreatment; 15 import org.onlab.onos.net.flow.TrafficTreatment;
28 -import org.onlab.onos.net.intent.IntentId;
29 import org.onlab.onos.net.intent.IntentService; 16 import org.onlab.onos.net.intent.IntentService;
30 import org.onlab.onos.net.intent.PointToPointIntent; 17 import org.onlab.onos.net.intent.PointToPointIntent;
31 import org.onlab.onos.sdnip.bgp.BgpConstants; 18 import org.onlab.onos.sdnip.bgp.BgpConstants;
...@@ -40,13 +27,32 @@ import org.onlab.packet.IpAddress; ...@@ -40,13 +27,32 @@ import org.onlab.packet.IpAddress;
40 import org.onlab.packet.IpPrefix; 27 import org.onlab.packet.IpPrefix;
41 import org.onlab.packet.MacAddress; 28 import org.onlab.packet.MacAddress;
42 29
43 -import com.google.common.collect.Sets; 30 +import java.util.ArrayList;
31 +import java.util.Collections;
32 +import java.util.HashMap;
33 +import java.util.LinkedList;
34 +import java.util.List;
35 +import java.util.Map;
36 +
37 +import static org.easymock.EasyMock.*;
44 38
45 /** 39 /**
46 * Unit tests for PeerConnectivityManager interface. 40 * Unit tests for PeerConnectivityManager interface.
47 */ 41 */
48 public class PeerConnectivityManagerTest { 42 public class PeerConnectivityManagerTest {
49 43
44 + private static final ApplicationId APPID = new ApplicationId() {
45 + @Override
46 + public short id() {
47 + return 0;
48 + }
49 +
50 + @Override
51 + public String name() {
52 + return "foo";
53 + }
54 + };
55 +
50 private PeerConnectivityManager peerConnectivityManager; 56 private PeerConnectivityManager peerConnectivityManager;
51 private IntentService intentService; 57 private IntentService intentService;
52 private SdnIpConfigService configInfoService; 58 private SdnIpConfigService configInfoService;
...@@ -81,9 +87,6 @@ public class PeerConnectivityManagerTest { ...@@ -81,9 +87,6 @@ public class PeerConnectivityManagerTest {
81 private final ConnectPoint s2Eth1 = 87 private final ConnectPoint s2Eth1 =
82 new ConnectPoint(deviceId2, PortNumber.portNumber(1)); 88 new ConnectPoint(deviceId2, PortNumber.portNumber(1));
83 89
84 - // We don't compare the intent ID so all expected intents can use the same ID
85 - private final IntentId testIntentId = new IntentId(0);
86 -
87 private final TrafficTreatment noTreatment = 90 private final TrafficTreatment noTreatment =
88 DefaultTrafficTreatment.builder().build(); 91 DefaultTrafficTreatment.builder().build();
89 92
...@@ -257,7 +260,7 @@ public class PeerConnectivityManagerTest { ...@@ -257,7 +260,7 @@ public class PeerConnectivityManagerTest {
257 } 260 }
258 261
259 PointToPointIntent intent = new PointToPointIntent( 262 PointToPointIntent intent = new PointToPointIntent(
260 - testIntentId, builder.build(), noTreatment, 263 + APPID, builder.build(), noTreatment,
261 srcConnectPoint, dstConnectPoint); 264 srcConnectPoint, dstConnectPoint);
262 265
263 intentList.add(intent); 266 intentList.add(intent);
...@@ -429,7 +432,7 @@ public class PeerConnectivityManagerTest { ...@@ -429,7 +432,7 @@ public class PeerConnectivityManagerTest {
429 .build(); 432 .build();
430 433
431 PointToPointIntent intent = new PointToPointIntent( 434 PointToPointIntent intent = new PointToPointIntent(
432 - testIntentId, selector, noTreatment, 435 + APPID, selector, noTreatment,
433 srcConnectPoint, dstConnectPoint); 436 srcConnectPoint, dstConnectPoint);
434 437
435 intentList.add(intent); 438 intentList.add(intent);
...@@ -511,7 +514,7 @@ public class PeerConnectivityManagerTest { ...@@ -511,7 +514,7 @@ public class PeerConnectivityManagerTest {
511 intentService = createMock(IntentService.class); 514 intentService = createMock(IntentService.class);
512 replay(intentService); 515 replay(intentService);
513 516
514 - peerConnectivityManager = new PeerConnectivityManager(configInfoService, 517 + peerConnectivityManager = new PeerConnectivityManager(APPID, configInfoService,
515 interfaceService, intentService); 518 interfaceService, intentService);
516 } 519 }
517 520
...@@ -557,7 +560,7 @@ public class PeerConnectivityManagerTest { ...@@ -557,7 +560,7 @@ public class PeerConnectivityManagerTest {
557 providedIntentString = providedIntent.toString(); 560 providedIntentString = providedIntent.toString();
558 561
559 PointToPointIntent matchIntent = 562 PointToPointIntent matchIntent =
560 - new PointToPointIntent(providedIntent.id(), 563 + new PointToPointIntent(providedIntent.appId(),
561 intent.selector(), intent.treatment(), 564 intent.selector(), intent.treatment(),
562 intent.ingressPoint(), intent.egressPoint()); 565 intent.ingressPoint(), intent.egressPoint());
563 566
......
...@@ -2,6 +2,8 @@ package org.onlab.onos.cli; ...@@ -2,6 +2,8 @@ package org.onlab.onos.cli;
2 2
3 import org.apache.karaf.shell.commands.Option; 3 import org.apache.karaf.shell.commands.Option;
4 import org.apache.karaf.shell.console.OsgiCommandSupport; 4 import org.apache.karaf.shell.console.OsgiCommandSupport;
5 +import org.onlab.onos.ApplicationId;
6 +import org.onlab.onos.CoreService;
5 import org.onlab.osgi.DefaultServiceDirectory; 7 import org.onlab.osgi.DefaultServiceDirectory;
6 import org.onlab.osgi.ServiceNotFoundException; 8 import org.onlab.osgi.ServiceNotFoundException;
7 9
...@@ -27,6 +29,15 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { ...@@ -27,6 +29,15 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport {
27 } 29 }
28 30
29 /** 31 /**
32 + * Returns application ID for the CLI.
33 + *
34 + * @return command-line application identifier
35 + */
36 + protected ApplicationId appId() {
37 + return get(CoreService.class).registerApplication("org.onlab.onos.cli");
38 + }
39 +
40 + /**
30 * Prints the arguments using the specified format. 41 * Prints the arguments using the specified format.
31 * 42 *
32 * @param format format string; see {@link String#format} 43 * @param format format string; see {@link String#format}
......
...@@ -9,7 +9,6 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment; ...@@ -9,7 +9,6 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment;
9 import org.onlab.onos.net.flow.TrafficSelector; 9 import org.onlab.onos.net.flow.TrafficSelector;
10 import org.onlab.onos.net.flow.TrafficTreatment; 10 import org.onlab.onos.net.flow.TrafficTreatment;
11 import org.onlab.onos.net.intent.HostToHostIntent; 11 import org.onlab.onos.net.intent.HostToHostIntent;
12 -import org.onlab.onos.net.intent.IntentId;
13 import org.onlab.onos.net.intent.IntentService; 12 import org.onlab.onos.net.intent.IntentService;
14 13
15 /** 14 /**
...@@ -27,8 +26,6 @@ public class AddHostToHostIntentCommand extends AbstractShellCommand { ...@@ -27,8 +26,6 @@ public class AddHostToHostIntentCommand extends AbstractShellCommand {
27 required = true, multiValued = false) 26 required = true, multiValued = false)
28 String two = null; 27 String two = null;
29 28
30 - private static long id = 0x7870001;
31 -
32 @Override 29 @Override
33 protected void execute() { 30 protected void execute() {
34 IntentService service = get(IntentService.class); 31 IntentService service = get(IntentService.class);
...@@ -39,9 +36,8 @@ public class AddHostToHostIntentCommand extends AbstractShellCommand { ...@@ -39,9 +36,8 @@ public class AddHostToHostIntentCommand extends AbstractShellCommand {
39 TrafficSelector selector = DefaultTrafficSelector.builder().build(); 36 TrafficSelector selector = DefaultTrafficSelector.builder().build();
40 TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); 37 TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
41 38
42 - HostToHostIntent intent = 39 + HostToHostIntent intent = new HostToHostIntent(appId(), oneId, twoId,
43 - new HostToHostIntent(new IntentId(id++), oneId, twoId, 40 + selector, treatment);
44 - selector, treatment);
45 service.submit(intent); 41 service.submit(intent);
46 } 42 }
47 43
......
1 package org.onlab.onos.cli.net; 1 package org.onlab.onos.cli.net;
2 2
3 -import java.util.HashSet;
4 -import java.util.Set;
5 -
6 import org.apache.karaf.shell.commands.Argument; 3 import org.apache.karaf.shell.commands.Argument;
7 import org.apache.karaf.shell.commands.Command; 4 import org.apache.karaf.shell.commands.Command;
8 import org.onlab.onos.cli.AbstractShellCommand; 5 import org.onlab.onos.cli.AbstractShellCommand;
...@@ -14,11 +11,16 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment; ...@@ -14,11 +11,16 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment;
14 import org.onlab.onos.net.flow.TrafficSelector; 11 import org.onlab.onos.net.flow.TrafficSelector;
15 import org.onlab.onos.net.flow.TrafficTreatment; 12 import org.onlab.onos.net.flow.TrafficTreatment;
16 import org.onlab.onos.net.intent.Intent; 13 import org.onlab.onos.net.intent.Intent;
17 -import org.onlab.onos.net.intent.IntentId;
18 import org.onlab.onos.net.intent.IntentService; 14 import org.onlab.onos.net.intent.IntentService;
19 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; 15 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
20 import org.onlab.packet.Ethernet; 16 import org.onlab.packet.Ethernet;
21 17
18 +import java.util.HashSet;
19 +import java.util.Set;
20 +
21 +import static org.onlab.onos.net.DeviceId.deviceId;
22 +import static org.onlab.onos.net.PortNumber.portNumber;
23 +
22 /** 24 /**
23 * Installs point-to-point connectivity intents. 25 * Installs point-to-point connectivity intents.
24 */ 26 */
...@@ -31,8 +33,6 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman ...@@ -31,8 +33,6 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman
31 required = true, multiValued = true) 33 required = true, multiValued = true)
32 String[] deviceStrings = null; 34 String[] deviceStrings = null;
33 35
34 - private static long id = 0x7070001;
35 -
36 @Override 36 @Override
37 protected void execute() { 37 protected void execute() {
38 IntentService service = get(IntentService.class); 38 IntentService service = get(IntentService.class);
...@@ -42,33 +42,26 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman ...@@ -42,33 +42,26 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman
42 } 42 }
43 43
44 String egressDeviceString = deviceStrings[deviceStrings.length - 1]; 44 String egressDeviceString = deviceStrings[deviceStrings.length - 1];
45 - DeviceId egressDeviceId = DeviceId.deviceId(getDeviceId(egressDeviceString)); 45 + DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
46 - PortNumber egressPortNumber = 46 + PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
47 - PortNumber.portNumber(getPortNumber(egressDeviceString));
48 ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); 47 ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
49 Set<ConnectPoint> ingressPoints = new HashSet<>(); 48 Set<ConnectPoint> ingressPoints = new HashSet<>();
50 49
51 for (int index = 0; index < deviceStrings.length - 1; index++) { 50 for (int index = 0; index < deviceStrings.length - 1; index++) {
52 String ingressDeviceString = deviceStrings[index]; 51 String ingressDeviceString = deviceStrings[index];
53 - DeviceId ingressDeviceId = DeviceId.deviceId(getDeviceId(ingressDeviceString)); 52 + DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
54 - PortNumber ingressPortNumber = 53 + PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
55 - PortNumber.portNumber(getPortNumber(ingressDeviceString));
56 ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber); 54 ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
57 ingressPoints.add(ingress); 55 ingressPoints.add(ingress);
58 } 56 }
59 57
60 -
61 TrafficSelector selector = DefaultTrafficSelector.builder() 58 TrafficSelector selector = DefaultTrafficSelector.builder()
62 .matchEthType(Ethernet.TYPE_IPV4) 59 .matchEthType(Ethernet.TYPE_IPV4)
63 .build(); 60 .build();
64 TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); 61 TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
65 62
66 - Intent intent = 63 + Intent intent = new MultiPointToSinglePointIntent(appId(), selector, treatment,
67 - new MultiPointToSinglePointIntent(new IntentId(id++), 64 + ingressPoints, egress);
68 - selector,
69 - treatment,
70 - ingressPoints,
71 - egress);
72 service.submit(intent); 65 service.submit(intent);
73 } 66 }
74 67
......
...@@ -11,11 +11,13 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment; ...@@ -11,11 +11,13 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment;
11 import org.onlab.onos.net.flow.TrafficSelector; 11 import org.onlab.onos.net.flow.TrafficSelector;
12 import org.onlab.onos.net.flow.TrafficTreatment; 12 import org.onlab.onos.net.flow.TrafficTreatment;
13 import org.onlab.onos.net.intent.Intent; 13 import org.onlab.onos.net.intent.Intent;
14 -import org.onlab.onos.net.intent.IntentId;
15 import org.onlab.onos.net.intent.IntentService; 14 import org.onlab.onos.net.intent.IntentService;
16 import org.onlab.onos.net.intent.PointToPointIntent; 15 import org.onlab.onos.net.intent.PointToPointIntent;
17 import org.onlab.packet.Ethernet; 16 import org.onlab.packet.Ethernet;
18 17
18 +import static org.onlab.onos.net.DeviceId.deviceId;
19 +import static org.onlab.onos.net.PortNumber.portNumber;
20 +
19 /** 21 /**
20 * Installs point-to-point connectivity intents. 22 * Installs point-to-point connectivity intents.
21 */ 23 */
...@@ -33,20 +35,16 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand { ...@@ -33,20 +35,16 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand {
33 required = true, multiValued = false) 35 required = true, multiValued = false)
34 String egressDeviceString = null; 36 String egressDeviceString = null;
35 37
36 - private static long id = 0x7470001;
37 -
38 @Override 38 @Override
39 protected void execute() { 39 protected void execute() {
40 IntentService service = get(IntentService.class); 40 IntentService service = get(IntentService.class);
41 41
42 - DeviceId ingressDeviceId = DeviceId.deviceId(getDeviceId(ingressDeviceString)); 42 + DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
43 - PortNumber ingressPortNumber = 43 + PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
44 - PortNumber.portNumber(getPortNumber(ingressDeviceString));
45 ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber); 44 ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
46 45
47 - DeviceId egressDeviceId = DeviceId.deviceId(getDeviceId(egressDeviceString)); 46 + DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
48 - PortNumber egressPortNumber = 47 + PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
49 - PortNumber.portNumber(getPortNumber(egressDeviceString));
50 ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); 48 ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
51 49
52 TrafficSelector selector = DefaultTrafficSelector.builder() 50 TrafficSelector selector = DefaultTrafficSelector.builder()
...@@ -54,12 +52,8 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand { ...@@ -54,12 +52,8 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand {
54 .build(); 52 .build();
55 TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); 53 TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
56 54
57 - Intent intent = 55 + Intent intent = new PointToPointIntent(appId(), selector, treatment,
58 - new PointToPointIntent(new IntentId(id++), 56 + ingress, egress);
59 - selector,
60 - treatment,
61 - ingress,
62 - egress);
63 service.submit(intent); 57 service.submit(intent);
64 } 58 }
65 59
......
1 package org.onlab.onos.cli.net; 1 package org.onlab.onos.cli.net;
2 2
3 -import java.util.concurrent.CountDownLatch;
4 -import java.util.concurrent.TimeUnit;
5 -
6 import org.apache.karaf.shell.commands.Argument; 3 import org.apache.karaf.shell.commands.Argument;
7 import org.apache.karaf.shell.commands.Command; 4 import org.apache.karaf.shell.commands.Command;
8 import org.onlab.onos.cli.AbstractShellCommand; 5 import org.onlab.onos.cli.AbstractShellCommand;
...@@ -16,20 +13,25 @@ import org.onlab.onos.net.flow.TrafficTreatment; ...@@ -16,20 +13,25 @@ import org.onlab.onos.net.flow.TrafficTreatment;
16 import org.onlab.onos.net.intent.Intent; 13 import org.onlab.onos.net.intent.Intent;
17 import org.onlab.onos.net.intent.IntentEvent; 14 import org.onlab.onos.net.intent.IntentEvent;
18 import org.onlab.onos.net.intent.IntentEvent.Type; 15 import org.onlab.onos.net.intent.IntentEvent.Type;
19 -import org.onlab.onos.net.intent.IntentId;
20 import org.onlab.onos.net.intent.IntentListener; 16 import org.onlab.onos.net.intent.IntentListener;
21 import org.onlab.onos.net.intent.IntentService; 17 import org.onlab.onos.net.intent.IntentService;
22 import org.onlab.onos.net.intent.PointToPointIntent; 18 import org.onlab.onos.net.intent.PointToPointIntent;
23 import org.onlab.packet.Ethernet; 19 import org.onlab.packet.Ethernet;
24 import org.onlab.packet.MacAddress; 20 import org.onlab.packet.MacAddress;
25 21
22 +import java.util.concurrent.CountDownLatch;
23 +import java.util.concurrent.TimeUnit;
24 +
25 +import static org.onlab.onos.net.DeviceId.deviceId;
26 +import static org.onlab.onos.net.PortNumber.portNumber;
27 +
26 /** 28 /**
27 * Installs point-to-point connectivity intents. 29 * Installs point-to-point connectivity intents.
28 */ 30 */
29 @Command(scope = "onos", name = "push-test-intents", 31 @Command(scope = "onos", name = "push-test-intents",
30 description = "Installs random intents to test throughput") 32 description = "Installs random intents to test throughput")
31 public class IntentPushTestCommand extends AbstractShellCommand 33 public class IntentPushTestCommand extends AbstractShellCommand
32 - implements IntentListener { 34 + implements IntentListener {
33 35
34 @Argument(index = 0, name = "ingressDevice", 36 @Argument(index = 0, name = "ingressDevice",
35 description = "Ingress Device/Port Description", 37 description = "Ingress Device/Port Description",
...@@ -42,8 +44,8 @@ public class IntentPushTestCommand extends AbstractShellCommand ...@@ -42,8 +44,8 @@ public class IntentPushTestCommand extends AbstractShellCommand
42 String egressDeviceString = null; 44 String egressDeviceString = null;
43 45
44 @Argument(index = 2, name = "count", 46 @Argument(index = 2, name = "count",
45 - description = "Number of intents to push", 47 + description = "Number of intents to push",
46 - required = true, multiValued = false) 48 + required = true, multiValued = false)
47 String countString = null; 49 String countString = null;
48 50
49 51
...@@ -57,14 +59,12 @@ public class IntentPushTestCommand extends AbstractShellCommand ...@@ -57,14 +59,12 @@ public class IntentPushTestCommand extends AbstractShellCommand
57 protected void execute() { 59 protected void execute() {
58 service = get(IntentService.class); 60 service = get(IntentService.class);
59 61
60 - DeviceId ingressDeviceId = DeviceId.deviceId(getDeviceId(ingressDeviceString)); 62 + DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
61 - PortNumber ingressPortNumber = 63 + PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
62 - PortNumber.portNumber(getPortNumber(ingressDeviceString));
63 ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber); 64 ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
64 65
65 - DeviceId egressDeviceId = DeviceId.deviceId(getDeviceId(egressDeviceString)); 66 + DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
66 - PortNumber egressPortNumber = 67 + PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
67 - PortNumber.portNumber(getPortNumber(egressDeviceString));
68 ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); 68 ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
69 69
70 TrafficSelector.Builder selector = DefaultTrafficSelector.builder() 70 TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
...@@ -79,14 +79,10 @@ public class IntentPushTestCommand extends AbstractShellCommand ...@@ -79,14 +79,10 @@ public class IntentPushTestCommand extends AbstractShellCommand
79 start = System.currentTimeMillis(); 79 start = System.currentTimeMillis();
80 for (int i = 0; i < count; i++) { 80 for (int i = 0; i < count; i++) {
81 TrafficSelector s = selector 81 TrafficSelector s = selector
82 - .matchEthSrc(MacAddress.valueOf(i)) 82 + .matchEthSrc(MacAddress.valueOf(i))
83 - .build(); 83 + .build();
84 - Intent intent = 84 + Intent intent = new PointToPointIntent(appId(), s, treatment,
85 - new PointToPointIntent(new IntentId(id++), 85 + ingress, egress);
86 - s,
87 - treatment,
88 - ingress,
89 - egress);
90 service.submit(intent); 86 service.submit(intent);
91 } 87 }
92 try { 88 try {
......
...@@ -7,6 +7,8 @@ import org.onlab.onos.net.intent.Intent; ...@@ -7,6 +7,8 @@ import org.onlab.onos.net.intent.Intent;
7 import org.onlab.onos.net.intent.IntentId; 7 import org.onlab.onos.net.intent.IntentId;
8 import org.onlab.onos.net.intent.IntentService; 8 import org.onlab.onos.net.intent.IntentService;
9 9
10 +import java.math.BigInteger;
11 +
10 /** 12 /**
11 * Removes host-to-host connectivity intent. 13 * Removes host-to-host connectivity intent.
12 */ 14 */
...@@ -22,13 +24,11 @@ public class IntentRemoveCommand extends AbstractShellCommand { ...@@ -22,13 +24,11 @@ public class IntentRemoveCommand extends AbstractShellCommand {
22 protected void execute() { 24 protected void execute() {
23 IntentService service = get(IntentService.class); 25 IntentService service = get(IntentService.class);
24 26
25 - int radix = id.startsWith("0x") ? 16 : 10; 27 + if (id.startsWith("0x")) {
26 - if (radix == 16) {
27 id = id.replaceFirst("0x", ""); 28 id = id.replaceFirst("0x", "");
28 } 29 }
29 - IntentId intentId = new IntentId(Long.parseLong(id, radix));
30 -
31 30
31 + IntentId intentId = IntentId.valueOf(new BigInteger(id, 16).longValue());
32 Intent intent = service.getIntent(intentId); 32 Intent intent = service.getIntent(intentId);
33 if (intent != null) { 33 if (intent != null) {
34 service.withdraw(intent); 34 service.withdraw(intent);
......
...@@ -18,7 +18,8 @@ public class IntentsListCommand extends AbstractShellCommand { ...@@ -18,7 +18,8 @@ public class IntentsListCommand extends AbstractShellCommand {
18 IntentService service = get(IntentService.class); 18 IntentService service = get(IntentService.class);
19 for (Intent intent : service.getIntents()) { 19 for (Intent intent : service.getIntents()) {
20 IntentState state = service.getIntentState(intent.id()); 20 IntentState state = service.getIntentState(intent.id());
21 - print("%s %s %s", intent.id(), state, intent); 21 + print("id=%s, state=%s, appId=%s, %s",
22 + intent.id(), state, intent.appId().name(), intent);
22 } 23 }
23 } 24 }
24 25
......
1 package org.onlab.onos.cluster; 1 package org.onlab.onos.cluster;
2 2
3 -import java.util.Collections;
4 -import java.util.LinkedList;
5 import java.util.List; 3 import java.util.List;
6 import java.util.Objects; 4 import java.util.Objects;
7 5
8 -import static com.google.common.base.Preconditions.checkNotNull; 6 +import com.google.common.collect.ImmutableList;
9 7
10 /** 8 /**
11 * A container for detailed role information for a device, 9 * A container for detailed role information for a device,
...@@ -18,9 +16,7 @@ public class RoleInfo { ...@@ -18,9 +16,7 @@ public class RoleInfo {
18 16
19 public RoleInfo(NodeId master, List<NodeId> backups) { 17 public RoleInfo(NodeId master, List<NodeId> backups) {
20 this.master = master; 18 this.master = master;
21 - this.backups = new LinkedList<>(); 19 + this.backups = ImmutableList.copyOf(backups);
22 -
23 - this.backups.addAll(checkNotNull(backups));
24 } 20 }
25 21
26 public NodeId master() { 22 public NodeId master() {
...@@ -28,7 +24,7 @@ public class RoleInfo { ...@@ -28,7 +24,7 @@ public class RoleInfo {
28 } 24 }
29 25
30 public List<NodeId> backups() { 26 public List<NodeId> backups() {
31 - return Collections.unmodifiableList(backups); 27 + return backups;
32 } 28 }
33 29
34 @Override 30 @Override
...@@ -57,10 +53,10 @@ public class RoleInfo { ...@@ -57,10 +53,10 @@ public class RoleInfo {
57 @Override 53 @Override
58 public String toString() { 54 public String toString() {
59 final StringBuilder builder = new StringBuilder(); 55 final StringBuilder builder = new StringBuilder();
60 - builder.append("master: \n\t").append(master).append("\n"); 56 + builder.append("master:").append(master).append(",");
61 - builder.append("backups: \n"); 57 + builder.append("backups:");
62 for (NodeId n : backups) { 58 for (NodeId n : backups) {
63 - builder.append("\t").append(n).append("\n"); 59 + builder.append(" ").append(n);
64 } 60 }
65 return builder.toString(); 61 return builder.toString();
66 } 62 }
......
...@@ -3,7 +3,7 @@ package org.onlab.onos.net; ...@@ -3,7 +3,7 @@ package org.onlab.onos.net;
3 /** 3 /**
4 * Abstraction of a network infrastructure link. 4 * Abstraction of a network infrastructure link.
5 */ 5 */
6 -public interface Link extends Annotated, Provided { 6 +public interface Link extends Annotated, Provided, NetworkResource {
7 7
8 /** 8 /**
9 * Coarse representation of the link type. 9 * Coarse representation of the link type.
......
...@@ -8,7 +8,6 @@ import org.onlab.packet.IpPrefix; ...@@ -8,7 +8,6 @@ import org.onlab.packet.IpPrefix;
8 import org.onlab.packet.MacAddress; 8 import org.onlab.packet.MacAddress;
9 import org.onlab.packet.VlanId; 9 import org.onlab.packet.VlanId;
10 10
11 -import java.util.Collections;
12 import java.util.HashMap; 11 import java.util.HashMap;
13 import java.util.Map; 12 import java.util.Map;
14 import java.util.Objects; 13 import java.util.Objects;
...@@ -27,7 +26,7 @@ public final class DefaultTrafficSelector implements TrafficSelector { ...@@ -27,7 +26,7 @@ public final class DefaultTrafficSelector implements TrafficSelector {
27 * @param criteria criteria 26 * @param criteria criteria
28 */ 27 */
29 private DefaultTrafficSelector(Set<Criterion> criteria) { 28 private DefaultTrafficSelector(Set<Criterion> criteria) {
30 - this.criteria = Collections.unmodifiableSet(criteria); 29 + this.criteria = ImmutableSet.copyOf(criteria);
31 } 30 }
32 31
33 @Override 32 @Override
......
...@@ -7,7 +7,8 @@ import org.onlab.packet.IpPrefix; ...@@ -7,7 +7,8 @@ import org.onlab.packet.IpPrefix;
7 import org.onlab.packet.MacAddress; 7 import org.onlab.packet.MacAddress;
8 import org.onlab.packet.VlanId; 8 import org.onlab.packet.VlanId;
9 9
10 -import java.util.Collections; 10 +import com.google.common.collect.ImmutableList;
11 +
11 import java.util.LinkedList; 12 import java.util.LinkedList;
12 import java.util.List; 13 import java.util.List;
13 import java.util.Objects; 14 import java.util.Objects;
...@@ -25,7 +26,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { ...@@ -25,7 +26,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
25 * @param instructions treatment instructions 26 * @param instructions treatment instructions
26 */ 27 */
27 private DefaultTrafficTreatment(List<Instruction> instructions) { 28 private DefaultTrafficTreatment(List<Instruction> instructions) {
28 - this.instructions = Collections.unmodifiableList(instructions); 29 + this.instructions = ImmutableList.copyOf(instructions);
29 } 30 }
30 31
31 @Override 32 @Override
......
...@@ -24,7 +24,18 @@ public class FlowRuleEvent extends AbstractEvent<FlowRuleEvent.Type, FlowRule> { ...@@ -24,7 +24,18 @@ public class FlowRuleEvent extends AbstractEvent<FlowRuleEvent.Type, FlowRule> {
24 /** 24 /**
25 * Signifies that a rule has been updated. 25 * Signifies that a rule has been updated.
26 */ 26 */
27 - RULE_UPDATED 27 + RULE_UPDATED,
28 +
29 + // internal event between Manager <-> Store
30 +
31 + /*
32 + * Signifies that a request to add flow rule has been added to the store.
33 + */
34 + RULE_ADD_REQUESTED,
35 + /*
36 + * Signifies that a request to remove flow rule has been added to the store.
37 + */
38 + RULE_REMOVE_REQUESTED,
28 } 39 }
29 40
30 /** 41 /**
......
...@@ -44,16 +44,18 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat ...@@ -44,16 +44,18 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat
44 * Stores a new flow rule without generating events. 44 * Stores a new flow rule without generating events.
45 * 45 *
46 * @param rule the flow rule to add 46 * @param rule the flow rule to add
47 + * @return true if the rule should be handled locally
47 */ 48 */
48 - void storeFlowRule(FlowRule rule); 49 + boolean storeFlowRule(FlowRule rule);
49 50
50 /** 51 /**
51 * Marks a flow rule for deletion. Actual deletion will occur 52 * Marks a flow rule for deletion. Actual deletion will occur
52 * when the provider indicates that the flow has been removed. 53 * when the provider indicates that the flow has been removed.
53 * 54 *
54 * @param rule the flow rule to delete 55 * @param rule the flow rule to delete
56 + * @return true if the rule should be handled locally
55 */ 57 */
56 - void deleteFlowRule(FlowRule rule); 58 + boolean deleteFlowRule(FlowRule rule);
57 59
58 /** 60 /**
59 * Stores a new flow rule, or updates an existing entry. 61 * Stores a new flow rule, or updates an existing entry.
......
1 -package org.onlab.onos.net.intent;
2 -
3 -/**
4 - * Base intent implementation.
5 - */
6 -public abstract class AbstractIntent implements Intent {
7 -
8 - private final IntentId id;
9 -
10 - /**
11 - * Creates a base intent with the specified identifier.
12 - *
13 - * @param id intent identifier
14 - */
15 - protected AbstractIntent(IntentId id) {
16 - this.id = id;
17 - }
18 -
19 - /**
20 - * Constructor for serializer.
21 - */
22 - protected AbstractIntent() {
23 - this.id = null;
24 - }
25 -
26 - @Override
27 - public IntentId id() {
28 - return id;
29 - }
30 -
31 - @Override
32 - public boolean equals(Object o) {
33 - if (this == o) {
34 - return true;
35 - }
36 - if (o == null || getClass() != o.getClass()) {
37 - return false;
38 - }
39 -
40 - AbstractIntent that = (AbstractIntent) o;
41 - return id.equals(that.id);
42 - }
43 -
44 - @Override
45 - public int hashCode() {
46 - return id.hashCode();
47 - }
48 -
49 -}
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 -import com.google.common.base.Objects; 3 +import com.google.common.collect.ImmutableSet;
4 +import org.onlab.onos.ApplicationId;
5 +import org.onlab.onos.net.Link;
6 +import org.onlab.onos.net.NetworkResource;
4 import org.onlab.onos.net.flow.TrafficSelector; 7 import org.onlab.onos.net.flow.TrafficSelector;
5 import org.onlab.onos.net.flow.TrafficTreatment; 8 import org.onlab.onos.net.flow.TrafficTreatment;
6 9
10 +import java.util.Collection;
11 +
7 import static com.google.common.base.Preconditions.checkNotNull; 12 import static com.google.common.base.Preconditions.checkNotNull;
8 13
9 /** 14 /**
10 * Abstraction of connectivity intent for traffic matching some criteria. 15 * Abstraction of connectivity intent for traffic matching some criteria.
11 */ 16 */
12 -public abstract class ConnectivityIntent extends AbstractIntent { 17 +public abstract class ConnectivityIntent extends Intent {
13 18
14 // TODO: other forms of intents should be considered for this family: 19 // TODO: other forms of intents should be considered for this family:
15 // point-to-point with constraints (waypoints/obstacles) 20 // point-to-point with constraints (waypoints/obstacles)
...@@ -19,24 +24,26 @@ public abstract class ConnectivityIntent extends AbstractIntent { ...@@ -19,24 +24,26 @@ public abstract class ConnectivityIntent extends AbstractIntent {
19 // ... 24 // ...
20 25
21 private final TrafficSelector selector; 26 private final TrafficSelector selector;
22 - // TODO: should consider which is better for multiple actions,
23 - // defining compound action class or using list of actions.
24 private final TrafficTreatment treatment; 27 private final TrafficTreatment treatment;
25 28
26 /** 29 /**
27 - * Creates a connectivity intent that matches on the specified intent 30 + * Creates a connectivity intent that matches on the specified selector
28 - * and applies the specified treatement. 31 + * and applies the specified treatment.
29 * 32 *
30 - * @param intentId intent identifier 33 + * @param id intent identifier
31 - * @param selector traffic selector 34 + * @param appId application identifier
32 - * @param treatement treatement 35 + * @param resources required network resources (optional)
36 + * @param selector traffic selector
37 + * @param treatment treatment
33 * @throws NullPointerException if the selector or treatement is null 38 * @throws NullPointerException if the selector or treatement is null
34 */ 39 */
35 - protected ConnectivityIntent(IntentId intentId, TrafficSelector selector, 40 + protected ConnectivityIntent(IntentId id, ApplicationId appId,
36 - TrafficTreatment treatement) { 41 + Collection<NetworkResource> resources,
37 - super(intentId); 42 + TrafficSelector selector,
43 + TrafficTreatment treatment) {
44 + super(id, appId, resources);
38 this.selector = checkNotNull(selector); 45 this.selector = checkNotNull(selector);
39 - this.treatment = checkNotNull(treatement); 46 + this.treatment = checkNotNull(treatment);
40 } 47 }
41 48
42 /** 49 /**
...@@ -66,19 +73,14 @@ public abstract class ConnectivityIntent extends AbstractIntent { ...@@ -66,19 +73,14 @@ public abstract class ConnectivityIntent extends AbstractIntent {
66 return treatment; 73 return treatment;
67 } 74 }
68 75
69 - @Override 76 + /**
70 - public boolean equals(Object o) { 77 + * Produces a collection of network resources from the given links.
71 - if (!super.equals(o)) { 78 + *
72 - return false; 79 + * @param links collection of links
73 - } 80 + * @return collection of link resources
74 - ConnectivityIntent that = (ConnectivityIntent) o; 81 + */
75 - return Objects.equal(this.selector, that.selector) 82 + protected static Collection<NetworkResource> resources(Collection<Link> links) {
76 - && Objects.equal(this.treatment, that.treatment); 83 + return ImmutableSet.<NetworkResource>copyOf(links);
77 - }
78 -
79 - @Override
80 - public int hashCode() {
81 - return Objects.hashCode(super.hashCode(), selector, treatment);
82 } 84 }
83 85
84 } 86 }
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 import com.google.common.base.MoreObjects; 3 import com.google.common.base.MoreObjects;
4 +import org.onlab.onos.ApplicationId;
4 import org.onlab.onos.net.HostId; 5 import org.onlab.onos.net.HostId;
5 import org.onlab.onos.net.flow.TrafficSelector; 6 import org.onlab.onos.net.flow.TrafficSelector;
6 import org.onlab.onos.net.flow.TrafficTreatment; 7 import org.onlab.onos.net.flow.TrafficTreatment;
7 8
8 -import java.util.Objects;
9 -
10 import static com.google.common.base.Preconditions.checkNotNull; 9 import static com.google.common.base.Preconditions.checkNotNull;
11 10
12 /** 11 /**
...@@ -18,25 +17,33 @@ public final class HostToHostIntent extends ConnectivityIntent { ...@@ -18,25 +17,33 @@ public final class HostToHostIntent extends ConnectivityIntent {
18 private final HostId two; 17 private final HostId two;
19 18
20 /** 19 /**
21 - * Creates a new point-to-point intent with the supplied ingress/egress 20 + * Creates a new host-to-host intent with the supplied host pair.
22 - * ports.
23 * 21 *
24 - * @param intentId intent identifier 22 + * @param appId application identifier
25 * @param one first host 23 * @param one first host
26 * @param two second host 24 * @param two second host
27 * @param selector action 25 * @param selector action
28 * @param treatment ingress port 26 * @param treatment ingress port
29 - * @throws NullPointerException if {@code ingressPort} or {@code egressPort} 27 + * @throws NullPointerException if {@code one} or {@code two} is null.
30 - * is null.
31 */ 28 */
32 - public HostToHostIntent(IntentId intentId, HostId one, HostId two, 29 + public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
33 TrafficSelector selector, 30 TrafficSelector selector,
34 TrafficTreatment treatment) { 31 TrafficTreatment treatment) {
35 - super(intentId, selector, treatment); 32 + super(id(HostToHostIntent.class, min(one, two), max(one, two),
33 + selector, treatment),
34 + appId, null, selector, treatment);
36 this.one = checkNotNull(one); 35 this.one = checkNotNull(one);
37 this.two = checkNotNull(two); 36 this.two = checkNotNull(two);
38 } 37 }
39 38
39 + private static HostId min(HostId one, HostId two) {
40 + return one.hashCode() < two.hashCode() ? one : two;
41 + }
42 +
43 + private static HostId max(HostId one, HostId two) {
44 + return one.hashCode() > two.hashCode() ? one : two;
45 + }
46 +
40 /** 47 /**
41 * Returns identifier of the first host. 48 * Returns identifier of the first host.
42 * 49 *
...@@ -56,31 +63,10 @@ public final class HostToHostIntent extends ConnectivityIntent { ...@@ -56,31 +63,10 @@ public final class HostToHostIntent extends ConnectivityIntent {
56 } 63 }
57 64
58 @Override 65 @Override
59 - public boolean equals(Object o) {
60 - if (this == o) {
61 - return true;
62 - }
63 - if (o == null || getClass() != o.getClass()) {
64 - return false;
65 - }
66 - if (!super.equals(o)) {
67 - return false;
68 - }
69 -
70 - HostToHostIntent that = (HostToHostIntent) o;
71 - return Objects.equals(this.one, that.one)
72 - && Objects.equals(this.two, that.two);
73 - }
74 -
75 - @Override
76 - public int hashCode() {
77 - return Objects.hash(super.hashCode(), one, two);
78 - }
79 -
80 - @Override
81 public String toString() { 66 public String toString() {
82 return MoreObjects.toStringHelper(getClass()) 67 return MoreObjects.toStringHelper(getClass())
83 .add("id", id()) 68 .add("id", id())
69 + .add("appId", appId())
84 .add("selector", selector()) 70 .add("selector", selector())
85 .add("treatment", treatment()) 71 .add("treatment", treatment())
86 .add("one", one) 72 .add("one", one)
......
1 -package org.onlab.onos.net.intent;
2 -//TODO is this the right package?
3 -
4 -/**
5 - * A generalized interface for ID generation
6 - *
7 - * {@link #getNewId()} generates a globally unique ID instance on
8 - * each invocation.
9 - *
10 - * @param <T> the type of ID
11 - */
12 -// TODO: do we need to define a base marker interface for ID,
13 -// then changed the type parameter to <T extends BaseId> something
14 -// like that?
15 -public interface IdGenerator<T> {
16 - /**
17 - * Returns a globally unique ID instance.
18 - *
19 - * @return globally unique ID instance
20 - */
21 - T getNewId();
22 -}
1 -package org.onlab.onos.net.intent;
2 -
3 -import org.onlab.onos.net.Link;
4 -
5 -import java.util.Collection;
6 -
7 -/**
8 - * Abstraction of an intent that can be installed into
9 - * the underlying system without additional compilation.
10 - */
11 -public interface InstallableIntent extends Intent {
12 -
13 - /**
14 - * Returns the collection of links that are required for this installable
15 - * intent to exist.
16 - *
17 - * @return collection of links
18 - */
19 - // FIXME: replace this with 'NetworkResource'
20 - Collection<Link> requiredLinks();
21 -
22 -}
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 +import org.onlab.onos.ApplicationId;
4 +import org.onlab.onos.net.NetworkResource;
5 +
6 +import java.util.Collection;
7 +import java.util.Objects;
8 +
9 +import static com.google.common.base.Preconditions.checkNotNull;
10 +
3 /** 11 /**
4 * Abstraction of an application level intent. 12 * Abstraction of an application level intent.
5 * <p/> 13 * <p/>
6 * Make sure that an Intent should be immutable when a new type is defined. 14 * Make sure that an Intent should be immutable when a new type is defined.
7 */ 15 */
8 -public interface Intent extends BatchOperationTarget { 16 +public abstract class Intent implements BatchOperationTarget {
17 +
18 + private final IntentId id;
19 + private final ApplicationId appId;
20 + private final Collection<NetworkResource> resources;
21 +
22 + /**
23 + * Constructor for serializer.
24 + */
25 + protected Intent() {
26 + this.id = null;
27 + this.appId = null;
28 + this.resources = null;
29 + }
30 +
31 + /**
32 + * Creates a new intent.
33 + *
34 + * @param id intent identifier
35 + * @param appId application identifier
36 + * @param resources required network resources (optional)
37 + */
38 + protected Intent(IntentId id, ApplicationId appId,
39 + Collection<NetworkResource> resources) {
40 + this.appId = checkNotNull(appId, "Application ID cannot be null");
41 + this.id = checkNotNull(id, "Fingerprint cannot be null");
42 + this.resources = resources;
43 + }
44 +
9 /** 45 /**
10 * Returns the intent identifier. 46 * Returns the intent identifier.
11 * 47 *
48 + * @return intent fingerprint
49 + */
50 + public IntentId id() {
51 + return id;
52 + }
53 +
54 + /**
55 + * Returns the identifier of the application that requested the intent.
56 + *
57 + * @return application identifier
58 + */
59 + public ApplicationId appId() {
60 + return appId;
61 + }
62 +
63 + /**
64 + * Returns the collection of resources required for this intent.
65 + *
66 + * @return collection of resources; may be null
67 + */
68 + public Collection<NetworkResource> resources() {
69 + return resources;
70 + }
71 +
72 + /**
73 + * Produces an intent identifier backed by hash-like fingerprint for the
74 + * specified class of intent and its constituent fields.
75 + *
76 + * @param fields intent fields
12 * @return intent identifier 77 * @return intent identifier
13 */ 78 */
14 - IntentId id(); 79 + protected static IntentId id(Object... fields) {
80 + return IntentId.valueOf(Objects.hash(fields));
81 + }
82 +
83 + /**
84 + * Indicates whether or not the intent is installable.
85 + *
86 + * @return true if installable
87 + */
88 + public boolean isInstallable() {
89 + return false;
90 + }
91 +
92 + @Override
93 + public int hashCode() {
94 + return Objects.hash(id);
95 + }
96 +
97 + @Override
98 + public boolean equals(Object obj) {
99 + if (this == obj) {
100 + return true;
101 + }
102 + if (obj == null || getClass() != obj.getClass()) {
103 + return false;
104 + }
105 + final Intent other = (Intent) obj;
106 + return Objects.equals(this.id, other.id);
107 + }
108 +
15 } 109 }
......
...@@ -38,7 +38,7 @@ public interface IntentExtensionService { ...@@ -38,7 +38,7 @@ public interface IntentExtensionService {
38 * @param installer intent installer 38 * @param installer intent installer
39 * @param <T> the type of installable intent 39 * @param <T> the type of installable intent
40 */ 40 */
41 - <T extends InstallableIntent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer); 41 + <T extends Intent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer);
42 42
43 /** 43 /**
44 * Unregisters the installer for the given installable intent class. 44 * Unregisters the installer for the given installable intent class.
...@@ -46,12 +46,12 @@ public interface IntentExtensionService { ...@@ -46,12 +46,12 @@ public interface IntentExtensionService {
46 * @param cls installable intent class 46 * @param cls installable intent class
47 * @param <T> the type of installable intent 47 * @param <T> the type of installable intent
48 */ 48 */
49 - <T extends InstallableIntent> void unregisterInstaller(Class<T> cls); 49 + <T extends Intent> void unregisterInstaller(Class<T> cls);
50 50
51 /** 51 /**
52 * Returns immutable set of bindings of currently registered intent installers. 52 * Returns immutable set of bindings of currently registered intent installers.
53 * 53 *
54 * @return the set of installer bindings 54 * @return the set of installer bindings
55 */ 55 */
56 - Map<Class<? extends InstallableIntent>, IntentInstaller<? extends InstallableIntent>> getInstallers(); 56 + Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> getInstallers();
57 } 57 }
......
...@@ -7,43 +7,37 @@ package org.onlab.onos.net.intent; ...@@ -7,43 +7,37 @@ package org.onlab.onos.net.intent;
7 */ 7 */
8 public final class IntentId implements BatchOperationTarget { 8 public final class IntentId implements BatchOperationTarget {
9 9
10 - private static final int DEC = 10; 10 + private final long fingerprint;
11 - private static final int HEX = 16;
12 -
13 - private final long id;
14 11
15 /** 12 /**
16 * Creates an intent identifier from the specified string representation. 13 * Creates an intent identifier from the specified string representation.
17 * 14 *
18 - * @param value long value 15 + * @param fingerprint long value
19 * @return intent identifier 16 * @return intent identifier
20 */ 17 */
21 - public static IntentId valueOf(String value) { 18 + public static IntentId valueOf(long fingerprint) {
22 - long id = value.toLowerCase().startsWith("0x") 19 + return new IntentId(fingerprint);
23 - ? Long.parseLong(value.substring(2), HEX)
24 - : Long.parseLong(value, DEC);
25 - return new IntentId(id);
26 } 20 }
27 21
28 /** 22 /**
29 * Constructor for serializer. 23 * Constructor for serializer.
30 */ 24 */
31 - protected IntentId() { 25 + IntentId() {
32 - this.id = 0; 26 + this.fingerprint = 0;
33 } 27 }
34 28
35 /** 29 /**
36 * Constructs the ID corresponding to a given long value. 30 * Constructs the ID corresponding to a given long value.
37 * 31 *
38 - * @param id the underlying value of this ID 32 + * @param fingerprint the underlying value of this ID
39 */ 33 */
40 - public IntentId(long id) { 34 + IntentId(long fingerprint) {
41 - this.id = id; 35 + this.fingerprint = fingerprint;
42 } 36 }
43 37
44 @Override 38 @Override
45 public int hashCode() { 39 public int hashCode() {
46 - return (int) (id ^ (id >>> 32)); 40 + return (int) (fingerprint ^ (fingerprint >>> 32));
47 } 41 }
48 42
49 @Override 43 @Override
...@@ -51,18 +45,16 @@ public final class IntentId implements BatchOperationTarget { ...@@ -51,18 +45,16 @@ public final class IntentId implements BatchOperationTarget {
51 if (obj == this) { 45 if (obj == this) {
52 return true; 46 return true;
53 } 47 }
54 -
55 if (!(obj instanceof IntentId)) { 48 if (!(obj instanceof IntentId)) {
56 return false; 49 return false;
57 } 50 }
58 -
59 IntentId that = (IntentId) obj; 51 IntentId that = (IntentId) obj;
60 - return this.id == that.id; 52 + return this.fingerprint == that.fingerprint;
61 } 53 }
62 54
63 @Override 55 @Override
64 public String toString() { 56 public String toString() {
65 - return "0x" + Long.toHexString(id); 57 + return "0x" + Long.toHexString(fingerprint);
66 } 58 }
67 59
68 } 60 }
......
...@@ -7,7 +7,7 @@ import org.onlab.onos.net.flow.FlowRuleBatchOperation; ...@@ -7,7 +7,7 @@ import org.onlab.onos.net.flow.FlowRuleBatchOperation;
7 /** 7 /**
8 * Abstraction of entity capable of installing intents to the environment. 8 * Abstraction of entity capable of installing intents to the environment.
9 */ 9 */
10 -public interface IntentInstaller<T extends InstallableIntent> { 10 +public interface IntentInstaller<T extends Intent> {
11 /** 11 /**
12 * Installs the specified intent to the environment. 12 * Installs the specified intent to the environment.
13 * 13 *
......
...@@ -77,8 +77,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { ...@@ -77,8 +77,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
77 * @param intentId original intent identifier 77 * @param intentId original intent identifier
78 * @param installableIntents compiled installable intents 78 * @param installableIntents compiled installable intents
79 */ 79 */
80 - void addInstallableIntents(IntentId intentId, 80 + void addInstallableIntents(IntentId intentId, List<Intent> installableIntents);
81 - List<InstallableIntent> installableIntents);
82 81
83 /** 82 /**
84 * Returns the list of the installable events associated with the specified 83 * Returns the list of the installable events associated with the specified
...@@ -87,7 +86,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { ...@@ -87,7 +86,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
87 * @param intentId original intent identifier 86 * @param intentId original intent identifier
88 * @return compiled installable intents 87 * @return compiled installable intents
89 */ 88 */
90 - List<InstallableIntent> getInstallableIntents(IntentId intentId); 89 + List<Intent> getInstallableIntents(IntentId intentId);
91 90
92 // TODO: this should be triggered from with the store as a result of removeIntent call 91 // TODO: this should be triggered from with the store as a result of removeIntent call
93 92
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 -import java.util.Collection; 3 +import com.google.common.base.MoreObjects;
4 -import java.util.Objects; 4 +import org.onlab.onos.ApplicationId;
5 -import java.util.Set;
6 -
7 import org.onlab.onos.net.ConnectPoint; 5 import org.onlab.onos.net.ConnectPoint;
8 import org.onlab.onos.net.Link; 6 import org.onlab.onos.net.Link;
9 import org.onlab.onos.net.flow.TrafficSelector; 7 import org.onlab.onos.net.flow.TrafficSelector;
10 import org.onlab.onos.net.flow.TrafficTreatment; 8 import org.onlab.onos.net.flow.TrafficTreatment;
11 9
12 -import com.google.common.base.MoreObjects; 10 +import java.util.Set;
13 11
14 /** 12 /**
15 * Abstraction of a connectivity intent that is implemented by a set of path 13 * Abstraction of a connectivity intent that is implemented by a set of path
16 * segments. 14 * segments.
17 */ 15 */
18 -public final class LinkCollectionIntent extends ConnectivityIntent implements InstallableIntent { 16 +public final class LinkCollectionIntent extends ConnectivityIntent {
19 17
20 private final Set<Link> links; 18 private final Set<Link> links;
21 19
...@@ -25,34 +23,33 @@ public final class LinkCollectionIntent extends ConnectivityIntent implements In ...@@ -25,34 +23,33 @@ public final class LinkCollectionIntent extends ConnectivityIntent implements In
25 * Creates a new point-to-point intent with the supplied ingress/egress 23 * Creates a new point-to-point intent with the supplied ingress/egress
26 * ports and using the specified explicit path. 24 * ports and using the specified explicit path.
27 * 25 *
28 - * @param id intent identifier 26 + * @param appId application identifier
29 * @param selector traffic match 27 * @param selector traffic match
30 * @param treatment action 28 * @param treatment action
31 * @param links traversed links 29 * @param links traversed links
32 * @param egressPoint egress point 30 * @param egressPoint egress point
33 * @throws NullPointerException {@code path} is null 31 * @throws NullPointerException {@code path} is null
34 */ 32 */
35 - public LinkCollectionIntent(IntentId id, 33 + public LinkCollectionIntent(ApplicationId appId,
36 TrafficSelector selector, 34 TrafficSelector selector,
37 TrafficTreatment treatment, 35 TrafficTreatment treatment,
38 Set<Link> links, 36 Set<Link> links,
39 ConnectPoint egressPoint) { 37 ConnectPoint egressPoint) {
40 - super(id, selector, treatment); 38 + super(id(LinkCollectionIntent.class, selector, treatment, links, egressPoint),
39 + appId, resources(links), selector, treatment);
41 this.links = links; 40 this.links = links;
42 this.egressPoint = egressPoint; 41 this.egressPoint = egressPoint;
43 } 42 }
44 43
44 + /**
45 + * Constructor for serializer.
46 + */
45 protected LinkCollectionIntent() { 47 protected LinkCollectionIntent() {
46 super(); 48 super();
47 this.links = null; 49 this.links = null;
48 this.egressPoint = null; 50 this.egressPoint = null;
49 } 51 }
50 52
51 - @Override
52 - public Collection<Link> requiredLinks() {
53 - return links;
54 - }
55 -
56 /** 53 /**
57 * Returns the set of links that represent the network connections needed 54 * Returns the set of links that represent the network connections needed
58 * by this intent. 55 * by this intent.
...@@ -73,34 +70,17 @@ public final class LinkCollectionIntent extends ConnectivityIntent implements In ...@@ -73,34 +70,17 @@ public final class LinkCollectionIntent extends ConnectivityIntent implements In
73 } 70 }
74 71
75 @Override 72 @Override
76 - public boolean equals(Object o) { 73 + public boolean isInstallable() {
77 - if (this == o) { 74 + return true;
78 - return true;
79 - }
80 - if (o == null || getClass() != o.getClass()) {
81 - return false;
82 - }
83 - if (!super.equals(o)) {
84 - return false;
85 - }
86 -
87 - LinkCollectionIntent that = (LinkCollectionIntent) o;
88 -
89 - return Objects.equals(this.links, that.links) &&
90 - Objects.equals(this.egressPoint, that.egressPoint);
91 - }
92 -
93 - @Override
94 - public int hashCode() {
95 - return Objects.hash(super.hashCode(), links, egressPoint);
96 } 75 }
97 76
98 @Override 77 @Override
99 public String toString() { 78 public String toString() {
100 return MoreObjects.toStringHelper(getClass()) 79 return MoreObjects.toStringHelper(getClass())
101 .add("id", id()) 80 .add("id", id())
102 - .add("match", selector()) 81 + .add("appId", appId())
103 - .add("action", treatment()) 82 + .add("selector", selector())
83 + .add("treatment", treatment())
104 .add("links", links()) 84 .add("links", links())
105 .add("egress", egressPoint()) 85 .add("egress", egressPoint())
106 .toString(); 86 .toString();
......
...@@ -2,11 +2,11 @@ package org.onlab.onos.net.intent; ...@@ -2,11 +2,11 @@ package org.onlab.onos.net.intent;
2 2
3 import com.google.common.base.MoreObjects; 3 import com.google.common.base.MoreObjects;
4 import com.google.common.collect.Sets; 4 import com.google.common.collect.Sets;
5 +import org.onlab.onos.ApplicationId;
5 import org.onlab.onos.net.ConnectPoint; 6 import org.onlab.onos.net.ConnectPoint;
6 import org.onlab.onos.net.flow.TrafficSelector; 7 import org.onlab.onos.net.flow.TrafficSelector;
7 import org.onlab.onos.net.flow.TrafficTreatment; 8 import org.onlab.onos.net.flow.TrafficTreatment;
8 9
9 -import java.util.Objects;
10 import java.util.Set; 10 import java.util.Set;
11 11
12 import static com.google.common.base.Preconditions.checkArgument; 12 import static com.google.common.base.Preconditions.checkArgument;
...@@ -22,11 +22,11 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { ...@@ -22,11 +22,11 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
22 22
23 /** 23 /**
24 * Creates a new multi-to-single point connectivity intent for the specified 24 * Creates a new multi-to-single point connectivity intent for the specified
25 - * traffic match and action. 25 + * traffic selector and treatment.
26 * 26 *
27 - * @param id intent identifier 27 + * @param appId application identifier
28 - * @param match traffic match 28 + * @param selector traffic selector
29 - * @param action action 29 + * @param treatment treatment
30 * @param ingressPoints set of ports from which ingress traffic originates 30 * @param ingressPoints set of ports from which ingress traffic originates
31 * @param egressPoint port to which traffic will egress 31 * @param egressPoint port to which traffic will egress
32 * @throws NullPointerException if {@code ingressPoints} or 32 * @throws NullPointerException if {@code ingressPoints} or
...@@ -34,15 +34,16 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { ...@@ -34,15 +34,16 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
34 * @throws IllegalArgumentException if the size of {@code ingressPoints} is 34 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
35 * not more than 1 35 * not more than 1
36 */ 36 */
37 - public MultiPointToSinglePointIntent(IntentId id, TrafficSelector match, 37 + public MultiPointToSinglePointIntent(ApplicationId appId,
38 - TrafficTreatment action, 38 + TrafficSelector selector,
39 + TrafficTreatment treatment,
39 Set<ConnectPoint> ingressPoints, 40 Set<ConnectPoint> ingressPoints,
40 ConnectPoint egressPoint) { 41 ConnectPoint egressPoint) {
41 - super(id, match, action); 42 + super(id(MultiPointToSinglePointIntent.class, selector, treatment,
43 + ingressPoints, egressPoint), appId, null, selector, treatment);
42 44
43 checkNotNull(ingressPoints); 45 checkNotNull(ingressPoints);
44 - checkArgument(!ingressPoints.isEmpty(), 46 + checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
45 - "there should be at least one ingress port");
46 47
47 this.ingressPoints = Sets.newHashSet(ingressPoints); 48 this.ingressPoints = Sets.newHashSet(ingressPoints);
48 this.egressPoint = checkNotNull(egressPoint); 49 this.egressPoint = checkNotNull(egressPoint);
...@@ -77,35 +78,14 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { ...@@ -77,35 +78,14 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
77 } 78 }
78 79
79 @Override 80 @Override
80 - public boolean equals(Object o) {
81 - if (this == o) {
82 - return true;
83 - }
84 - if (o == null || getClass() != o.getClass()) {
85 - return false;
86 - }
87 - if (!super.equals(o)) {
88 - return false;
89 - }
90 -
91 - MultiPointToSinglePointIntent that = (MultiPointToSinglePointIntent) o;
92 - return Objects.equals(this.ingressPoints, that.ingressPoints)
93 - && Objects.equals(this.egressPoint, that.egressPoint);
94 - }
95 -
96 - @Override
97 - public int hashCode() {
98 - return Objects.hash(super.hashCode(), ingressPoints, egressPoint);
99 - }
100 -
101 - @Override
102 public String toString() { 81 public String toString() {
103 return MoreObjects.toStringHelper(getClass()) 82 return MoreObjects.toStringHelper(getClass())
104 .add("id", id()) 83 .add("id", id())
105 - .add("match", selector()) 84 + .add("appId", appId())
106 - .add("action", treatment()) 85 + .add("selector", selector())
107 - .add("ingressPoints", ingressPoints()) 86 + .add("treatment", treatment())
108 - .add("egressPoint", egressPoint()) 87 + .add("ingress", ingressPoints())
88 + .add("egress", egressPoint())
109 .toString(); 89 .toString();
110 } 90 }
111 } 91 }
......
1 -package org.onlab.onos.net.intent;
2 -
3 -import org.onlab.onos.net.ConnectPoint;
4 -
5 -// TODO: consider if this intent should be sub-class of ConnectivityIntent
6 -
7 -/**
8 - * An optical layer Intent for a connectivity from a transponder port to another
9 - * transponder port.
10 - * <p/>
11 - * This class doesn't accepts lambda specifier. This class computes path between
12 - * ports and assign lambda automatically. The lambda can be specified using
13 - * OpticalPathFlow class.
14 - */
15 -public class OpticalConnectivityIntent extends AbstractIntent {
16 - protected ConnectPoint src;
17 - protected ConnectPoint dst;
18 -
19 - /**
20 - * Constructor.
21 - *
22 - * @param id ID for this new Intent object.
23 - * @param src The source transponder port.
24 - * @param dst The destination transponder port.
25 - */
26 - public OpticalConnectivityIntent(IntentId id, ConnectPoint src, ConnectPoint dst) {
27 - super(id);
28 - this.src = src;
29 - this.dst = dst;
30 - }
31 -
32 - /**
33 - * Constructor for serializer.
34 - */
35 - protected OpticalConnectivityIntent() {
36 - super();
37 - this.src = null;
38 - this.dst = null;
39 - }
40 -
41 - /**
42 - * Gets source transponder port.
43 - *
44 - * @return The source transponder port.
45 - */
46 - public ConnectPoint getSrcConnectPoint() {
47 - return src;
48 - }
49 -
50 - /**
51 - * Gets destination transponder port.
52 - *
53 - * @return The source transponder port.
54 - */
55 - public ConnectPoint getDst() {
56 - return dst;
57 - }
58 -}
1 -package org.onlab.onos.net.intent;
2 -
3 -import java.util.Collection;
4 -import java.util.Collections;
5 -import java.util.HashSet;
6 -import java.util.Set;
7 -
8 -import org.onlab.onos.net.ConnectPoint;
9 -import org.onlab.onos.net.flow.TrafficSelector;
10 -
11 -// TODO: consider if this intent should be sub-class of Connectivity intent
12 -/**
13 - * A packet layer Intent for a connectivity from a set of ports to a set of
14 - * ports.
15 - * <p>
16 - * TODO: Design methods to support the ReactiveForwarding and the SDN-IP. <br>
17 - * NOTE: Should this class support modifier methods? Should this object a
18 - * read-only object?
19 - */
20 -public class PacketConnectivityIntent extends AbstractIntent {
21 - protected Set<ConnectPoint> srcConnectPoints;
22 - protected TrafficSelector selector;
23 - protected Set<ConnectPoint> dstConnectPoints;
24 - protected boolean canSetupOpticalFlow;
25 - protected int idleTimeoutValue;
26 - protected int hardTimeoutValue;
27 -
28 - /**
29 - * Creates a connectivity intent for the packet layer.
30 - * <p>
31 - * When the "canSetupOpticalFlow" option is true, this intent will compute
32 - * the packet/optical converged path, decompose it to the OpticalPathFlow
33 - * and the PacketPathFlow objects, and execute the operations to add them
34 - * considering the dependency between the packet and optical layers.
35 - *
36 - * @param id ID for this new Intent object.
37 - * @param srcConnectPoints The set of source switch ports.
38 - * @param match Traffic specifier for this object.
39 - * @param dstConnectPoints The set of destination switch ports.
40 - * @param canSetupOpticalFlow The flag whether this intent can create
41 - * optical flows if needed.
42 - */
43 - public PacketConnectivityIntent(IntentId id,
44 - Collection<ConnectPoint> srcConnectPoints, TrafficSelector match,
45 - Collection<ConnectPoint> dstConnectPoints, boolean canSetupOpticalFlow) {
46 - super(id);
47 - this.srcConnectPoints = new HashSet<ConnectPoint>(srcConnectPoints);
48 - this.selector = match;
49 - this.dstConnectPoints = new HashSet<ConnectPoint>(dstConnectPoints);
50 - this.canSetupOpticalFlow = canSetupOpticalFlow;
51 - this.idleTimeoutValue = 0;
52 - this.hardTimeoutValue = 0;
53 -
54 - // TODO: check consistency between these parameters.
55 - }
56 -
57 - /**
58 - * Constructor for serializer.
59 - */
60 - protected PacketConnectivityIntent() {
61 - super();
62 - this.srcConnectPoints = null;
63 - this.selector = null;
64 - this.dstConnectPoints = null;
65 - this.canSetupOpticalFlow = false;
66 - this.idleTimeoutValue = 0;
67 - this.hardTimeoutValue = 0;
68 - }
69 -
70 - /**
71 - * Gets the set of source switch ports.
72 - *
73 - * @return the set of source switch ports.
74 - */
75 - public Collection<ConnectPoint> getSrcConnectPoints() {
76 - return Collections.unmodifiableCollection(srcConnectPoints);
77 - }
78 -
79 - /**
80 - * Gets the traffic specifier.
81 - *
82 - * @return The traffic specifier.
83 - */
84 - public TrafficSelector getMatch() {
85 - return selector;
86 - }
87 -
88 - /**
89 - * Gets the set of destination switch ports.
90 - *
91 - * @return the set of destination switch ports.
92 - */
93 - public Collection<ConnectPoint> getDstConnectPoints() {
94 - return Collections.unmodifiableCollection(dstConnectPoints);
95 - }
96 -
97 - /**
98 - * Adds the specified port to the set of source ports.
99 - *
100 - * @param port ConnectPoint object to be added
101 - */
102 - public void addSrcConnectPoint(ConnectPoint port) {
103 - // TODO implement it.
104 - }
105 -
106 - /**
107 - * Adds the specified port to the set of destination ports.
108 - *
109 - * @param port ConnectPoint object to be added
110 - */
111 - public void addDstConnectPoint(ConnectPoint port) {
112 - // TODO implement it.
113 - }
114 -
115 - /**
116 - * Removes the specified port from the set of source ports.
117 - *
118 - * @param port ConnectPoint object to be removed
119 - */
120 - public void removeSrcConnectPoint(ConnectPoint port) {
121 - // TODO implement it.
122 - }
123 -
124 - /**
125 - * Removes the specified port from the set of destination ports.
126 - *
127 - * @param port ConnectPoint object to be removed
128 - */
129 - public void removeDstConnectPoint(ConnectPoint port) {
130 - // TODO implement it.
131 - }
132 -
133 - /**
134 - * Sets idle-timeout value.
135 - *
136 - * @param timeout Idle-timeout value (seconds)
137 - */
138 - public void setIdleTimeout(int timeout) {
139 - idleTimeoutValue = timeout;
140 - }
141 -
142 - /**
143 - * Sets hard-timeout value.
144 - *
145 - * @param timeout Hard-timeout value (seconds)
146 - */
147 - public void setHardTimeout(int timeout) {
148 - hardTimeoutValue = timeout;
149 - }
150 -
151 - /**
152 - * Gets idle-timeout value.
153 - *
154 - * @return Idle-timeout value (seconds)
155 - */
156 - public int getIdleTimeout() {
157 - return idleTimeoutValue;
158 - }
159 -
160 - /**
161 - * Gets hard-timeout value.
162 - *
163 - * @return Hard-timeout value (seconds)
164 - */
165 - public int getHardTimeout() {
166 - return hardTimeoutValue;
167 - }
168 -
169 - /**
170 - * Returns whether this intent can create optical flows if needed.
171 - *
172 - * @return whether this intent can create optical flows.
173 - */
174 - public boolean canSetupOpticalFlow() {
175 - return canSetupOpticalFlow;
176 - }
177 -}
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 import com.google.common.base.MoreObjects; 3 import com.google.common.base.MoreObjects;
4 -import org.onlab.onos.net.ConnectPoint; 4 +import org.onlab.onos.ApplicationId;
5 -import org.onlab.onos.net.Link;
6 import org.onlab.onos.net.Path; 5 import org.onlab.onos.net.Path;
7 import org.onlab.onos.net.flow.TrafficSelector; 6 import org.onlab.onos.net.flow.TrafficSelector;
8 import org.onlab.onos.net.flow.TrafficTreatment; 7 import org.onlab.onos.net.flow.TrafficTreatment;
9 8
10 -import java.util.Collection;
11 -import java.util.Objects;
12 -
13 /** 9 /**
14 * Abstraction of explicitly path specified connectivity intent. 10 * Abstraction of explicitly path specified connectivity intent.
15 */ 11 */
16 -public class PathIntent extends PointToPointIntent implements InstallableIntent { 12 +public class PathIntent extends ConnectivityIntent {
17 13
18 private final Path path; 14 private final Path path;
19 15
...@@ -21,21 +17,22 @@ public class PathIntent extends PointToPointIntent implements InstallableIntent ...@@ -21,21 +17,22 @@ public class PathIntent extends PointToPointIntent implements InstallableIntent
21 * Creates a new point-to-point intent with the supplied ingress/egress 17 * Creates a new point-to-point intent with the supplied ingress/egress
22 * ports and using the specified explicit path. 18 * ports and using the specified explicit path.
23 * 19 *
24 - * @param id intent identifier 20 + * @param appId application identifier
25 - * @param match traffic match 21 + * @param selector traffic selector
26 - * @param action action 22 + * @param treatment treatment
27 - * @param ingressPort ingress port 23 + * @param path traversed links
28 - * @param egressPort egress port
29 - * @param path traversed links
30 * @throws NullPointerException {@code path} is null 24 * @throws NullPointerException {@code path} is null
31 */ 25 */
32 - public PathIntent(IntentId id, TrafficSelector match, TrafficTreatment action, 26 + public PathIntent(ApplicationId appId, TrafficSelector selector,
33 - ConnectPoint ingressPort, ConnectPoint egressPort, 27 + TrafficTreatment treatment, Path path) {
34 - Path path) { 28 + super(id(PathIntent.class, selector, treatment, path), appId,
35 - super(id, match, action, ingressPort, egressPort); 29 + resources(path.links()), selector, treatment);
36 this.path = path; 30 this.path = path;
37 } 31 }
38 32
33 + /**
34 + * Constructor for serializer.
35 + */
39 protected PathIntent() { 36 protected PathIntent() {
40 super(); 37 super();
41 this.path = null; 38 this.path = null;
...@@ -51,46 +48,19 @@ public class PathIntent extends PointToPointIntent implements InstallableIntent ...@@ -51,46 +48,19 @@ public class PathIntent extends PointToPointIntent implements InstallableIntent
51 } 48 }
52 49
53 @Override 50 @Override
54 - public boolean equals(Object o) { 51 + public boolean isInstallable() {
55 - if (this == o) {
56 - return true;
57 - }
58 - if (o == null || getClass() != o.getClass()) {
59 - return false;
60 - }
61 - if (!super.equals(o)) {
62 - return false;
63 - }
64 -
65 - PathIntent that = (PathIntent) o;
66 -
67 - if (!path.equals(that.path)) {
68 - return false;
69 - }
70 -
71 return true; 52 return true;
72 } 53 }
73 54
74 @Override 55 @Override
75 - public int hashCode() {
76 - return Objects.hash(super.hashCode(), path);
77 - }
78 -
79 - @Override
80 public String toString() { 56 public String toString() {
81 return MoreObjects.toStringHelper(getClass()) 57 return MoreObjects.toStringHelper(getClass())
82 .add("id", id()) 58 .add("id", id())
83 - .add("match", selector()) 59 + .add("appId", appId())
84 - .add("action", treatment()) 60 + .add("selector", selector())
85 - .add("ingressPort", ingressPoint()) 61 + .add("treatment", treatment())
86 - .add("egressPort", egressPoint())
87 .add("path", path) 62 .add("path", path)
88 .toString(); 63 .toString();
89 } 64 }
90 65
91 - @Override
92 - public Collection<Link> requiredLinks() {
93 - return path.links();
94 - }
95 -
96 } 66 }
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 import com.google.common.base.MoreObjects; 3 import com.google.common.base.MoreObjects;
4 +import org.onlab.onos.ApplicationId;
4 import org.onlab.onos.net.ConnectPoint; 5 import org.onlab.onos.net.ConnectPoint;
5 import org.onlab.onos.net.flow.TrafficSelector; 6 import org.onlab.onos.net.flow.TrafficSelector;
6 import org.onlab.onos.net.flow.TrafficTreatment; 7 import org.onlab.onos.net.flow.TrafficTreatment;
7 8
8 -import java.util.Objects;
9 -
10 import static com.google.common.base.Preconditions.checkNotNull; 9 import static com.google.common.base.Preconditions.checkNotNull;
11 10
12 /** 11 /**
...@@ -21,18 +20,19 @@ public class PointToPointIntent extends ConnectivityIntent { ...@@ -21,18 +20,19 @@ public class PointToPointIntent extends ConnectivityIntent {
21 * Creates a new point-to-point intent with the supplied ingress/egress 20 * Creates a new point-to-point intent with the supplied ingress/egress
22 * ports. 21 * ports.
23 * 22 *
24 - * @param id intent identifier 23 + * @param appId application identifier
25 * @param selector traffic selector 24 * @param selector traffic selector
26 * @param treatment treatment 25 * @param treatment treatment
27 * @param ingressPoint ingress port 26 * @param ingressPoint ingress port
28 * @param egressPoint egress port 27 * @param egressPoint egress port
29 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. 28 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
30 */ 29 */
31 - public PointToPointIntent(IntentId id, TrafficSelector selector, 30 + public PointToPointIntent(ApplicationId appId, TrafficSelector selector,
32 TrafficTreatment treatment, 31 TrafficTreatment treatment,
33 ConnectPoint ingressPoint, 32 ConnectPoint ingressPoint,
34 ConnectPoint egressPoint) { 33 ConnectPoint egressPoint) {
35 - super(id, selector, treatment); 34 + super(id(PointToPointIntent.class, selector, treatment, ingressPoint, egressPoint),
35 + appId, null, selector, treatment);
36 this.ingressPoint = checkNotNull(ingressPoint); 36 this.ingressPoint = checkNotNull(ingressPoint);
37 this.egressPoint = checkNotNull(egressPoint); 37 this.egressPoint = checkNotNull(egressPoint);
38 } 38 }
...@@ -66,35 +66,14 @@ public class PointToPointIntent extends ConnectivityIntent { ...@@ -66,35 +66,14 @@ public class PointToPointIntent extends ConnectivityIntent {
66 } 66 }
67 67
68 @Override 68 @Override
69 - public boolean equals(Object o) {
70 - if (this == o) {
71 - return true;
72 - }
73 - if (o == null || getClass() != o.getClass()) {
74 - return false;
75 - }
76 - if (!super.equals(o)) {
77 - return false;
78 - }
79 -
80 - PointToPointIntent that = (PointToPointIntent) o;
81 - return Objects.equals(this.ingressPoint, that.ingressPoint)
82 - && Objects.equals(this.egressPoint, that.egressPoint);
83 - }
84 -
85 - @Override
86 - public int hashCode() {
87 - return Objects.hash(super.hashCode(), ingressPoint, egressPoint);
88 - }
89 -
90 - @Override
91 public String toString() { 69 public String toString() {
92 return MoreObjects.toStringHelper(getClass()) 70 return MoreObjects.toStringHelper(getClass())
93 .add("id", id()) 71 .add("id", id())
94 - .add("match", selector()) 72 + .add("appId", appId())
95 - .add("action", treatment()) 73 + .add("selector", selector())
96 - .add("ingressPoint", ingressPoint) 74 + .add("treatment", treatment())
97 - .add("egressPoints", egressPoint) 75 + .add("ingress", ingressPoint)
76 + .add("egress", egressPoint)
98 .toString(); 77 .toString();
99 } 78 }
100 79
......
...@@ -2,11 +2,11 @@ package org.onlab.onos.net.intent; ...@@ -2,11 +2,11 @@ package org.onlab.onos.net.intent;
2 2
3 import com.google.common.base.MoreObjects; 3 import com.google.common.base.MoreObjects;
4 import com.google.common.collect.Sets; 4 import com.google.common.collect.Sets;
5 +import org.onlab.onos.ApplicationId;
5 import org.onlab.onos.net.ConnectPoint; 6 import org.onlab.onos.net.ConnectPoint;
6 import org.onlab.onos.net.flow.TrafficSelector; 7 import org.onlab.onos.net.flow.TrafficSelector;
7 import org.onlab.onos.net.flow.TrafficTreatment; 8 import org.onlab.onos.net.flow.TrafficTreatment;
8 9
9 -import java.util.Objects;
10 import java.util.Set; 10 import java.util.Set;
11 11
12 import static com.google.common.base.Preconditions.checkArgument; 12 import static com.google.common.base.Preconditions.checkArgument;
...@@ -23,7 +23,7 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent { ...@@ -23,7 +23,7 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
23 /** 23 /**
24 * Creates a new single-to-multi point connectivity intent. 24 * Creates a new single-to-multi point connectivity intent.
25 * 25 *
26 - * @param id intent identifier 26 + * @param appId application identifier
27 * @param selector traffic selector 27 * @param selector traffic selector
28 * @param treatment treatment 28 * @param treatment treatment
29 * @param ingressPoint port on which traffic will ingress 29 * @param ingressPoint port on which traffic will ingress
...@@ -33,16 +33,15 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent { ...@@ -33,16 +33,15 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
33 * @throws IllegalArgumentException if the size of {@code egressPoints} is 33 * @throws IllegalArgumentException if the size of {@code egressPoints} is
34 * not more than 1 34 * not more than 1
35 */ 35 */
36 - public SinglePointToMultiPointIntent(IntentId id, TrafficSelector selector, 36 + public SinglePointToMultiPointIntent(ApplicationId appId,
37 + TrafficSelector selector,
37 TrafficTreatment treatment, 38 TrafficTreatment treatment,
38 ConnectPoint ingressPoint, 39 ConnectPoint ingressPoint,
39 Set<ConnectPoint> egressPoints) { 40 Set<ConnectPoint> egressPoints) {
40 - super(id, selector, treatment); 41 + super(id(SinglePointToMultiPointIntent.class, selector, treatment,
41 - 42 + ingressPoint, egressPoints), appId, null, selector, treatment);
42 checkNotNull(egressPoints); 43 checkNotNull(egressPoints);
43 - checkArgument(!egressPoints.isEmpty(), 44 + checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
44 - "there should be at least one egress port");
45 -
46 this.ingressPoint = checkNotNull(ingressPoint); 45 this.ingressPoint = checkNotNull(ingressPoint);
47 this.egressPoints = Sets.newHashSet(egressPoints); 46 this.egressPoints = Sets.newHashSet(egressPoints);
48 } 47 }
...@@ -75,35 +74,14 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent { ...@@ -75,35 +74,14 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
75 } 74 }
76 75
77 @Override 76 @Override
78 - public boolean equals(Object o) {
79 - if (this == o) {
80 - return true;
81 - }
82 - if (o == null || getClass() != o.getClass()) {
83 - return false;
84 - }
85 - if (!super.equals(o)) {
86 - return false;
87 - }
88 -
89 - SinglePointToMultiPointIntent that = (SinglePointToMultiPointIntent) o;
90 - return Objects.equals(this.ingressPoint, that.ingressPoint)
91 - && Objects.equals(this.egressPoints, that.egressPoints);
92 - }
93 -
94 - @Override
95 - public int hashCode() {
96 - return Objects.hash(super.hashCode(), ingressPoint, egressPoints);
97 - }
98 -
99 - @Override
100 public String toString() { 77 public String toString() {
101 return MoreObjects.toStringHelper(getClass()) 78 return MoreObjects.toStringHelper(getClass())
102 .add("id", id()) 79 .add("id", id())
103 - .add("match", selector()) 80 + .add("appId", appId())
104 - .add("action", treatment()) 81 + .add("selector", selector())
105 - .add("ingressPoint", ingressPoint) 82 + .add("treatment", treatment())
106 - .add("egressPort", egressPoints) 83 + .add("ingress", ingressPoint)
84 + .add("egress", egressPoints)
107 .toString(); 85 .toString();
108 } 86 }
109 87
......
1 +package org.onlab.onos.net.resource;
2 +
3 +/**
4 + * Representation of allocated bandwidth resource.
5 + */
6 +public interface BandwidthResourceAllocation extends BandwidthResourceRequest {
7 +
8 +}
1 +package org.onlab.onos.net.resource;
2 +
3 +/**
4 + * Representation of a request for bandwidth resource.
5 + */
6 +public interface BandwidthResourceRequest {
7 + /**
8 + * Returns the bandwidth resource.
9 + *
10 + * @return the bandwidth resource
11 + */
12 + Bandwidth bandwidth();
13 +}
...@@ -30,6 +30,7 @@ public final class Lambda extends LinkResource { ...@@ -30,6 +30,7 @@ public final class Lambda extends LinkResource {
30 30
31 /** 31 /**
32 * Returns lambda as an int value. 32 * Returns lambda as an int value.
33 + *
33 * @return lambda as an int value 34 * @return lambda as an int value
34 */ 35 */
35 public int toInt() { 36 public int toInt() {
......
1 +package org.onlab.onos.net.resource;
2 +
3 +/**
4 + * Representation of allocated lambda resource.
5 + */
6 +public interface LambdaResourceAllocation extends LambdaResourceRequest {
7 + /**
8 + * Returns the lambda resource.
9 + *
10 + * @return the lambda resource
11 + */
12 + Lambda lambda();
13 +}
1 +package org.onlab.onos.net.resource;
2 +
3 +/**
4 + * Representation of a request for lambda resource.
5 + */
6 +public interface LambdaResourceRequest {
7 +
8 +}
1 +package org.onlab.onos.net.resource;
2 +
3 +import org.onlab.onos.net.Link;
4 +
5 +/**
6 + * Representation of allocated link resources.
7 + */
8 +public interface LinkResourceAllocations extends LinkResourceRequest {
9 + /**
10 + * Returns allocated resource for the given link.
11 + *
12 + * @param link the target link
13 + * @return allocated resource for the link
14 + */
15 + ResourceAllocation getResourceAllocation(Link link);
16 +}
1 +package org.onlab.onos.net.resource;
2 +
3 +import java.util.Collection;
4 +import java.util.Set;
5 +
6 +import org.onlab.onos.net.Link;
7 +import org.onlab.onos.net.intent.IntentId;
8 +
9 +/**
10 + * Representation of a request for link resource.
11 + */
12 +public interface LinkResourceRequest extends ResourceRequest {
13 +
14 + /**
15 + * Returns the {@link IntentId} associated with the request.
16 + *
17 + * @return the {@link IntentId} associated with the request
18 + */
19 + IntentId intendId();
20 +
21 + /**
22 + * Returns the set of target links.
23 + *
24 + * @return the set of target links
25 + */
26 + Collection<Link> links();
27 +
28 + /**
29 + * Returns the set of resource requests.
30 + *
31 + * @return the set of resource requests
32 + */
33 + Set<ResourceRequest> resources();
34 +}
1 package org.onlab.onos.net.resource; 1 package org.onlab.onos.net.resource;
2 2
3 -import java.util.Map;
4 -
5 import org.onlab.onos.net.Link; 3 import org.onlab.onos.net.Link;
6 import org.onlab.onos.net.intent.IntentId; 4 import org.onlab.onos.net.intent.IntentId;
7 -import org.onlab.onos.net.intent.PathIntent;
8 5
9 /** 6 /**
10 * Service for providing link resource allocation. 7 * Service for providing link resource allocation.
...@@ -12,49 +9,48 @@ import org.onlab.onos.net.intent.PathIntent; ...@@ -12,49 +9,48 @@ import org.onlab.onos.net.intent.PathIntent;
12 public interface LinkResourceService { 9 public interface LinkResourceService {
13 10
14 /** 11 /**
15 - * Allocates resources along the path. 12 + * Requests resources.
16 - * <p>
17 - * Tries to allocate given resources on the links along the path specified
18 - * by the given intent.
19 * 13 *
20 - * @param res resources to be allocated 14 + * @param req resources to be allocated
21 - * @param intent an intent to be used for specifying the path 15 + * @return allocated resources
22 */ 16 */
23 - void allocateResource(LinkResources res, PathIntent intent); 17 + LinkResourceAllocations requestResources(LinkResourceRequest req);
24 18
25 /** 19 /**
26 - * Releases resources along the path. 20 + * Releases resources.
27 * 21 *
28 - * @param intentId an ID for the intent for specifying the path 22 + * @param allocations resources to be released
29 */ 23 */
30 - void releaseResource(IntentId intentId); 24 + void releaseResources(LinkResourceAllocations allocations);
31 25
32 /** 26 /**
33 - * Returns all allocated resources to each link. 27 + * Returns all allocated resources.
34 * 28 *
35 - * @return allocated resources to each link with {@link IntentId} 29 + * @return allocated resources
36 */ 30 */
37 - Map<Link, Map<IntentId, LinkResources>> allocatedResources(); 31 + Iterable<LinkResourceAllocations> getAllocations();
38 32
39 /** 33 /**
40 * Returns all allocated resources to given link. 34 * Returns all allocated resources to given link.
41 * 35 *
42 * @param link a target link 36 * @param link a target link
43 - * @return allocated resources to the target link with {@link IntentId} 37 + * @return allocated resources
44 */ 38 */
45 - Map<IntentId, LinkResources> allocatedResources(Link link); 39 + Iterable<LinkResourceAllocations> getAllocations(Link link);
46 40
47 /** 41 /**
48 - * Returns available resources for each link. 42 + * Returns all IDs of intents using the given link.
49 * 43 *
50 - * @return available resources for each link 44 + * @param link a target link
45 + * @return IDs of intents using the link
51 */ 46 */
52 - Map<Link, LinkResources> availableResources(); 47 + Iterable<IntentId> getIntents(Link link);
53 48
54 /** 49 /**
55 * Returns available resources for given link. 50 * Returns available resources for given link.
51 + *
56 * @param link a target link 52 * @param link a target link
57 * @return available resources for the target link 53 * @return available resources for the target link
58 */ 54 */
59 - LinkResources availableResources(Link link); 55 + ResourceRequest getAvailableResources(Link link);
60 } 56 }
......
1 +package org.onlab.onos.net.resource;
2 +
3 +/**
4 + * Abstraction of allocated resource.
5 + */
6 +public interface ResourceAllocation extends ResourceRequest {
7 +
8 +}
1 +package org.onlab.onos.net.resource;
2 +
3 +/**
4 + * Representation of ID for allocated resource.
5 + */
6 +public interface ResourceId {
7 +
8 +}
1 +package org.onlab.onos.net.resource;
2 +
3 +/**
4 + * Abstraction of resource request.
5 + */
6 +public interface ResourceRequest {
7 +
8 +}
1 +/**
2 + * Services for reserving network resources, e.g.&nbsp;bandwidth, lambdas.
3 + */
4 +package org.onlab.onos.net.resource;
...\ No newline at end of file ...\ No newline at end of file
...@@ -2,6 +2,8 @@ package org.onlab.onos.net.intent; ...@@ -2,6 +2,8 @@ package org.onlab.onos.net.intent;
2 2
3 import java.util.Set; 3 import java.util.Set;
4 4
5 +import org.onlab.onos.ApplicationId;
6 +import org.onlab.onos.TestApplicationId;
5 import org.onlab.onos.net.ConnectPoint; 7 import org.onlab.onos.net.ConnectPoint;
6 import org.onlab.onos.net.DeviceId; 8 import org.onlab.onos.net.DeviceId;
7 import org.onlab.onos.net.PortNumber; 9 import org.onlab.onos.net.PortNumber;
...@@ -15,6 +17,8 @@ import org.onlab.onos.net.flow.TrafficTreatment; ...@@ -15,6 +17,8 @@ import org.onlab.onos.net.flow.TrafficTreatment;
15 */ 17 */
16 public abstract class ConnectivityIntentTest extends IntentTest { 18 public abstract class ConnectivityIntentTest extends IntentTest {
17 19
20 + public static final ApplicationId APPID = new TestApplicationId("foo");
21 +
18 public static final IntentId IID = new IntentId(123); 22 public static final IntentId IID = new IntentId(123);
19 public static final TrafficSelector MATCH = DefaultTrafficSelector.builder().build(); 23 public static final TrafficSelector MATCH = DefaultTrafficSelector.builder().build();
20 public static final TrafficTreatment NOP = DefaultTrafficTreatment.builder().build(); 24 public static final TrafficTreatment NOP = DefaultTrafficTreatment.builder().build();
......
...@@ -18,11 +18,11 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -18,11 +18,11 @@ public class FakeIntentManager implements TestableIntentService {
18 18
19 private final Map<IntentId, Intent> intents = new HashMap<>(); 19 private final Map<IntentId, Intent> intents = new HashMap<>();
20 private final Map<IntentId, IntentState> intentStates = new HashMap<>(); 20 private final Map<IntentId, IntentState> intentStates = new HashMap<>();
21 - private final Map<IntentId, List<InstallableIntent>> installables = new HashMap<>(); 21 + private final Map<IntentId, List<Intent>> installables = new HashMap<>();
22 private final Set<IntentListener> listeners = new HashSet<>(); 22 private final Set<IntentListener> listeners = new HashSet<>();
23 23
24 private final Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> compilers = new HashMap<>(); 24 private final Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> compilers = new HashMap<>();
25 - private final Map<Class<? extends InstallableIntent>, IntentInstaller<? extends InstallableIntent>> installers 25 + private final Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> installers
26 = new HashMap<>(); 26 = new HashMap<>();
27 27
28 private final ExecutorService executor = Executors.newSingleThreadExecutor(); 28 private final ExecutorService executor = Executors.newSingleThreadExecutor();
...@@ -54,7 +54,7 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -54,7 +54,7 @@ public class FakeIntentManager implements TestableIntentService {
54 @Override 54 @Override
55 public void run() { 55 public void run() {
56 try { 56 try {
57 - List<InstallableIntent> installable = getInstallable(intent.id()); 57 + List<Intent> installable = getInstallable(intent.id());
58 executeWithdrawingPhase(intent, installable); 58 executeWithdrawingPhase(intent, installable);
59 } catch (IntentException e) { 59 } catch (IntentException e) {
60 exceptions.add(e); 60 exceptions.add(e);
...@@ -73,7 +73,7 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -73,7 +73,7 @@ public class FakeIntentManager implements TestableIntentService {
73 return compiler; 73 return compiler;
74 } 74 }
75 75
76 - private <T extends InstallableIntent> IntentInstaller<T> getInstaller(T intent) { 76 + private <T extends Intent> IntentInstaller<T> getInstaller(T intent) {
77 @SuppressWarnings("unchecked") 77 @SuppressWarnings("unchecked")
78 IntentInstaller<T> installer = (IntentInstaller<T>) installers.get(intent 78 IntentInstaller<T> installer = (IntentInstaller<T>) installers.get(intent
79 .getClass()); 79 .getClass());
...@@ -87,9 +87,9 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -87,9 +87,9 @@ public class FakeIntentManager implements TestableIntentService {
87 setState(intent, IntentState.COMPILING); 87 setState(intent, IntentState.COMPILING);
88 try { 88 try {
89 // For the fake, we compile using a single level pass 89 // For the fake, we compile using a single level pass
90 - List<InstallableIntent> installable = new ArrayList<>(); 90 + List<Intent> installable = new ArrayList<>();
91 for (Intent compiled : getCompiler(intent).compile(intent)) { 91 for (Intent compiled : getCompiler(intent).compile(intent)) {
92 - installable.add((InstallableIntent) compiled); 92 + installable.add((Intent) compiled);
93 } 93 }
94 executeInstallingPhase(intent, installable); 94 executeInstallingPhase(intent, installable);
95 95
...@@ -100,10 +100,10 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -100,10 +100,10 @@ public class FakeIntentManager implements TestableIntentService {
100 } 100 }
101 101
102 private void executeInstallingPhase(Intent intent, 102 private void executeInstallingPhase(Intent intent,
103 - List<InstallableIntent> installable) { 103 + List<Intent> installable) {
104 setState(intent, IntentState.INSTALLING); 104 setState(intent, IntentState.INSTALLING);
105 try { 105 try {
106 - for (InstallableIntent ii : installable) { 106 + for (Intent ii : installable) {
107 registerSubclassInstallerIfNeeded(ii); 107 registerSubclassInstallerIfNeeded(ii);
108 getInstaller(ii).install(ii); 108 getInstaller(ii).install(ii);
109 } 109 }
...@@ -118,10 +118,10 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -118,10 +118,10 @@ public class FakeIntentManager implements TestableIntentService {
118 } 118 }
119 119
120 private void executeWithdrawingPhase(Intent intent, 120 private void executeWithdrawingPhase(Intent intent,
121 - List<InstallableIntent> installable) { 121 + List<Intent> installable) {
122 setState(intent, IntentState.WITHDRAWING); 122 setState(intent, IntentState.WITHDRAWING);
123 try { 123 try {
124 - for (InstallableIntent ii : installable) { 124 + for (Intent ii : installable) {
125 getInstaller(ii).uninstall(ii); 125 getInstaller(ii).uninstall(ii);
126 } 126 }
127 removeInstallable(intent.id()); 127 removeInstallable(intent.id());
...@@ -139,7 +139,7 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -139,7 +139,7 @@ public class FakeIntentManager implements TestableIntentService {
139 intentStates.put(intent.id(), state); 139 intentStates.put(intent.id(), state);
140 } 140 }
141 141
142 - private void putInstallable(IntentId id, List<InstallableIntent> installable) { 142 + private void putInstallable(IntentId id, List<Intent> installable) {
143 installables.put(id, installable); 143 installables.put(id, installable);
144 } 144 }
145 145
...@@ -147,8 +147,8 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -147,8 +147,8 @@ public class FakeIntentManager implements TestableIntentService {
147 installables.remove(id); 147 installables.remove(id);
148 } 148 }
149 149
150 - private List<InstallableIntent> getInstallable(IntentId id) { 150 + private List<Intent> getInstallable(IntentId id) {
151 - List<InstallableIntent> installable = installables.get(id); 151 + List<Intent> installable = installables.get(id);
152 if (installable != null) { 152 if (installable != null) {
153 return installable; 153 return installable;
154 } else { 154 } else {
...@@ -228,19 +228,19 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -228,19 +228,19 @@ public class FakeIntentManager implements TestableIntentService {
228 } 228 }
229 229
230 @Override 230 @Override
231 - public <T extends InstallableIntent> void registerInstaller(Class<T> cls, 231 + public <T extends Intent> void registerInstaller(Class<T> cls,
232 IntentInstaller<T> installer) { 232 IntentInstaller<T> installer) {
233 installers.put(cls, installer); 233 installers.put(cls, installer);
234 } 234 }
235 235
236 @Override 236 @Override
237 - public <T extends InstallableIntent> void unregisterInstaller(Class<T> cls) { 237 + public <T extends Intent> void unregisterInstaller(Class<T> cls) {
238 installers.remove(cls); 238 installers.remove(cls);
239 } 239 }
240 240
241 @Override 241 @Override
242 - public Map<Class<? extends InstallableIntent>, 242 + public Map<Class<? extends Intent>,
243 - IntentInstaller<? extends InstallableIntent>> getInstallers() { 243 + IntentInstaller<? extends Intent>> getInstallers() {
244 return Collections.unmodifiableMap(installers); 244 return Collections.unmodifiableMap(installers);
245 } 245 }
246 246
...@@ -261,13 +261,13 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -261,13 +261,13 @@ public class FakeIntentManager implements TestableIntentService {
261 } 261 }
262 } 262 }
263 263
264 - private void registerSubclassInstallerIfNeeded(InstallableIntent intent) { 264 + private void registerSubclassInstallerIfNeeded(Intent intent) {
265 if (!installers.containsKey(intent.getClass())) { 265 if (!installers.containsKey(intent.getClass())) {
266 Class<?> cls = intent.getClass(); 266 Class<?> cls = intent.getClass();
267 while (cls != Object.class) { 267 while (cls != Object.class) {
268 - // As long as we're within the InstallableIntent class 268 + // As long as we're within the Intent class
269 // descendants 269 // descendants
270 - if (InstallableIntent.class.isAssignableFrom(cls)) { 270 + if (Intent.class.isAssignableFrom(cls)) {
271 IntentInstaller<?> installer = installers.get(cls); 271 IntentInstaller<?> installer = installers.get(cls);
272 if (installer != null) { 272 if (installer != null) {
273 installers.put(intent.getClass(), installer); 273 installers.put(intent.getClass(), installer);
......
1 -package org.onlab.onos.net.intent;
2 -
3 -/**
4 - * This interface is for generator of IntentId. It is defined only for
5 - * testing purpose to keep type safety on mock creation.
6 - *
7 - * <p>
8 - * {@link #getNewId()} generates a globally unique {@link IntentId} instance
9 - * on each invocation. Application developers should not generate IntentId
10 - * by themselves. Instead use an implementation of this interface.
11 - * </p>
12 - */
13 -public interface IntentIdGenerator extends IdGenerator<IntentId> {
14 -}
...@@ -44,14 +44,8 @@ public class IntentIdTest { ...@@ -44,14 +44,8 @@ public class IntentIdTest {
44 44
45 @Test 45 @Test
46 public void valueOf() { 46 public void valueOf() {
47 - IntentId id = new IntentId(12345);
48 - assertEquals("incorrect valueOf", id, IntentId.valueOf("12345"));
49 - }
50 -
51 - @Test
52 - public void valueOfHex() {
53 IntentId id = new IntentId(0xdeadbeefL); 47 IntentId id = new IntentId(0xdeadbeefL);
54 - assertEquals("incorrect valueOf", id, IntentId.valueOf(id.toString())); 48 + assertEquals("incorrect valueOf", id, IntentId.valueOf(0xdeadbeefL));
55 } 49 }
56 50
57 } 51 }
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 -import static org.junit.Assert.assertEquals; 3 +import org.junit.Test;
4 -import static org.junit.Assert.assertFalse;
5 -import static org.junit.Assert.assertTrue;
6 4
7 import java.util.Arrays; 5 import java.util.Arrays;
8 import java.util.HashSet; 6 import java.util.HashSet;
9 import java.util.Set; 7 import java.util.Set;
10 8
11 -import org.junit.Test; 9 +import static org.junit.Assert.*;
12 10
13 /** 11 /**
14 * Base facilities to test various intent tests. 12 * Base facilities to test various intent tests.
...@@ -33,11 +31,7 @@ public abstract class IntentTest { ...@@ -33,11 +31,7 @@ public abstract class IntentTest {
33 31
34 assertTrue("should be equal", one.equals(like)); 32 assertTrue("should be equal", one.equals(like));
35 assertEquals("incorrect hashCode", one.hashCode(), like.hashCode()); 33 assertEquals("incorrect hashCode", one.hashCode(), like.hashCode());
36 -
37 assertFalse("should not be equal", one.equals(another)); 34 assertFalse("should not be equal", one.equals(another));
38 -
39 - assertFalse("should not be equal", one.equals(null));
40 - assertFalse("should not be equal", one.equals("foo"));
41 } 35 }
42 36
43 @Test 37 @Test
......
...@@ -12,7 +12,7 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { ...@@ -12,7 +12,7 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest {
12 @Test 12 @Test
13 public void basics() { 13 public void basics() {
14 MultiPointToSinglePointIntent intent = createOne(); 14 MultiPointToSinglePointIntent intent = createOne();
15 - assertEquals("incorrect id", IID, intent.id()); 15 + assertEquals("incorrect id", APPID, intent.appId());
16 assertEquals("incorrect match", MATCH, intent.selector()); 16 assertEquals("incorrect match", MATCH, intent.selector());
17 assertEquals("incorrect ingress", PS1, intent.ingressPoints()); 17 assertEquals("incorrect ingress", PS1, intent.ingressPoints());
18 assertEquals("incorrect egress", P2, intent.egressPoint()); 18 assertEquals("incorrect egress", P2, intent.egressPoint());
...@@ -20,11 +20,11 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { ...@@ -20,11 +20,11 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest {
20 20
21 @Override 21 @Override
22 protected MultiPointToSinglePointIntent createOne() { 22 protected MultiPointToSinglePointIntent createOne() {
23 - return new MultiPointToSinglePointIntent(IID, MATCH, NOP, PS1, P2); 23 + return new MultiPointToSinglePointIntent(APPID, MATCH, NOP, PS1, P2);
24 } 24 }
25 25
26 @Override 26 @Override
27 protected MultiPointToSinglePointIntent createAnother() { 27 protected MultiPointToSinglePointIntent createAnother() {
28 - return new MultiPointToSinglePointIntent(IID, MATCH, NOP, PS2, P1); 28 + return new MultiPointToSinglePointIntent(APPID, MATCH, NOP, PS2, P1);
29 } 29 }
30 } 30 }
......
...@@ -16,21 +16,19 @@ public class PathIntentTest extends ConnectivityIntentTest { ...@@ -16,21 +16,19 @@ public class PathIntentTest extends ConnectivityIntentTest {
16 @Test 16 @Test
17 public void basics() { 17 public void basics() {
18 PathIntent intent = createOne(); 18 PathIntent intent = createOne();
19 - assertEquals("incorrect id", IID, intent.id()); 19 + assertEquals("incorrect id", APPID, intent.appId());
20 assertEquals("incorrect match", MATCH, intent.selector()); 20 assertEquals("incorrect match", MATCH, intent.selector());
21 assertEquals("incorrect action", NOP, intent.treatment()); 21 assertEquals("incorrect action", NOP, intent.treatment());
22 - assertEquals("incorrect ingress", P1, intent.ingressPoint());
23 - assertEquals("incorrect egress", P2, intent.egressPoint());
24 assertEquals("incorrect path", PATH1, intent.path()); 22 assertEquals("incorrect path", PATH1, intent.path());
25 } 23 }
26 24
27 @Override 25 @Override
28 protected PathIntent createOne() { 26 protected PathIntent createOne() {
29 - return new PathIntent(IID, MATCH, NOP, P1, P2, PATH1); 27 + return new PathIntent(APPID, MATCH, NOP, PATH1);
30 } 28 }
31 29
32 @Override 30 @Override
33 protected PathIntent createAnother() { 31 protected PathIntent createAnother() {
34 - return new PathIntent(IID, MATCH, NOP, P1, P3, PATH2); 32 + return new PathIntent(APPID, MATCH, NOP, PATH2);
35 } 33 }
36 } 34 }
......
...@@ -12,7 +12,7 @@ public class PointToPointIntentTest extends ConnectivityIntentTest { ...@@ -12,7 +12,7 @@ public class PointToPointIntentTest extends ConnectivityIntentTest {
12 @Test 12 @Test
13 public void basics() { 13 public void basics() {
14 PointToPointIntent intent = createOne(); 14 PointToPointIntent intent = createOne();
15 - assertEquals("incorrect id", IID, intent.id()); 15 + assertEquals("incorrect id", APPID, intent.appId());
16 assertEquals("incorrect match", MATCH, intent.selector()); 16 assertEquals("incorrect match", MATCH, intent.selector());
17 assertEquals("incorrect ingress", P1, intent.ingressPoint()); 17 assertEquals("incorrect ingress", P1, intent.ingressPoint());
18 assertEquals("incorrect egress", P2, intent.egressPoint()); 18 assertEquals("incorrect egress", P2, intent.egressPoint());
...@@ -20,11 +20,11 @@ public class PointToPointIntentTest extends ConnectivityIntentTest { ...@@ -20,11 +20,11 @@ public class PointToPointIntentTest extends ConnectivityIntentTest {
20 20
21 @Override 21 @Override
22 protected PointToPointIntent createOne() { 22 protected PointToPointIntent createOne() {
23 - return new PointToPointIntent(IID, MATCH, NOP, P1, P2); 23 + return new PointToPointIntent(APPID, MATCH, NOP, P1, P2);
24 } 24 }
25 25
26 @Override 26 @Override
27 protected PointToPointIntent createAnother() { 27 protected PointToPointIntent createAnother() {
28 - return new PointToPointIntent(IID, MATCH, NOP, P2, P1); 28 + return new PointToPointIntent(APPID, MATCH, NOP, P2, P1);
29 } 29 }
30 } 30 }
......
...@@ -12,7 +12,7 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest { ...@@ -12,7 +12,7 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest {
12 @Test 12 @Test
13 public void basics() { 13 public void basics() {
14 SinglePointToMultiPointIntent intent = createOne(); 14 SinglePointToMultiPointIntent intent = createOne();
15 - assertEquals("incorrect id", IID, intent.id()); 15 + assertEquals("incorrect id", APPID, intent.appId());
16 assertEquals("incorrect match", MATCH, intent.selector()); 16 assertEquals("incorrect match", MATCH, intent.selector());
17 assertEquals("incorrect ingress", P1, intent.ingressPoint()); 17 assertEquals("incorrect ingress", P1, intent.ingressPoint());
18 assertEquals("incorrect egress", PS2, intent.egressPoints()); 18 assertEquals("incorrect egress", PS2, intent.egressPoints());
...@@ -20,11 +20,11 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest { ...@@ -20,11 +20,11 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest {
20 20
21 @Override 21 @Override
22 protected SinglePointToMultiPointIntent createOne() { 22 protected SinglePointToMultiPointIntent createOne() {
23 - return new SinglePointToMultiPointIntent(IID, MATCH, NOP, P1, PS2); 23 + return new SinglePointToMultiPointIntent(APPID, MATCH, NOP, P1, PS2);
24 } 24 }
25 25
26 @Override 26 @Override
27 protected SinglePointToMultiPointIntent createAnother() { 27 protected SinglePointToMultiPointIntent createAnother() {
28 - return new SinglePointToMultiPointIntent(IID, MATCH, NOP, P2, PS1); 28 + return new SinglePointToMultiPointIntent(APPID, MATCH, NOP, P2, PS1);
29 } 29 }
30 } 30 }
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 -//TODO is this the right package?
3 2
4 -import org.onlab.onos.net.Link; 3 +import org.onlab.onos.TestApplicationId;
5 -
6 -import java.util.Collection;
7 4
8 /** 5 /**
9 * An installable intent used in the unit test. 6 * An installable intent used in the unit test.
10 - *
11 - * FIXME: we don't want to expose this class publicly, but the current Kryo
12 - * serialization mechanism does not allow this class to be private and placed
13 - * on testing directory.
14 */ 7 */
15 -public class TestInstallableIntent extends AbstractIntent implements InstallableIntent { 8 +public class TestInstallableIntent extends Intent {
16 /** 9 /**
17 * Constructs an instance with the specified intent ID. 10 * Constructs an instance with the specified intent ID.
18 * 11 *
19 * @param id intent ID 12 * @param id intent ID
20 */ 13 */
21 public TestInstallableIntent(IntentId id) { 14 public TestInstallableIntent(IntentId id) {
22 - super(id); 15 + super(id, new TestApplicationId("foo"), null);
23 } 16 }
24 17
25 /** 18 /**
...@@ -30,7 +23,8 @@ public class TestInstallableIntent extends AbstractIntent implements Installable ...@@ -30,7 +23,8 @@ public class TestInstallableIntent extends AbstractIntent implements Installable
30 } 23 }
31 24
32 @Override 25 @Override
33 - public Collection<Link> requiredLinks() { 26 + public boolean isInstallable() {
34 - return null; 27 + return true;
35 } 28 }
29 +
36 } 30 }
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 -//TODO is this the right package? 2 +
3 +import org.onlab.onos.TestApplicationId;
3 4
4 /** 5 /**
5 * An intent used in the unit test. 6 * An intent used in the unit test.
6 - *
7 - * FIXME: we don't want to expose this class publicly, but the current Kryo
8 - * serialization mechanism does not allow this class to be private and placed
9 - * on testing directory.
10 */ 7 */
11 -public class TestIntent extends AbstractIntent { 8 +public class TestIntent extends Intent {
12 /** 9 /**
13 * Constructs an instance with the specified intent ID. 10 * Constructs an instance with the specified intent ID.
14 * 11 *
15 * @param id intent ID 12 * @param id intent ID
16 */ 13 */
17 public TestIntent(IntentId id) { 14 public TestIntent(IntentId id) {
18 - super(id); 15 + super(id, new TestApplicationId("foo"), null);
19 } 16 }
20 17
21 /** 18 /**
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 -//TODO is this the right package?
3 2
4 /** 3 /**
5 * An intent used in the unit test. 4 * An intent used in the unit test.
6 - *
7 - * FIXME: we don't want to expose this class publicly, but the current Kryo
8 - * serialization mechanism does not allow this class to be private and placed
9 - * on testing directory.
10 */ 5 */
11 -public class TestSubclassInstallableIntent extends TestInstallableIntent implements InstallableIntent { 6 +public class TestSubclassInstallableIntent extends TestInstallableIntent {
12 /** 7 /**
13 * Constructs an instance with the specified intent ID. 8 * Constructs an instance with the specified intent ID.
14 * 9 *
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 -//TODO is this the right package?
3 2
4 /** 3 /**
5 * An intent used in the unit test. 4 * An intent used in the unit test.
6 - *
7 - * FIXME: we don't want to expose this class publicly, but the current Kryo
8 - * serialization mechanism does not allow this class to be private and placed
9 - * on testing directory.
10 */ 5 */
11 public class TestSubclassIntent extends TestIntent { 6 public class TestSubclassIntent extends TestIntent {
12 /** 7 /**
......
...@@ -27,6 +27,7 @@ public class CoreManager implements CoreService { ...@@ -27,6 +27,7 @@ public class CoreManager implements CoreService {
27 private static Version version = Version.version("1.0.0-SNAPSHOT"); 27 private static Version version = Version.version("1.0.0-SNAPSHOT");
28 28
29 private final Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>(); 29 private final Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>();
30 + private final Map<String, DefaultApplicationId> appIdsByName = new ConcurrentHashMap<>();
30 31
31 // TODO: work in progress 32 // TODO: work in progress
32 33
...@@ -50,9 +51,13 @@ public class CoreManager implements CoreService { ...@@ -50,9 +51,13 @@ public class CoreManager implements CoreService {
50 51
51 @Override 52 @Override
52 public ApplicationId registerApplication(String name) { 53 public ApplicationId registerApplication(String name) {
53 - short id = (short) ID_DISPENSER.getAndIncrement(); 54 + DefaultApplicationId appId = appIdsByName.get(name);
54 - DefaultApplicationId appId = new DefaultApplicationId(id, name); 55 + if (appId == null) {
55 - appIds.put(id, appId); 56 + short id = (short) ID_DISPENSER.getAndIncrement();
57 + appId = new DefaultApplicationId(id, name);
58 + appIds.put(id, appId);
59 + appIdsByName.put(name, appId);
60 + }
56 return appId; 61 return appId;
57 } 62 }
58 63
......
...@@ -104,24 +104,52 @@ public class FlowRuleManager ...@@ -104,24 +104,52 @@ public class FlowRuleManager
104 public void applyFlowRules(FlowRule... flowRules) { 104 public void applyFlowRules(FlowRule... flowRules) {
105 for (int i = 0; i < flowRules.length; i++) { 105 for (int i = 0; i < flowRules.length; i++) {
106 FlowRule f = flowRules[i]; 106 FlowRule f = flowRules[i];
107 - final Device device = deviceService.getDevice(f.deviceId()); 107 + boolean local = store.storeFlowRule(f);
108 - final FlowRuleProvider frp = getProvider(device.providerId()); 108 + if (local) {
109 - store.storeFlowRule(f); 109 + // TODO: aggregate all local rules and push down once?
110 - frp.applyFlowRule(f); 110 + applyFlowRulesToProviders(f);
111 + }
112 + }
113 + }
114 +
115 + private void applyFlowRulesToProviders(FlowRule... flowRules) {
116 + DeviceId did = null;
117 + FlowRuleProvider frp = null;
118 + for (FlowRule f : flowRules) {
119 + if (!f.deviceId().equals(did)) {
120 + did = f.deviceId();
121 + final Device device = deviceService.getDevice(did);
122 + frp = getProvider(device.providerId());
123 + }
124 + if (frp != null) {
125 + frp.applyFlowRule(f);
126 + }
111 } 127 }
112 } 128 }
113 129
114 @Override 130 @Override
115 public void removeFlowRules(FlowRule... flowRules) { 131 public void removeFlowRules(FlowRule... flowRules) {
116 FlowRule f; 132 FlowRule f;
117 - FlowRuleProvider frp;
118 - Device device;
119 for (int i = 0; i < flowRules.length; i++) { 133 for (int i = 0; i < flowRules.length; i++) {
120 f = flowRules[i]; 134 f = flowRules[i];
121 - device = deviceService.getDevice(f.deviceId()); 135 + boolean local = store.deleteFlowRule(f);
122 - store.deleteFlowRule(f); 136 + if (local) {
123 - if (device != null) { 137 + // TODO: aggregate all local rules and push down once?
138 + removeFlowRulesFromProviders(f);
139 + }
140 + }
141 + }
142 +
143 + private void removeFlowRulesFromProviders(FlowRule... flowRules) {
144 + DeviceId did = null;
145 + FlowRuleProvider frp = null;
146 + for (FlowRule f : flowRules) {
147 + if (!f.deviceId().equals(did)) {
148 + did = f.deviceId();
149 + final Device device = deviceService.getDevice(did);
124 frp = getProvider(device.providerId()); 150 frp = getProvider(device.providerId());
151 + }
152 + if (frp != null) {
125 frp.removeFlowRule(f); 153 frp.removeFlowRule(f);
126 } 154 }
127 } 155 }
...@@ -135,8 +163,11 @@ public class FlowRuleManager ...@@ -135,8 +163,11 @@ public class FlowRuleManager
135 163
136 for (FlowRule f : rules) { 164 for (FlowRule f : rules) {
137 store.deleteFlowRule(f); 165 store.deleteFlowRule(f);
166 + // FIXME: only accept request and push to provider on internal event
138 device = deviceService.getDevice(f.deviceId()); 167 device = deviceService.getDevice(f.deviceId());
139 frp = getProvider(device.providerId()); 168 frp = getProvider(device.providerId());
169 + // FIXME: flows removed from store and flows removed from might diverge
170 + // get rid of #removeRulesById?
140 frp.removeRulesById(id, f); 171 frp.removeRulesById(id, f);
141 } 172 }
142 } 173 }
...@@ -352,7 +383,23 @@ public class FlowRuleManager ...@@ -352,7 +383,23 @@ public class FlowRuleManager
352 private class InternalStoreDelegate implements FlowRuleStoreDelegate { 383 private class InternalStoreDelegate implements FlowRuleStoreDelegate {
353 @Override 384 @Override
354 public void notify(FlowRuleEvent event) { 385 public void notify(FlowRuleEvent event) {
355 - eventDispatcher.post(event); 386 + switch (event.type()) {
387 + case RULE_ADD_REQUESTED:
388 + applyFlowRulesToProviders(event.subject());
389 + break;
390 + case RULE_REMOVE_REQUESTED:
391 + removeFlowRulesFromProviders(event.subject());
392 + break;
393 +
394 + case RULE_ADDED:
395 + case RULE_REMOVED:
396 + case RULE_UPDATED:
397 + // only dispatch events related to switch
398 + eventDispatcher.post(event);
399 + break;
400 + default:
401 + break;
402 + }
356 } 403 }
357 } 404 }
358 405
......
1 -package org.onlab.onos.net.intent.impl;
2 -
3 -import org.onlab.onos.net.intent.IdGenerator;
4 -
5 -/**
6 - * Base class of {@link IdGenerator} implementations which use {@link IdBlockAllocator} as
7 - * backend.
8 - *
9 - * @param <T> the type of ID
10 - */
11 -public abstract class AbstractBlockAllocatorBasedIdGenerator<T> implements IdGenerator<T> {
12 - protected final IdBlockAllocator allocator;
13 - protected IdBlock idBlock;
14 -
15 - /**
16 - * Constructs an ID generator which use {@link IdBlockAllocator} as backend.
17 - *
18 - * @param allocator
19 - */
20 - protected AbstractBlockAllocatorBasedIdGenerator(IdBlockAllocator allocator) {
21 - this.allocator = allocator;
22 - this.idBlock = allocator.allocateUniqueIdBlock();
23 - }
24 -
25 - @Override
26 - public synchronized T getNewId() {
27 - try {
28 - return convertFrom(idBlock.getNextId());
29 - } catch (UnavailableIdException e) {
30 - idBlock = allocator.allocateUniqueIdBlock();
31 - return convertFrom(idBlock.getNextId());
32 - }
33 - }
34 -
35 - /**
36 - * Returns an ID instance of {@code T} type from the long value.
37 - *
38 - * @param value original long value
39 - * @return ID instance
40 - */
41 - protected abstract T convertFrom(long value);
42 -}
1 -package org.onlab.onos.net.intent.impl;
2 -
3 -public class DummyIdBlockAllocator implements IdBlockAllocator {
4 - private long blockTop;
5 - private static final long BLOCK_SIZE = 0x1000000L;
6 -
7 - /**
8 - * Returns a block of IDs which are unique and unused.
9 - * Range of IDs is fixed size and is assigned incrementally as this method
10 - * called.
11 - *
12 - * @return an IdBlock containing a set of unique IDs
13 - */
14 - @Override
15 - public IdBlock allocateUniqueIdBlock() {
16 - synchronized (this) {
17 - long blockHead = blockTop;
18 - long blockTail = blockTop + BLOCK_SIZE;
19 -
20 - IdBlock block = new IdBlock(blockHead, BLOCK_SIZE);
21 - blockTop = blockTail;
22 -
23 - return block;
24 - }
25 - }
26 -
27 - @Override
28 - public IdBlock allocateUniqueIdBlock(long range) {
29 - throw new UnsupportedOperationException("Not supported yet");
30 - }
31 -}
...@@ -11,11 +11,9 @@ import org.onlab.onos.net.Path; ...@@ -11,11 +11,9 @@ import org.onlab.onos.net.Path;
11 import org.onlab.onos.net.flow.TrafficSelector; 11 import org.onlab.onos.net.flow.TrafficSelector;
12 import org.onlab.onos.net.host.HostService; 12 import org.onlab.onos.net.host.HostService;
13 import org.onlab.onos.net.intent.HostToHostIntent; 13 import org.onlab.onos.net.intent.HostToHostIntent;
14 -import org.onlab.onos.net.intent.IdGenerator;
15 import org.onlab.onos.net.intent.Intent; 14 import org.onlab.onos.net.intent.Intent;
16 import org.onlab.onos.net.intent.IntentCompiler; 15 import org.onlab.onos.net.intent.IntentCompiler;
17 import org.onlab.onos.net.intent.IntentExtensionService; 16 import org.onlab.onos.net.intent.IntentExtensionService;
18 -import org.onlab.onos.net.intent.IntentId;
19 import org.onlab.onos.net.intent.PathIntent; 17 import org.onlab.onos.net.intent.PathIntent;
20 import org.onlab.onos.net.topology.PathService; 18 import org.onlab.onos.net.topology.PathService;
21 19
...@@ -41,12 +39,8 @@ public class HostToHostIntentCompiler ...@@ -41,12 +39,8 @@ public class HostToHostIntentCompiler
41 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 39 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
42 protected HostService hostService; 40 protected HostService hostService;
43 41
44 - protected IdGenerator<IntentId> intentIdGenerator;
45 -
46 @Activate 42 @Activate
47 public void activate() { 43 public void activate() {
48 - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
49 - intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
50 intentManager.registerCompiler(HostToHostIntent.class, this); 44 intentManager.registerCompiler(HostToHostIntent.class, this);
51 } 45 }
52 46
...@@ -70,13 +64,10 @@ public class HostToHostIntentCompiler ...@@ -70,13 +64,10 @@ public class HostToHostIntentCompiler
70 // Creates a path intent from the specified path and original connectivity intent. 64 // Creates a path intent from the specified path and original connectivity intent.
71 private Intent createPathIntent(Path path, Host src, Host dst, 65 private Intent createPathIntent(Path path, Host src, Host dst,
72 HostToHostIntent intent) { 66 HostToHostIntent intent) {
73 -
74 TrafficSelector selector = builder(intent.selector()) 67 TrafficSelector selector = builder(intent.selector())
75 .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build(); 68 .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
76 - 69 + return new PathIntent(intent.appId(), selector, intent.treatment(),
77 - return new PathIntent(intentIdGenerator.getNewId(), 70 + path);
78 - selector, intent.treatment(),
79 - path.src(), path.dst(), path);
80 } 71 }
81 72
82 private Path getPath(HostId one, HostId two) { 73 private Path getPath(HostId one, HostId two) {
......
1 -package org.onlab.onos.net.intent.impl;
2 -
3 -import static com.google.common.base.Preconditions.checkArgument;
4 -
5 -import java.util.Objects;
6 -import java.util.concurrent.atomic.AtomicLong;
7 -
8 -import com.google.common.base.MoreObjects;
9 -
10 -/**
11 - * A class representing an ID space.
12 - */
13 -public final class IdBlock {
14 - private final long start;
15 - private final long size;
16 -
17 - private final AtomicLong currentId;
18 -
19 - /**
20 - * Constructs a new ID block with the specified size and initial value.
21 - *
22 - * @param start initial value of the block
23 - * @param size size of the block
24 - * @throws IllegalArgumentException if the size is less than or equal to 0
25 - */
26 - public IdBlock(long start, long size) {
27 - checkArgument(size > 0, "size should be more than 0, but %s", size);
28 -
29 - this.start = start;
30 - this.size = size;
31 -
32 - this.currentId = new AtomicLong(start);
33 - }
34 -
35 - // TODO: consider if this method is needed or not
36 - /**
37 - * Returns the initial value.
38 - *
39 - * @return initial value
40 - */
41 - public long getStart() {
42 - return start;
43 - }
44 -
45 - // TODO: consider if this method is needed or not
46 - /**
47 - * Returns the last value.
48 - *
49 - * @return last value
50 - */
51 - public long getEnd() {
52 - return start + size - 1;
53 - }
54 -
55 - /**
56 - * Returns the block size.
57 - *
58 - * @return block size
59 - */
60 - public long getSize() {
61 - return size;
62 - }
63 -
64 - /**
65 - * Returns the next ID in the block.
66 - *
67 - * @return next ID
68 - * @throws UnavailableIdException if there is no available ID in the block.
69 - */
70 - public long getNextId() {
71 - final long id = currentId.getAndIncrement();
72 - if (id > getEnd()) {
73 - throw new UnavailableIdException(String.format(
74 - "used all IDs in allocated space (size: %d, end: %d, current: %d)",
75 - size, getEnd(), id
76 - ));
77 - }
78 -
79 - return id;
80 - }
81 -
82 - // TODO: Do we really need equals and hashCode? Should it contain currentId?
83 - @Override
84 - public boolean equals(Object o) {
85 - if (this == o) {
86 - return true;
87 - }
88 - if (o == null || getClass() != o.getClass()) {
89 - return false;
90 - }
91 -
92 - IdBlock that = (IdBlock) o;
93 - return Objects.equals(this.start, that.start)
94 - && Objects.equals(this.size, that.size)
95 - && Objects.equals(this.currentId.get(), that.currentId.get());
96 - }
97 -
98 - @Override
99 - public int hashCode() {
100 - return Objects.hash(start, size, currentId);
101 - }
102 -
103 - @Override
104 - public String toString() {
105 - return MoreObjects.toStringHelper(getClass())
106 - .add("start", start)
107 - .add("size", size)
108 - .add("currentId", currentId)
109 - .toString();
110 - }
111 -}
1 -package org.onlab.onos.net.intent.impl;
2 -
3 -/**
4 - * An interface that gives unique ID spaces.
5 - */
6 -public interface IdBlockAllocator {
7 - /**
8 - * Allocates a unique Id Block.
9 - *
10 - * @return Id Block.
11 - */
12 - IdBlock allocateUniqueIdBlock();
13 -
14 - /**
15 - * Allocates next unique id and retrieve a new range of ids if needed.
16 - *
17 - * @param range range to use for the identifier
18 - * @return Id Block.
19 - */
20 - IdBlock allocateUniqueIdBlock(long range);
21 -}
1 -package org.onlab.onos.net.intent.impl;
2 -
3 -import org.onlab.onos.net.intent.IntentId;
4 -
5 -/**
6 - * An implementation of {@link org.onlab.onos.net.intent.IdGenerator} of intent ID,
7 - * which uses {@link IdBlockAllocator}.
8 - */
9 -public class IdBlockAllocatorBasedIntentIdGenerator extends AbstractBlockAllocatorBasedIdGenerator<IntentId> {
10 -
11 - /**
12 - * Constructs an intent ID generator, which uses the specified ID block allocator
13 - * to generate a global unique intent ID.
14 - *
15 - * @param allocator the ID block allocator to use for generating intent IDs
16 - */
17 - public IdBlockAllocatorBasedIntentIdGenerator(IdBlockAllocator allocator) {
18 - super(allocator);
19 - }
20 -
21 - @Override
22 - protected IntentId convertFrom(long value) {
23 - return new IntentId(value);
24 - }
25 -}
1 package org.onlab.onos.net.intent.impl; 1 package org.onlab.onos.net.intent.impl;
2 2
3 -import static com.google.common.base.Preconditions.checkNotNull; 3 +import com.google.common.collect.ImmutableList;
4 -import static java.util.concurrent.Executors.newSingleThreadExecutor; 4 +import com.google.common.collect.ImmutableMap;
5 -import static org.onlab.onos.net.intent.IntentState.COMPILING; 5 +import com.google.common.collect.Lists;
6 -import static org.onlab.onos.net.intent.IntentState.FAILED;
7 -import static org.onlab.onos.net.intent.IntentState.INSTALLED;
8 -import static org.onlab.onos.net.intent.IntentState.INSTALLING;
9 -import static org.onlab.onos.net.intent.IntentState.RECOMPILING;
10 -import static org.onlab.onos.net.intent.IntentState.WITHDRAWING;
11 -import static org.onlab.onos.net.intent.IntentState.WITHDRAWN;
12 -import static org.onlab.util.Tools.namedThreads;
13 -import static org.slf4j.LoggerFactory.getLogger;
14 -
15 -import java.util.ArrayList;
16 -import java.util.Iterator;
17 -import java.util.List;
18 -import java.util.Map;
19 -import java.util.Objects;
20 -import java.util.concurrent.ConcurrentHashMap;
21 -import java.util.concurrent.ConcurrentMap;
22 -import java.util.concurrent.ExecutionException;
23 -import java.util.concurrent.ExecutorService;
24 -import java.util.concurrent.Future;
25 -import java.util.concurrent.TimeUnit;
26 -import java.util.concurrent.TimeoutException;
27 -
28 import org.apache.felix.scr.annotations.Activate; 6 import org.apache.felix.scr.annotations.Activate;
29 import org.apache.felix.scr.annotations.Component; 7 import org.apache.felix.scr.annotations.Component;
30 import org.apache.felix.scr.annotations.Deactivate; 8 import org.apache.felix.scr.annotations.Deactivate;
...@@ -36,7 +14,6 @@ import org.onlab.onos.event.EventDeliveryService; ...@@ -36,7 +14,6 @@ import org.onlab.onos.event.EventDeliveryService;
36 import org.onlab.onos.net.flow.CompletedBatchOperation; 14 import org.onlab.onos.net.flow.CompletedBatchOperation;
37 import org.onlab.onos.net.flow.FlowRuleBatchOperation; 15 import org.onlab.onos.net.flow.FlowRuleBatchOperation;
38 import org.onlab.onos.net.flow.FlowRuleService; 16 import org.onlab.onos.net.flow.FlowRuleService;
39 -import org.onlab.onos.net.intent.InstallableIntent;
40 import org.onlab.onos.net.intent.Intent; 17 import org.onlab.onos.net.intent.Intent;
41 import org.onlab.onos.net.intent.IntentCompiler; 18 import org.onlab.onos.net.intent.IntentCompiler;
42 import org.onlab.onos.net.intent.IntentEvent; 19 import org.onlab.onos.net.intent.IntentEvent;
...@@ -52,9 +29,24 @@ import org.onlab.onos.net.intent.IntentStore; ...@@ -52,9 +29,24 @@ import org.onlab.onos.net.intent.IntentStore;
52 import org.onlab.onos.net.intent.IntentStoreDelegate; 29 import org.onlab.onos.net.intent.IntentStoreDelegate;
53 import org.slf4j.Logger; 30 import org.slf4j.Logger;
54 31
55 -import com.google.common.collect.ImmutableList; 32 +import java.util.ArrayList;
56 -import com.google.common.collect.ImmutableMap; 33 +import java.util.Iterator;
57 -import com.google.common.collect.Lists; 34 +import java.util.List;
35 +import java.util.Map;
36 +import java.util.Objects;
37 +import java.util.concurrent.ConcurrentHashMap;
38 +import java.util.concurrent.ConcurrentMap;
39 +import java.util.concurrent.ExecutionException;
40 +import java.util.concurrent.ExecutorService;
41 +import java.util.concurrent.Future;
42 +import java.util.concurrent.TimeUnit;
43 +import java.util.concurrent.TimeoutException;
44 +
45 +import static com.google.common.base.Preconditions.checkNotNull;
46 +import static java.util.concurrent.Executors.newSingleThreadExecutor;
47 +import static org.onlab.onos.net.intent.IntentState.*;
48 +import static org.onlab.util.Tools.namedThreads;
49 +import static org.slf4j.LoggerFactory.getLogger;
58 50
59 /** 51 /**
60 * An implementation of Intent Manager. 52 * An implementation of Intent Manager.
...@@ -71,8 +63,8 @@ public class IntentManager ...@@ -71,8 +63,8 @@ public class IntentManager
71 // Collections for compiler, installer, and listener are ONOS instance local 63 // Collections for compiler, installer, and listener are ONOS instance local
72 private final ConcurrentMap<Class<? extends Intent>, 64 private final ConcurrentMap<Class<? extends Intent>,
73 IntentCompiler<? extends Intent>> compilers = new ConcurrentHashMap<>(); 65 IntentCompiler<? extends Intent>> compilers = new ConcurrentHashMap<>();
74 - private final ConcurrentMap<Class<? extends InstallableIntent>, 66 + private final ConcurrentMap<Class<? extends Intent>,
75 - IntentInstaller<? extends InstallableIntent>> installers = new ConcurrentHashMap<>(); 67 + IntentInstaller<? extends Intent>> installers = new ConcurrentHashMap<>();
76 68
77 private final AbstractListenerRegistry<IntentEvent, IntentListener> 69 private final AbstractListenerRegistry<IntentEvent, IntentListener>
78 listenerRegistry = new AbstractListenerRegistry<>(); 70 listenerRegistry = new AbstractListenerRegistry<>();
...@@ -186,17 +178,17 @@ public class IntentManager ...@@ -186,17 +178,17 @@ public class IntentManager
186 } 178 }
187 179
188 @Override 180 @Override
189 - public <T extends InstallableIntent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) { 181 + public <T extends Intent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) {
190 installers.put(cls, installer); 182 installers.put(cls, installer);
191 } 183 }
192 184
193 @Override 185 @Override
194 - public <T extends InstallableIntent> void unregisterInstaller(Class<T> cls) { 186 + public <T extends Intent> void unregisterInstaller(Class<T> cls) {
195 installers.remove(cls); 187 installers.remove(cls);
196 } 188 }
197 189
198 @Override 190 @Override
199 - public Map<Class<? extends InstallableIntent>, IntentInstaller<? extends InstallableIntent>> getInstallers() { 191 + public Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> getInstallers() {
200 return ImmutableMap.copyOf(installers); 192 return ImmutableMap.copyOf(installers);
201 } 193 }
202 194
...@@ -223,7 +215,7 @@ public class IntentManager ...@@ -223,7 +215,7 @@ public class IntentManager
223 * @param <T> the type of installable intent 215 * @param <T> the type of installable intent
224 * @return intent installer corresponding to the specified installable intent 216 * @return intent installer corresponding to the specified installable intent
225 */ 217 */
226 - private <T extends InstallableIntent> IntentInstaller<T> getInstaller(T intent) { 218 + private <T extends Intent> IntentInstaller<T> getInstaller(T intent) {
227 @SuppressWarnings("unchecked") 219 @SuppressWarnings("unchecked")
228 IntentInstaller<T> installer = (IntentInstaller<T>) installers.get(intent.getClass()); 220 IntentInstaller<T> installer = (IntentInstaller<T>) installers.get(intent.getClass());
229 if (installer == null) { 221 if (installer == null) {
...@@ -243,7 +235,7 @@ public class IntentManager ...@@ -243,7 +235,7 @@ public class IntentManager
243 235
244 try { 236 try {
245 // Compile the intent into installable derivatives. 237 // Compile the intent into installable derivatives.
246 - List<InstallableIntent> installable = compileIntent(intent); 238 + List<Intent> installable = compileIntent(intent);
247 239
248 // If all went well, associate the resulting list of installable 240 // If all went well, associate the resulting list of installable
249 // intents with the top-level intent and proceed to install. 241 // intents with the top-level intent and proceed to install.
...@@ -264,12 +256,12 @@ public class IntentManager ...@@ -264,12 +256,12 @@ public class IntentManager
264 * @param intent intent 256 * @param intent intent
265 * @return result of compilation 257 * @return result of compilation
266 */ 258 */
267 - private List<InstallableIntent> compileIntent(Intent intent) { 259 + private List<Intent> compileIntent(Intent intent) {
268 - if (intent instanceof InstallableIntent) { 260 + if (intent.isInstallable()) {
269 - return ImmutableList.of((InstallableIntent) intent); 261 + return ImmutableList.of(intent);
270 } 262 }
271 263
272 - List<InstallableIntent> installable = new ArrayList<>(); 264 + List<Intent> installable = new ArrayList<>();
273 // TODO do we need to registerSubclassCompiler? 265 // TODO do we need to registerSubclassCompiler?
274 for (Intent compiled : getCompiler(intent).compile(intent)) { 266 for (Intent compiled : getCompiler(intent).compile(intent)) {
275 installable.addAll(compileIntent(compiled)); 267 installable.addAll(compileIntent(compiled));
...@@ -290,12 +282,12 @@ public class IntentManager ...@@ -290,12 +282,12 @@ public class IntentManager
290 282
291 List<FlowRuleBatchOperation> installWork = Lists.newArrayList(); 283 List<FlowRuleBatchOperation> installWork = Lists.newArrayList();
292 try { 284 try {
293 - List<InstallableIntent> installables = store.getInstallableIntents(intent.id()); 285 + List<Intent> installables = store.getInstallableIntents(intent.id());
294 if (installables != null) { 286 if (installables != null) {
295 - for (InstallableIntent installable : installables) { 287 + for (Intent installable : installables) {
296 registerSubclassInstallerIfNeeded(installable); 288 registerSubclassInstallerIfNeeded(installable);
297 trackerService.addTrackedResources(intent.id(), 289 trackerService.addTrackedResources(intent.id(),
298 - installable.requiredLinks()); 290 + installable.resources());
299 List<FlowRuleBatchOperation> batch = getInstaller(installable).install(installable); 291 List<FlowRuleBatchOperation> batch = getInstaller(installable).install(installable);
300 installWork.addAll(batch); 292 installWork.addAll(batch);
301 } 293 }
...@@ -324,14 +316,13 @@ public class IntentManager ...@@ -324,14 +316,13 @@ public class IntentManager
324 316
325 try { 317 try {
326 // Compile the intent into installable derivatives. 318 // Compile the intent into installable derivatives.
327 - List<InstallableIntent> installable = compileIntent(intent); 319 + List<Intent> installable = compileIntent(intent);
328 320
329 // If all went well, compare the existing list of installable 321 // If all went well, compare the existing list of installable
330 // intents with the newly compiled list. If they are the same, 322 // intents with the newly compiled list. If they are the same,
331 // bail, out since the previous approach was determined not to 323 // bail, out since the previous approach was determined not to
332 // be viable. 324 // be viable.
333 - List<InstallableIntent> originalInstallable = 325 + List<Intent> originalInstallable = store.getInstallableIntents(intent.id());
334 - store.getInstallableIntents(intent.id());
335 326
336 if (Objects.equals(originalInstallable, installable)) { 327 if (Objects.equals(originalInstallable, installable)) {
337 eventDispatcher.post(store.setState(intent, FAILED)); 328 eventDispatcher.post(store.setState(intent, FAILED));
...@@ -376,9 +367,9 @@ public class IntentManager ...@@ -376,9 +367,9 @@ public class IntentManager
376 private void uninstallIntent(Intent intent, IntentState nextState) { 367 private void uninstallIntent(Intent intent, IntentState nextState) {
377 List<FlowRuleBatchOperation> uninstallWork = Lists.newArrayList(); 368 List<FlowRuleBatchOperation> uninstallWork = Lists.newArrayList();
378 try { 369 try {
379 - List<InstallableIntent> installables = store.getInstallableIntents(intent.id()); 370 + List<Intent> installables = store.getInstallableIntents(intent.id());
380 if (installables != null) { 371 if (installables != null) {
381 - for (InstallableIntent installable : installables) { 372 + for (Intent installable : installables) {
382 List<FlowRuleBatchOperation> batches = getInstaller(installable).uninstall(installable); 373 List<FlowRuleBatchOperation> batches = getInstaller(installable).uninstall(installable);
383 uninstallWork.addAll(batches); 374 uninstallWork.addAll(batches);
384 } 375 }
...@@ -422,12 +413,12 @@ public class IntentManager ...@@ -422,12 +413,12 @@ public class IntentManager
422 * 413 *
423 * @param intent intent 414 * @param intent intent
424 */ 415 */
425 - private void registerSubclassInstallerIfNeeded(InstallableIntent intent) { 416 + private void registerSubclassInstallerIfNeeded(Intent intent) {
426 if (!installers.containsKey(intent.getClass())) { 417 if (!installers.containsKey(intent.getClass())) {
427 Class<?> cls = intent.getClass(); 418 Class<?> cls = intent.getClass();
428 while (cls != Object.class) { 419 while (cls != Object.class) {
429 - // As long as we're within the InstallableIntent class descendants 420 + // As long as we're within the Intent class descendants
430 - if (InstallableIntent.class.isAssignableFrom(cls)) { 421 + if (Intent.class.isAssignableFrom(cls)) {
431 IntentInstaller<?> installer = installers.get(cls); 422 IntentInstaller<?> installer = installers.get(cls);
432 if (installer != null) { 423 if (installer != null) {
433 installers.put(intent.getClass(), installer); 424 installers.put(intent.getClass(), installer);
...@@ -505,8 +496,8 @@ public class IntentManager ...@@ -505,8 +496,8 @@ public class IntentManager
505 private final IntentState nextState; 496 private final IntentState nextState;
506 497
507 public IntentInstallMonitor(Intent intent, 498 public IntentInstallMonitor(Intent intent,
508 - List<FlowRuleBatchOperation> work, 499 + List<FlowRuleBatchOperation> work,
509 - IntentState nextState) { 500 + IntentState nextState) {
510 this.intent = intent; 501 this.intent = intent;
511 this.work = work; 502 this.work = work;
512 // TODO how many Futures can be outstanding? one? 503 // TODO how many Futures can be outstanding? one?
...@@ -531,9 +522,7 @@ public class IntentManager ...@@ -531,9 +522,7 @@ public class IntentManager
531 } 522 }
532 523
533 /** 524 /**
534 - * Apply a list of FlowRules. 525 + * Applies the next batch.
535 - *
536 - * @param rules rules to apply
537 */ 526 */
538 private Future<CompletedBatchOperation> applyNextBatch() { 527 private Future<CompletedBatchOperation> applyNextBatch() {
539 if (work.isEmpty()) { 528 if (work.isEmpty()) {
......
1 package org.onlab.onos.net.intent.impl; 1 package org.onlab.onos.net.intent.impl;
2 2
3 -import java.util.Arrays;
4 -import java.util.HashSet;
5 -import java.util.List;
6 -import java.util.Set;
7 -
8 import org.apache.felix.scr.annotations.Activate; 3 import org.apache.felix.scr.annotations.Activate;
9 import org.apache.felix.scr.annotations.Component; 4 import org.apache.felix.scr.annotations.Component;
10 import org.apache.felix.scr.annotations.Deactivate; 5 import org.apache.felix.scr.annotations.Deactivate;
...@@ -13,16 +8,19 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -13,16 +8,19 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
13 import org.onlab.onos.net.ConnectPoint; 8 import org.onlab.onos.net.ConnectPoint;
14 import org.onlab.onos.net.Link; 9 import org.onlab.onos.net.Link;
15 import org.onlab.onos.net.Path; 10 import org.onlab.onos.net.Path;
16 -import org.onlab.onos.net.intent.IdGenerator;
17 import org.onlab.onos.net.intent.Intent; 11 import org.onlab.onos.net.intent.Intent;
18 import org.onlab.onos.net.intent.IntentCompiler; 12 import org.onlab.onos.net.intent.IntentCompiler;
19 import org.onlab.onos.net.intent.IntentExtensionService; 13 import org.onlab.onos.net.intent.IntentExtensionService;
20 -import org.onlab.onos.net.intent.IntentId;
21 import org.onlab.onos.net.intent.LinkCollectionIntent; 14 import org.onlab.onos.net.intent.LinkCollectionIntent;
22 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; 15 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
23 import org.onlab.onos.net.intent.PointToPointIntent; 16 import org.onlab.onos.net.intent.PointToPointIntent;
24 import org.onlab.onos.net.topology.PathService; 17 import org.onlab.onos.net.topology.PathService;
25 18
19 +import java.util.Arrays;
20 +import java.util.HashSet;
21 +import java.util.List;
22 +import java.util.Set;
23 +
26 /** 24 /**
27 * An intent compiler for 25 * An intent compiler for
28 * {@link org.onlab.onos.net.intent.MultiPointToSinglePointIntent}. 26 * {@link org.onlab.onos.net.intent.MultiPointToSinglePointIntent}.
...@@ -37,12 +35,8 @@ public class MultiPointToSinglePointIntentCompiler ...@@ -37,12 +35,8 @@ public class MultiPointToSinglePointIntentCompiler
37 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 35 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
38 protected PathService pathService; 36 protected PathService pathService;
39 37
40 - protected IdGenerator<IntentId> intentIdGenerator;
41 -
42 @Activate 38 @Activate
43 public void activate() { 39 public void activate() {
44 - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
45 - intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
46 intentManager.registerCompiler(MultiPointToSinglePointIntent.class, this); 40 intentManager.registerCompiler(MultiPointToSinglePointIntent.class, this);
47 } 41 }
48 42
...@@ -60,9 +54,9 @@ public class MultiPointToSinglePointIntentCompiler ...@@ -60,9 +54,9 @@ public class MultiPointToSinglePointIntentCompiler
60 links.addAll(path.links()); 54 links.addAll(path.links());
61 } 55 }
62 56
63 - Intent result = new LinkCollectionIntent(intentIdGenerator.getNewId(), 57 + Intent result = new LinkCollectionIntent(intent.appId(),
64 - intent.selector(), intent.treatment(), 58 + intent.selector(), intent.treatment(),
65 - links, intent.egressPoint()); 59 + links, intent.egressPoint());
66 return Arrays.asList(result); 60 return Arrays.asList(result);
67 } 61 }
68 62
......
...@@ -11,6 +11,7 @@ import org.apache.felix.scr.annotations.Service; ...@@ -11,6 +11,7 @@ import org.apache.felix.scr.annotations.Service;
11 import org.onlab.onos.event.Event; 11 import org.onlab.onos.event.Event;
12 import org.onlab.onos.net.Link; 12 import org.onlab.onos.net.Link;
13 import org.onlab.onos.net.LinkKey; 13 import org.onlab.onos.net.LinkKey;
14 +import org.onlab.onos.net.NetworkResource;
14 import org.onlab.onos.net.intent.IntentId; 15 import org.onlab.onos.net.intent.IntentId;
15 import org.onlab.onos.net.link.LinkEvent; 16 import org.onlab.onos.net.link.LinkEvent;
16 import org.onlab.onos.net.topology.TopologyEvent; 17 import org.onlab.onos.net.topology.TopologyEvent;
...@@ -27,8 +28,8 @@ import static com.google.common.base.Preconditions.checkArgument; ...@@ -27,8 +28,8 @@ import static com.google.common.base.Preconditions.checkArgument;
27 import static com.google.common.base.Preconditions.checkNotNull; 28 import static com.google.common.base.Preconditions.checkNotNull;
28 import static com.google.common.collect.Multimaps.synchronizedSetMultimap; 29 import static com.google.common.collect.Multimaps.synchronizedSetMultimap;
29 import static java.util.concurrent.Executors.newSingleThreadExecutor; 30 import static java.util.concurrent.Executors.newSingleThreadExecutor;
30 -import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED;
31 import static org.onlab.onos.net.LinkKey.linkKey; 31 import static org.onlab.onos.net.LinkKey.linkKey;
32 +import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED;
32 import static org.onlab.util.Tools.namedThreads; 33 import static org.onlab.util.Tools.namedThreads;
33 import static org.slf4j.LoggerFactory.getLogger; 34 import static org.slf4j.LoggerFactory.getLogger;
34 35
...@@ -81,16 +82,22 @@ public class ObjectiveTracker implements ObjectiveTrackerService { ...@@ -81,16 +82,22 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
81 } 82 }
82 83
83 @Override 84 @Override
84 - public void addTrackedResources(IntentId intentId, Collection<Link> resources) { 85 + public void addTrackedResources(IntentId intentId,
85 - for (Link link : resources) { 86 + Collection<NetworkResource> resources) {
86 - intentsByLink.put(linkKey(link), intentId); 87 + for (NetworkResource resource : resources) {
88 + if (resource instanceof Link) {
89 + intentsByLink.put(linkKey((Link) resource), intentId);
90 + }
87 } 91 }
88 } 92 }
89 93
90 @Override 94 @Override
91 - public void removeTrackedResources(IntentId intentId, Collection<Link> resources) { 95 + public void removeTrackedResources(IntentId intentId,
92 - for (Link link : resources) { 96 + Collection<NetworkResource> resources) {
93 - intentsByLink.remove(linkKey(link), intentId); 97 + for (NetworkResource resource : resources) {
98 + if (resource instanceof Link) {
99 + intentsByLink.remove(linkKey((Link) resource), intentId);
100 + }
94 } 101 }
95 } 102 }
96 103
......
1 package org.onlab.onos.net.intent.impl; 1 package org.onlab.onos.net.intent.impl;
2 2
3 -import org.onlab.onos.net.Link; 3 +import org.onlab.onos.net.NetworkResource;
4 import org.onlab.onos.net.intent.IntentId; 4 import org.onlab.onos.net.intent.IntentId;
5 5
6 import java.util.Collection; 6 import java.util.Collection;
...@@ -28,17 +28,19 @@ public interface ObjectiveTrackerService { ...@@ -28,17 +28,19 @@ public interface ObjectiveTrackerService {
28 /** 28 /**
29 * Adds a path flow to be tracked. 29 * Adds a path flow to be tracked.
30 * 30 *
31 - * @param intentId intent identity on whose behalf the path is being tracked 31 + * @param intentId intent identity on whose behalf the path is being tracked
32 * @param resources resources to track 32 * @param resources resources to track
33 */ 33 */
34 - public void addTrackedResources(IntentId intentId, Collection<Link> resources); 34 + public void addTrackedResources(IntentId intentId,
35 + Collection<NetworkResource> resources);
35 36
36 /** 37 /**
37 * Removes a path flow to be tracked. 38 * Removes a path flow to be tracked.
38 * 39 *
39 - * @param intentId intent identity on whose behalf the path is being tracked 40 + * @param intentId intent identity on whose behalf the path is being tracked
40 * @param resources resources to stop tracking 41 * @param resources resources to stop tracking
41 */ 42 */
42 - public void removeTrackedResources(IntentId intentId, Collection<Link> resources); 43 + public void removeTrackedResources(IntentId intentId,
44 + Collection<NetworkResource> resources);
43 45
44 } 46 }
......
1 package org.onlab.onos.net.intent.impl; 1 package org.onlab.onos.net.intent.impl;
2 2
3 -import java.util.ArrayList;
4 -import java.util.Arrays;
5 -import java.util.List;
6 -import java.util.Set;
7 -
8 import org.apache.felix.scr.annotations.Activate; 3 import org.apache.felix.scr.annotations.Activate;
9 import org.apache.felix.scr.annotations.Component; 4 import org.apache.felix.scr.annotations.Component;
10 import org.apache.felix.scr.annotations.Deactivate; 5 import org.apache.felix.scr.annotations.Deactivate;
...@@ -16,16 +11,19 @@ import org.onlab.onos.net.DefaultPath; ...@@ -16,16 +11,19 @@ import org.onlab.onos.net.DefaultPath;
16 import org.onlab.onos.net.Link; 11 import org.onlab.onos.net.Link;
17 import org.onlab.onos.net.Path; 12 import org.onlab.onos.net.Path;
18 import org.onlab.onos.net.host.HostService; 13 import org.onlab.onos.net.host.HostService;
19 -import org.onlab.onos.net.intent.IdGenerator;
20 import org.onlab.onos.net.intent.Intent; 14 import org.onlab.onos.net.intent.Intent;
21 import org.onlab.onos.net.intent.IntentCompiler; 15 import org.onlab.onos.net.intent.IntentCompiler;
22 import org.onlab.onos.net.intent.IntentExtensionService; 16 import org.onlab.onos.net.intent.IntentExtensionService;
23 -import org.onlab.onos.net.intent.IntentId;
24 import org.onlab.onos.net.intent.PathIntent; 17 import org.onlab.onos.net.intent.PathIntent;
25 import org.onlab.onos.net.intent.PointToPointIntent; 18 import org.onlab.onos.net.intent.PointToPointIntent;
26 import org.onlab.onos.net.provider.ProviderId; 19 import org.onlab.onos.net.provider.ProviderId;
27 import org.onlab.onos.net.topology.PathService; 20 import org.onlab.onos.net.topology.PathService;
28 21
22 +import java.util.ArrayList;
23 +import java.util.Arrays;
24 +import java.util.List;
25 +import java.util.Set;
26 +
29 /** 27 /**
30 * A intent compiler for {@link org.onlab.onos.net.intent.HostToHostIntent}. 28 * A intent compiler for {@link org.onlab.onos.net.intent.HostToHostIntent}.
31 */ 29 */
...@@ -43,12 +41,8 @@ public class PointToPointIntentCompiler ...@@ -43,12 +41,8 @@ public class PointToPointIntentCompiler
43 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 41 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
44 protected HostService hostService; 42 protected HostService hostService;
45 43
46 - protected IdGenerator<IntentId> intentIdGenerator;
47 -
48 @Activate 44 @Activate
49 public void activate() { 45 public void activate() {
50 - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
51 - intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
52 intentManager.registerCompiler(PointToPointIntent.class, this); 46 intentManager.registerCompiler(PointToPointIntent.class, this);
53 } 47 }
54 48
...@@ -67,23 +61,21 @@ public class PointToPointIntentCompiler ...@@ -67,23 +61,21 @@ public class PointToPointIntentCompiler
67 links.add(DefaultEdgeLink.createEdgeLink(intent.egressPoint(), false)); 61 links.add(DefaultEdgeLink.createEdgeLink(intent.egressPoint(), false));
68 62
69 return Arrays.asList(createPathIntent(new DefaultPath(PID, links, path.cost() + 2, 63 return Arrays.asList(createPathIntent(new DefaultPath(PID, links, path.cost() + 2,
70 - path.annotations()), 64 + path.annotations()),
71 - intent)); 65 + intent));
72 } 66 }
73 67
74 /** 68 /**
75 * Creates a path intent from the specified path and original 69 * Creates a path intent from the specified path and original
76 * connectivity intent. 70 * connectivity intent.
77 * 71 *
78 - * @param path path to create an intent for 72 + * @param path path to create an intent for
79 * @param intent original intent 73 * @param intent original intent
80 */ 74 */
81 private Intent createPathIntent(Path path, 75 private Intent createPathIntent(Path path,
82 PointToPointIntent intent) { 76 PointToPointIntent intent) {
83 - 77 + return new PathIntent(intent.appId(),
84 - return new PathIntent(intentIdGenerator.getNewId(), 78 + intent.selector(), intent.treatment(), path);
85 - intent.selector(), intent.treatment(),
86 - path.src(), path.dst(), path);
87 } 79 }
88 80
89 /** 81 /**
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 import org.junit.Test; 3 import org.junit.Test;
4 +import org.onlab.onos.ApplicationId;
5 +import org.onlab.onos.TestApplicationId;
4 import org.onlab.onos.net.HostId; 6 import org.onlab.onos.net.HostId;
5 import org.onlab.onos.net.flow.TrafficSelector; 7 import org.onlab.onos.net.flow.TrafficSelector;
6 import org.onlab.onos.net.flow.TrafficTreatment; 8 import org.onlab.onos.net.flow.TrafficTreatment;
...@@ -16,15 +18,13 @@ import static org.onlab.onos.net.NetTestTools.hid; ...@@ -16,15 +18,13 @@ import static org.onlab.onos.net.NetTestTools.hid;
16 */ 18 */
17 public class TestHostToHostIntent { 19 public class TestHostToHostIntent {
18 20
21 + private static final ApplicationId APPID = new TestApplicationId("foo");
22 +
19 private TrafficSelector selector = new IntentTestsMocks.MockSelector(); 23 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
20 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); 24 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
21 25
22 - private HostToHostIntent makeHostToHost(long id, HostId one, HostId two) { 26 + private HostToHostIntent makeHostToHost(HostId one, HostId two) {
23 - return new HostToHostIntent(new IntentId(id), 27 + return new HostToHostIntent(APPID, one, two, selector, treatment);
24 - one,
25 - two,
26 - selector,
27 - treatment);
28 } 28 }
29 29
30 /** 30 /**
...@@ -36,8 +36,8 @@ public class TestHostToHostIntent { ...@@ -36,8 +36,8 @@ public class TestHostToHostIntent {
36 36
37 HostId one = hid("00:00:00:00:00:01/-1"); 37 HostId one = hid("00:00:00:00:00:01/-1");
38 HostId two = hid("00:00:00:00:00:02/-1"); 38 HostId two = hid("00:00:00:00:00:02/-1");
39 - HostToHostIntent i1 = makeHostToHost(12, one, two); 39 + HostToHostIntent i1 = makeHostToHost(one, two);
40 - HostToHostIntent i2 = makeHostToHost(12, one, two); 40 + HostToHostIntent i2 = makeHostToHost(one, two);
41 41
42 assertThat(i1, is(equalTo(i2))); 42 assertThat(i1, is(equalTo(i2)));
43 } 43 }
...@@ -47,42 +47,39 @@ public class TestHostToHostIntent { ...@@ -47,42 +47,39 @@ public class TestHostToHostIntent {
47 * to different Hosts. These should compare not equal. 47 * to different Hosts. These should compare not equal.
48 */ 48 */
49 @Test 49 @Test
50 - public void testLinksDifferentEquals() { 50 + public void testSameEquals2() {
51 -
52 HostId one = hid("00:00:00:00:00:01/-1"); 51 HostId one = hid("00:00:00:00:00:01/-1");
53 HostId two = hid("00:00:00:00:00:02/-1"); 52 HostId two = hid("00:00:00:00:00:02/-1");
54 - HostToHostIntent i1 = makeHostToHost(12, one, two); 53 + HostToHostIntent i1 = makeHostToHost(one, two);
55 - HostToHostIntent i2 = makeHostToHost(12, two, one); 54 + HostToHostIntent i2 = makeHostToHost(two, one);
56 55
57 - assertThat(i1, is(not(equalTo(i2)))); 56 + assertThat(i1, is(equalTo(i2)));
58 } 57 }
59 58
60 /** 59 /**
61 - * Tests the equals() method where two HostToHostIntents have different 60 + * Tests that the hashCode() values for two equivalent HostToHostIntent
62 - * ids. These should compare not equal. 61 + * objects are the same.
63 */ 62 */
64 -
65 @Test 63 @Test
66 - public void testBaseDifferentEquals() { 64 + public void testHashCodeEquals() {
67 HostId one = hid("00:00:00:00:00:01/-1"); 65 HostId one = hid("00:00:00:00:00:01/-1");
68 HostId two = hid("00:00:00:00:00:02/-1"); 66 HostId two = hid("00:00:00:00:00:02/-1");
69 - HostToHostIntent i1 = makeHostToHost(12, one, two); 67 + HostToHostIntent i1 = makeHostToHost(one, two);
70 - HostToHostIntent i2 = makeHostToHost(11, one, two); 68 + HostToHostIntent i2 = makeHostToHost(one, two);
71 69
72 - assertThat(i1, is(not(equalTo(i2)))); 70 + assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
73 } 71 }
74 72
75 /** 73 /**
76 - * Tests that the hashCode() values for two equivalent HostToHostIntent 74 + * Tests that the hashCode() values for two distinct LinkCollectionIntent
77 - * objects are the same. 75 + * objects are different.
78 */ 76 */
79 -
80 @Test 77 @Test
81 - public void testHashCodeEquals() { 78 + public void testHashCodeEquals2() {
82 HostId one = hid("00:00:00:00:00:01/-1"); 79 HostId one = hid("00:00:00:00:00:01/-1");
83 HostId two = hid("00:00:00:00:00:02/-1"); 80 HostId two = hid("00:00:00:00:00:02/-1");
84 - HostToHostIntent i1 = makeHostToHost(12, one, two); 81 + HostToHostIntent i1 = makeHostToHost(one, two);
85 - HostToHostIntent i2 = makeHostToHost(12, one, two); 82 + HostToHostIntent i2 = makeHostToHost(two, one);
86 83
87 assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); 84 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
88 } 85 }
...@@ -91,13 +88,13 @@ public class TestHostToHostIntent { ...@@ -91,13 +88,13 @@ public class TestHostToHostIntent {
91 * Tests that the hashCode() values for two distinct LinkCollectionIntent 88 * Tests that the hashCode() values for two distinct LinkCollectionIntent
92 * objects are different. 89 * objects are different.
93 */ 90 */
94 -
95 @Test 91 @Test
96 public void testHashCodeDifferent() { 92 public void testHashCodeDifferent() {
97 HostId one = hid("00:00:00:00:00:01/-1"); 93 HostId one = hid("00:00:00:00:00:01/-1");
98 HostId two = hid("00:00:00:00:00:02/-1"); 94 HostId two = hid("00:00:00:00:00:02/-1");
99 - HostToHostIntent i1 = makeHostToHost(12, one, two); 95 + HostId three = hid("00:00:00:00:00:32/-1");
100 - HostToHostIntent i2 = makeHostToHost(112, one, two); 96 + HostToHostIntent i1 = makeHostToHost(one, two);
97 + HostToHostIntent i2 = makeHostToHost(one, three);
101 98
102 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); 99 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
103 } 100 }
......
...@@ -11,6 +11,8 @@ import java.util.Set; ...@@ -11,6 +11,8 @@ import java.util.Set;
11 11
12 import org.junit.Before; 12 import org.junit.Before;
13 import org.junit.Test; 13 import org.junit.Test;
14 +import org.onlab.onos.ApplicationId;
15 +import org.onlab.onos.TestApplicationId;
14 import org.onlab.onos.net.ConnectPoint; 16 import org.onlab.onos.net.ConnectPoint;
15 import org.onlab.onos.net.DeviceId; 17 import org.onlab.onos.net.DeviceId;
16 import org.onlab.onos.net.Link; 18 import org.onlab.onos.net.Link;
...@@ -23,6 +25,8 @@ import org.onlab.onos.net.flow.TrafficTreatment; ...@@ -23,6 +25,8 @@ import org.onlab.onos.net.flow.TrafficTreatment;
23 */ 25 */
24 public class TestLinkCollectionIntent { 26 public class TestLinkCollectionIntent {
25 27
28 + private static final ApplicationId APPID = new TestApplicationId("foo");
29 +
26 private Link link1 = link("dev1", 1, "dev2", 2); 30 private Link link1 = link("dev1", 1, "dev2", 2);
27 private Link link2 = link("dev1", 1, "dev3", 2); 31 private Link link2 = link("dev1", 1, "dev3", 2);
28 private Link link3 = link("dev2", 1, "dev3", 2); 32 private Link link3 = link("dev2", 1, "dev3", 2);
...@@ -38,10 +42,9 @@ public class TestLinkCollectionIntent { ...@@ -38,10 +42,9 @@ public class TestLinkCollectionIntent {
38 private TrafficSelector selector = new IntentTestsMocks.MockSelector(); 42 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
39 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); 43 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
40 44
41 - private LinkCollectionIntent makeLinkCollection(long id, Set<Link> links, 45 + private LinkCollectionIntent makeLinkCollection(Set<Link> links,
42 ConnectPoint egress) { 46 ConnectPoint egress) {
43 - return new LinkCollectionIntent(new IntentId(id), 47 + return new LinkCollectionIntent(APPID, selector, treatment, links, egress);
44 - selector, treatment, links, egress);
45 } 48 }
46 49
47 @Before 50 @Before
...@@ -64,8 +67,8 @@ public class TestLinkCollectionIntent { ...@@ -64,8 +67,8 @@ public class TestLinkCollectionIntent {
64 links2.add(link2); 67 links2.add(link2);
65 links2.add(link1); 68 links2.add(link1);
66 69
67 - LinkCollectionIntent i1 = makeLinkCollection(12, links1, egress1); 70 + LinkCollectionIntent i1 = makeLinkCollection(links1, egress1);
68 - LinkCollectionIntent i2 = makeLinkCollection(12, links2, egress1); 71 + LinkCollectionIntent i2 = makeLinkCollection(links2, egress1);
69 72
70 assertThat(i1, is(equalTo(i2))); 73 assertThat(i1, is(equalTo(i2)));
71 } 74 }
...@@ -82,8 +85,8 @@ public class TestLinkCollectionIntent { ...@@ -82,8 +85,8 @@ public class TestLinkCollectionIntent {
82 links2.add(link3); 85 links2.add(link3);
83 links2.add(link1); 86 links2.add(link1);
84 87
85 - LinkCollectionIntent i1 = makeLinkCollection(12, links1, egress1); 88 + LinkCollectionIntent i1 = makeLinkCollection(links1, egress1);
86 - LinkCollectionIntent i2 = makeLinkCollection(12, links2, egress1); 89 + LinkCollectionIntent i2 = makeLinkCollection(links2, egress1);
87 90
88 assertThat(i1, is(not(equalTo(i2)))); 91 assertThat(i1, is(not(equalTo(i2))));
89 } 92 }
...@@ -102,26 +105,8 @@ public class TestLinkCollectionIntent { ...@@ -102,26 +105,8 @@ public class TestLinkCollectionIntent {
102 links2.add(link2); 105 links2.add(link2);
103 links2.add(link1); 106 links2.add(link1);
104 107
105 - LinkCollectionIntent i1 = makeLinkCollection(12, links1, egress1); 108 + LinkCollectionIntent i1 = makeLinkCollection(links1, egress1);
106 - LinkCollectionIntent i2 = makeLinkCollection(12, links2, egress2); 109 + LinkCollectionIntent i2 = makeLinkCollection(links2, egress2);
107 -
108 - assertThat(i1, is(not(equalTo(i2))));
109 - }
110 -
111 - /**
112 - * Tests the equals() method where two LinkCollectionIntents have different
113 - * ids. These should compare not equal.
114 - */
115 - @Test
116 - public void testBaseDifferentEquals() {
117 - links1.add(link1);
118 - links1.add(link2);
119 -
120 - links2.add(link2);
121 - links2.add(link1);
122 -
123 - LinkCollectionIntent i1 = makeLinkCollection(1, links1, egress1);
124 - LinkCollectionIntent i2 = makeLinkCollection(2, links2, egress1);
125 110
126 assertThat(i1, is(not(equalTo(i2)))); 111 assertThat(i1, is(not(equalTo(i2))));
127 } 112 }
...@@ -140,8 +125,8 @@ public class TestLinkCollectionIntent { ...@@ -140,8 +125,8 @@ public class TestLinkCollectionIntent {
140 links2.add(link2); 125 links2.add(link2);
141 links2.add(link1); 126 links2.add(link1);
142 127
143 - LinkCollectionIntent i1 = makeLinkCollection(1, links1, egress1); 128 + LinkCollectionIntent i1 = makeLinkCollection(links1, egress1);
144 - LinkCollectionIntent i2 = makeLinkCollection(1, links2, egress1); 129 + LinkCollectionIntent i2 = makeLinkCollection(links2, egress1);
145 130
146 assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); 131 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
147 } 132 }
...@@ -158,8 +143,8 @@ public class TestLinkCollectionIntent { ...@@ -158,8 +143,8 @@ public class TestLinkCollectionIntent {
158 links2.add(link1); 143 links2.add(link1);
159 links2.add(link3); 144 links2.add(link3);
160 145
161 - LinkCollectionIntent i1 = makeLinkCollection(1, links1, egress1); 146 + LinkCollectionIntent i1 = makeLinkCollection(links1, egress1);
162 - LinkCollectionIntent i2 = makeLinkCollection(1, links2, egress2); 147 + LinkCollectionIntent i2 = makeLinkCollection(links2, egress2);
163 148
164 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); 149 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
165 } 150 }
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 -import java.util.HashSet;
4 -import java.util.Set;
5 -
6 import org.junit.Before; 3 import org.junit.Before;
7 import org.junit.Test; 4 import org.junit.Test;
5 +import org.onlab.onos.ApplicationId;
6 +import org.onlab.onos.TestApplicationId;
8 import org.onlab.onos.net.ConnectPoint; 7 import org.onlab.onos.net.ConnectPoint;
9 import org.onlab.onos.net.flow.TrafficSelector; 8 import org.onlab.onos.net.flow.TrafficSelector;
10 import org.onlab.onos.net.flow.TrafficTreatment; 9 import org.onlab.onos.net.flow.TrafficTreatment;
11 10
11 +import java.util.HashSet;
12 +import java.util.Set;
13 +
12 import static org.hamcrest.CoreMatchers.not; 14 import static org.hamcrest.CoreMatchers.not;
13 import static org.hamcrest.MatcherAssert.assertThat; 15 import static org.hamcrest.MatcherAssert.assertThat;
14 import static org.hamcrest.Matchers.equalTo; 16 import static org.hamcrest.Matchers.equalTo;
...@@ -20,6 +22,8 @@ import static org.onlab.onos.net.NetTestTools.connectPoint; ...@@ -20,6 +22,8 @@ import static org.onlab.onos.net.NetTestTools.connectPoint;
20 */ 22 */
21 public class TestMultiPointToSinglePointIntent { 23 public class TestMultiPointToSinglePointIntent {
22 24
25 + private static final ApplicationId APPID = new TestApplicationId("foo");
26 +
23 private ConnectPoint point1 = connectPoint("dev1", 1); 27 private ConnectPoint point1 = connectPoint("dev1", 1);
24 private ConnectPoint point2 = connectPoint("dev2", 1); 28 private ConnectPoint point2 = connectPoint("dev2", 1);
25 private ConnectPoint point3 = connectPoint("dev3", 1); 29 private ConnectPoint point3 = connectPoint("dev3", 1);
...@@ -33,19 +37,14 @@ public class TestMultiPointToSinglePointIntent { ...@@ -33,19 +37,14 @@ public class TestMultiPointToSinglePointIntent {
33 /** 37 /**
34 * Creates a MultiPointToSinglePointIntent object. 38 * Creates a MultiPointToSinglePointIntent object.
35 * 39 *
36 - * @param id identifier to use for the new intent
37 * @param ingress set of ingress points 40 * @param ingress set of ingress points
38 - * @param egress egress point 41 + * @param egress egress point
39 * @return MultiPointToSinglePoint intent 42 * @return MultiPointToSinglePoint intent
40 */ 43 */
41 - private MultiPointToSinglePointIntent makeIntent(long id, 44 + private MultiPointToSinglePointIntent makeIntent(Set<ConnectPoint> ingress,
42 - Set<ConnectPoint> ingress, 45 + ConnectPoint egress) {
43 - ConnectPoint egress) { 46 + return new MultiPointToSinglePointIntent(APPID, selector, treatment,
44 - return new MultiPointToSinglePointIntent(new IntentId(id), 47 + ingress, egress);
45 - selector,
46 - treatment,
47 - ingress,
48 - egress);
49 } 48 }
50 49
51 /** 50 /**
...@@ -72,8 +71,8 @@ public class TestMultiPointToSinglePointIntent { ...@@ -72,8 +71,8 @@ public class TestMultiPointToSinglePointIntent {
72 ingress2.add(point3); 71 ingress2.add(point3);
73 ingress2.add(point2); 72 ingress2.add(point2);
74 73
75 - Intent i1 = makeIntent(12, ingress1, point1); 74 + Intent i1 = makeIntent(ingress1, point1);
76 - Intent i2 = makeIntent(12, ingress2, point1); 75 + Intent i2 = makeIntent(ingress2, point1);
77 76
78 assertThat(i1, is(equalTo(i2))); 77 assertThat(i1, is(equalTo(i2)));
79 } 78 }
...@@ -89,23 +88,8 @@ public class TestMultiPointToSinglePointIntent { ...@@ -89,23 +88,8 @@ public class TestMultiPointToSinglePointIntent {
89 ingress2.add(point3); 88 ingress2.add(point3);
90 ingress2.add(point2); 89 ingress2.add(point2);
91 90
92 - Intent i1 = makeIntent(12, ingress1, point1); 91 + Intent i1 = makeIntent(ingress1, point1);
93 - Intent i2 = makeIntent(12, ingress2, point1); 92 + Intent i2 = makeIntent(ingress2, point1);
94 -
95 - assertThat(i1, is(not(equalTo(i2))));
96 - }
97 -
98 - /**
99 - * Tests the equals() method where two MultiPointToSinglePoint have different
100 - * ids. These should compare not equal.
101 - */
102 - @Test
103 - public void testBaseDifferentEquals() {
104 - ingress1.add(point3);
105 - ingress2.add(point3);
106 -
107 - Intent i1 = makeIntent(12, ingress1, point1);
108 - Intent i2 = makeIntent(11, ingress2, point1);
109 93
110 assertThat(i1, is(not(equalTo(i2)))); 94 assertThat(i1, is(not(equalTo(i2))));
111 } 95 }
...@@ -122,8 +106,8 @@ public class TestMultiPointToSinglePointIntent { ...@@ -122,8 +106,8 @@ public class TestMultiPointToSinglePointIntent {
122 ingress2.add(point3); 106 ingress2.add(point3);
123 ingress2.add(point2); 107 ingress2.add(point2);
124 108
125 - Intent i1 = makeIntent(12, ingress1, point1); 109 + Intent i1 = makeIntent(ingress1, point1);
126 - Intent i2 = makeIntent(12, ingress2, point1); 110 + Intent i2 = makeIntent(ingress2, point1);
127 111
128 assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); 112 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
129 } 113 }
...@@ -139,8 +123,8 @@ public class TestMultiPointToSinglePointIntent { ...@@ -139,8 +123,8 @@ public class TestMultiPointToSinglePointIntent {
139 ingress2.add(point3); 123 ingress2.add(point3);
140 ingress2.add(point2); 124 ingress2.add(point2);
141 125
142 - Intent i1 = makeIntent(12, ingress1, point1); 126 + Intent i1 = makeIntent(ingress1, point1);
143 - Intent i2 = makeIntent(12, ingress2, point1); 127 + Intent i2 = makeIntent(ingress2, point1);
144 128
145 129
146 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); 130 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 import org.junit.Test; 3 import org.junit.Test;
4 +import org.onlab.onos.ApplicationId;
5 +import org.onlab.onos.TestApplicationId;
4 import org.onlab.onos.net.ConnectPoint; 6 import org.onlab.onos.net.ConnectPoint;
5 import org.onlab.onos.net.flow.TrafficSelector; 7 import org.onlab.onos.net.flow.TrafficSelector;
6 import org.onlab.onos.net.flow.TrafficTreatment; 8 import org.onlab.onos.net.flow.TrafficTreatment;
7 9
8 import static org.hamcrest.MatcherAssert.assertThat; 10 import static org.hamcrest.MatcherAssert.assertThat;
9 -import static org.hamcrest.Matchers.equalTo; 11 +import static org.hamcrest.Matchers.*;
10 -import static org.hamcrest.Matchers.is;
11 -import static org.hamcrest.Matchers.not;
12 import static org.onlab.onos.net.NetTestTools.connectPoint; 12 import static org.onlab.onos.net.NetTestTools.connectPoint;
13 13
14 /** 14 /**
...@@ -16,20 +16,17 @@ import static org.onlab.onos.net.NetTestTools.connectPoint; ...@@ -16,20 +16,17 @@ import static org.onlab.onos.net.NetTestTools.connectPoint;
16 */ 16 */
17 public class TestPointToPointIntent { 17 public class TestPointToPointIntent {
18 18
19 + private static final ApplicationId APPID = new TestApplicationId("foo");
20 +
19 private TrafficSelector selector = new IntentTestsMocks.MockSelector(); 21 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
20 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); 22 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
21 23
22 private ConnectPoint point1 = connectPoint("dev1", 1); 24 private ConnectPoint point1 = connectPoint("dev1", 1);
23 private ConnectPoint point2 = connectPoint("dev2", 1); 25 private ConnectPoint point2 = connectPoint("dev2", 1);
24 26
25 - private PointToPointIntent makePointToPoint(long id, 27 + private PointToPointIntent makePointToPoint(ConnectPoint ingress,
26 - ConnectPoint ingress,
27 ConnectPoint egress) { 28 ConnectPoint egress) {
28 - return new PointToPointIntent(new IntentId(id), 29 + return new PointToPointIntent(APPID, selector, treatment, ingress, egress);
29 - selector,
30 - treatment,
31 - ingress,
32 - egress);
33 } 30 }
34 31
35 /** 32 /**
...@@ -38,8 +35,8 @@ public class TestPointToPointIntent { ...@@ -38,8 +35,8 @@ public class TestPointToPointIntent {
38 */ 35 */
39 @Test 36 @Test
40 public void testSameEquals() { 37 public void testSameEquals() {
41 - PointToPointIntent i1 = makePointToPoint(12, point1, point2); 38 + PointToPointIntent i1 = makePointToPoint(point1, point2);
42 - PointToPointIntent i2 = makePointToPoint(12, point1, point2); 39 + PointToPointIntent i2 = makePointToPoint(point1, point2);
43 40
44 assertThat(i1, is(equalTo(i2))); 41 assertThat(i1, is(equalTo(i2)));
45 } 42 }
...@@ -50,22 +47,8 @@ public class TestPointToPointIntent { ...@@ -50,22 +47,8 @@ public class TestPointToPointIntent {
50 */ 47 */
51 @Test 48 @Test
52 public void testLinksDifferentEquals() { 49 public void testLinksDifferentEquals() {
53 - 50 + PointToPointIntent i1 = makePointToPoint(point1, point2);
54 - PointToPointIntent i1 = makePointToPoint(12, point1, point2); 51 + PointToPointIntent i2 = makePointToPoint(point2, point1);
55 - PointToPointIntent i2 = makePointToPoint(12, point2, point1);
56 -
57 - assertThat(i1, is(not(equalTo(i2))));
58 - }
59 -
60 - /**
61 - * Tests the equals() method where two HostToHostIntents have different
62 - * ids. These should compare not equal.
63 - */
64 - @Test
65 - public void testBaseDifferentEquals() {
66 - PointToPointIntent i1 = makePointToPoint(12, point1, point2);
67 - PointToPointIntent i2 = makePointToPoint(11, point1, point2);
68 -
69 52
70 assertThat(i1, is(not(equalTo(i2)))); 53 assertThat(i1, is(not(equalTo(i2))));
71 } 54 }
...@@ -76,8 +59,8 @@ public class TestPointToPointIntent { ...@@ -76,8 +59,8 @@ public class TestPointToPointIntent {
76 */ 59 */
77 @Test 60 @Test
78 public void testHashCodeEquals() { 61 public void testHashCodeEquals() {
79 - PointToPointIntent i1 = makePointToPoint(12, point1, point2); 62 + PointToPointIntent i1 = makePointToPoint(point1, point2);
80 - PointToPointIntent i2 = makePointToPoint(12, point1, point2); 63 + PointToPointIntent i2 = makePointToPoint(point1, point2);
81 64
82 assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); 65 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
83 } 66 }
...@@ -88,8 +71,8 @@ public class TestPointToPointIntent { ...@@ -88,8 +71,8 @@ public class TestPointToPointIntent {
88 */ 71 */
89 @Test 72 @Test
90 public void testHashCodeDifferent() { 73 public void testHashCodeDifferent() {
91 - PointToPointIntent i1 = makePointToPoint(12, point1, point2); 74 + PointToPointIntent i1 = makePointToPoint(point1, point2);
92 - PointToPointIntent i2 = makePointToPoint(22, point1, point2); 75 + PointToPointIntent i2 = makePointToPoint(point2, point1);
93 76
94 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); 77 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
95 } 78 }
......
1 package org.onlab.onos.net.intent.impl; 1 package org.onlab.onos.net.intent.impl;
2 2
3 -import java.util.List;
4 -
5 import org.hamcrest.Matchers; 3 import org.hamcrest.Matchers;
6 import org.junit.Before; 4 import org.junit.Before;
7 import org.junit.Test; 5 import org.junit.Test;
6 +import org.onlab.onos.ApplicationId;
7 +import org.onlab.onos.TestApplicationId;
8 import org.onlab.onos.net.Host; 8 import org.onlab.onos.net.Host;
9 import org.onlab.onos.net.HostId; 9 import org.onlab.onos.net.HostId;
10 import org.onlab.onos.net.flow.TrafficSelector; 10 import org.onlab.onos.net.flow.TrafficSelector;
...@@ -12,16 +12,14 @@ import org.onlab.onos.net.flow.TrafficTreatment; ...@@ -12,16 +12,14 @@ import org.onlab.onos.net.flow.TrafficTreatment;
12 import org.onlab.onos.net.host.HostService; 12 import org.onlab.onos.net.host.HostService;
13 import org.onlab.onos.net.intent.HostToHostIntent; 13 import org.onlab.onos.net.intent.HostToHostIntent;
14 import org.onlab.onos.net.intent.Intent; 14 import org.onlab.onos.net.intent.Intent;
15 -import org.onlab.onos.net.intent.IntentId;
16 import org.onlab.onos.net.intent.IntentTestsMocks; 15 import org.onlab.onos.net.intent.IntentTestsMocks;
17 import org.onlab.onos.net.intent.PathIntent; 16 import org.onlab.onos.net.intent.PathIntent;
18 import org.onlab.packet.MacAddress; 17 import org.onlab.packet.MacAddress;
19 import org.onlab.packet.VlanId; 18 import org.onlab.packet.VlanId;
20 19
21 -import static org.easymock.EasyMock.createMock; 20 +import java.util.List;
22 -import static org.easymock.EasyMock.eq; 21 +
23 -import static org.easymock.EasyMock.expect; 22 +import static org.easymock.EasyMock.*;
24 -import static org.easymock.EasyMock.replay;
25 import static org.hamcrest.CoreMatchers.notNullValue; 23 import static org.hamcrest.CoreMatchers.notNullValue;
26 import static org.hamcrest.MatcherAssert.assertThat; 24 import static org.hamcrest.MatcherAssert.assertThat;
27 import static org.hamcrest.Matchers.hasSize; 25 import static org.hamcrest.Matchers.hasSize;
...@@ -40,6 +38,8 @@ public class TestHostToHostIntentCompiler { ...@@ -40,6 +38,8 @@ public class TestHostToHostIntentCompiler {
40 private static final String HOST_ONE = HOST_ONE_MAC + "/" + HOST_ONE_VLAN; 38 private static final String HOST_ONE = HOST_ONE_MAC + "/" + HOST_ONE_VLAN;
41 private static final String HOST_TWO = HOST_TWO_MAC + "/" + HOST_TWO_VLAN; 39 private static final String HOST_TWO = HOST_TWO_MAC + "/" + HOST_TWO_VLAN;
42 40
41 + private static final ApplicationId APPID = new TestApplicationId("foo");
42 +
43 private TrafficSelector selector = new IntentTestsMocks.MockSelector(); 43 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
44 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); 44 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
45 45
...@@ -73,11 +73,8 @@ public class TestHostToHostIntentCompiler { ...@@ -73,11 +73,8 @@ public class TestHostToHostIntentCompiler {
73 * @return HostToHostIntent for the two hosts 73 * @return HostToHostIntent for the two hosts
74 */ 74 */
75 private HostToHostIntent makeIntent(String oneIdString, String twoIdString) { 75 private HostToHostIntent makeIntent(String oneIdString, String twoIdString) {
76 - return new HostToHostIntent(new IntentId(12), 76 + return new HostToHostIntent(APPID, hid(oneIdString), hid(twoIdString),
77 - hid(oneIdString), 77 + selector, treatment);
78 - hid(twoIdString),
79 - selector,
80 - treatment);
81 } 78 }
82 79
83 /** 80 /**
...@@ -91,9 +88,6 @@ public class TestHostToHostIntentCompiler { ...@@ -91,9 +88,6 @@ public class TestHostToHostIntentCompiler {
91 new HostToHostIntentCompiler(); 88 new HostToHostIntentCompiler();
92 compiler.pathService = new IntentTestsMocks.MockPathService(hops); 89 compiler.pathService = new IntentTestsMocks.MockPathService(hops);
93 compiler.hostService = mockHostService; 90 compiler.hostService = mockHostService;
94 - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
95 - compiler.intentIdGenerator =
96 - new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
97 return compiler; 91 return compiler;
98 } 92 }
99 93
......
1 package org.onlab.onos.net.intent.impl; 1 package org.onlab.onos.net.intent.impl;
2 2
3 -import java.util.HashSet;
4 -import java.util.List;
5 -import java.util.Set;
6 -
7 import org.hamcrest.Matchers; 3 import org.hamcrest.Matchers;
8 import org.junit.Test; 4 import org.junit.Test;
5 +import org.onlab.onos.ApplicationId;
6 +import org.onlab.onos.TestApplicationId;
9 import org.onlab.onos.net.ConnectPoint; 7 import org.onlab.onos.net.ConnectPoint;
10 import org.onlab.onos.net.ElementId; 8 import org.onlab.onos.net.ElementId;
11 import org.onlab.onos.net.Path; 9 import org.onlab.onos.net.Path;
12 import org.onlab.onos.net.flow.TrafficSelector; 10 import org.onlab.onos.net.flow.TrafficSelector;
13 import org.onlab.onos.net.flow.TrafficTreatment; 11 import org.onlab.onos.net.flow.TrafficTreatment;
14 import org.onlab.onos.net.intent.Intent; 12 import org.onlab.onos.net.intent.Intent;
15 -import org.onlab.onos.net.intent.IntentId;
16 import org.onlab.onos.net.intent.IntentTestsMocks; 13 import org.onlab.onos.net.intent.IntentTestsMocks;
17 import org.onlab.onos.net.intent.LinkCollectionIntent; 14 import org.onlab.onos.net.intent.LinkCollectionIntent;
18 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; 15 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
19 import org.onlab.onos.net.topology.LinkWeight; 16 import org.onlab.onos.net.topology.LinkWeight;
20 import org.onlab.onos.net.topology.PathService; 17 import org.onlab.onos.net.topology.PathService;
21 18
19 +import java.util.HashSet;
20 +import java.util.List;
21 +import java.util.Set;
22 +
22 import static org.hamcrest.CoreMatchers.notNullValue; 23 import static org.hamcrest.CoreMatchers.notNullValue;
23 import static org.hamcrest.MatcherAssert.assertThat; 24 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.hasSize; 25 import static org.hamcrest.Matchers.hasSize;
...@@ -32,6 +33,8 @@ import static org.onlab.onos.net.intent.LinksHaveEntryWithSourceDestinationPairM ...@@ -32,6 +33,8 @@ import static org.onlab.onos.net.intent.LinksHaveEntryWithSourceDestinationPairM
32 */ 33 */
33 public class TestMultiPointToSinglePointIntentCompiler { 34 public class TestMultiPointToSinglePointIntentCompiler {
34 35
36 + private static final ApplicationId APPID = new TestApplicationId("foo");
37 +
35 private TrafficSelector selector = new IntentTestsMocks.MockSelector(); 38 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
36 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); 39 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
37 40
...@@ -74,7 +77,7 @@ public class TestMultiPointToSinglePointIntentCompiler { ...@@ -74,7 +77,7 @@ public class TestMultiPointToSinglePointIntentCompiler {
74 * and an egress point. 77 * and an egress point.
75 * 78 *
76 * @param ingressIds array of ingress device ids 79 * @param ingressIds array of ingress device ids
77 - * @param egressId device id of the egress point 80 + * @param egressId device id of the egress point
78 * @return MultiPointToSinglePoint intent 81 * @return MultiPointToSinglePoint intent
79 */ 82 */
80 private MultiPointToSinglePointIntent makeIntent(String[] ingressIds, String egressId) { 83 private MultiPointToSinglePointIntent makeIntent(String[] ingressIds, String egressId) {
...@@ -82,15 +85,11 @@ public class TestMultiPointToSinglePointIntentCompiler { ...@@ -82,15 +85,11 @@ public class TestMultiPointToSinglePointIntentCompiler {
82 ConnectPoint egressPoint = connectPoint(egressId, 1); 85 ConnectPoint egressPoint = connectPoint(egressId, 1);
83 86
84 for (String ingressId : ingressIds) { 87 for (String ingressId : ingressIds) {
85 - ingressPoints.add(connectPoint(ingressId, 1)); 88 + ingressPoints.add(connectPoint(ingressId, 1));
86 } 89 }
87 90
88 - return new MultiPointToSinglePointIntent( 91 + return new MultiPointToSinglePointIntent(APPID, selector, treatment,
89 - new IntentId(12), 92 + ingressPoints, egressPoint);
90 - selector,
91 - treatment,
92 - ingressPoints,
93 - egressPoint);
94 } 93 }
95 94
96 /** 95 /**
...@@ -103,9 +102,6 @@ public class TestMultiPointToSinglePointIntentCompiler { ...@@ -103,9 +102,6 @@ public class TestMultiPointToSinglePointIntentCompiler {
103 MultiPointToSinglePointIntentCompiler compiler = 102 MultiPointToSinglePointIntentCompiler compiler =
104 new MultiPointToSinglePointIntentCompiler(); 103 new MultiPointToSinglePointIntentCompiler();
105 compiler.pathService = new MockPathService(hops); 104 compiler.pathService = new MockPathService(hops);
106 - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
107 - compiler.intentIdGenerator =
108 - new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
109 return compiler; 105 return compiler;
110 } 106 }
111 107
...@@ -122,7 +118,7 @@ public class TestMultiPointToSinglePointIntentCompiler { ...@@ -122,7 +118,7 @@ public class TestMultiPointToSinglePointIntentCompiler {
122 assertThat(intent, is(notNullValue())); 118 assertThat(intent, is(notNullValue()));
123 119
124 String[] hops = {"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", 120 String[] hops = {"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8",
125 - egress}; 121 + egress};
126 MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); 122 MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
127 assertThat(compiler, is(notNullValue())); 123 assertThat(compiler, is(notNullValue()));
128 124
...@@ -184,7 +180,7 @@ public class TestMultiPointToSinglePointIntentCompiler { ...@@ -184,7 +180,7 @@ public class TestMultiPointToSinglePointIntentCompiler {
184 @Test 180 @Test
185 public void testMultiIngressCompilation() { 181 public void testMultiIngressCompilation() {
186 String[] ingress = {"i1", "i2", "i3", "i4", "i5", 182 String[] ingress = {"i1", "i2", "i3", "i4", "i5",
187 - "i6", "i7", "i8", "i9", "i10"}; 183 + "i6", "i7", "i8", "i9", "i10"};
188 String egress = "e"; 184 String egress = "e";
189 185
190 MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); 186 MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
......
1 package org.onlab.onos.net.intent.impl; 1 package org.onlab.onos.net.intent.impl;
2 2
3 -import java.util.List;
4 -
5 import org.hamcrest.Matchers; 3 import org.hamcrest.Matchers;
6 import org.junit.Test; 4 import org.junit.Test;
5 +import org.onlab.onos.ApplicationId;
6 +import org.onlab.onos.TestApplicationId;
7 import org.onlab.onos.net.flow.TrafficSelector; 7 import org.onlab.onos.net.flow.TrafficSelector;
8 import org.onlab.onos.net.flow.TrafficTreatment; 8 import org.onlab.onos.net.flow.TrafficTreatment;
9 import org.onlab.onos.net.intent.Intent; 9 import org.onlab.onos.net.intent.Intent;
10 -import org.onlab.onos.net.intent.IntentId;
11 import org.onlab.onos.net.intent.IntentTestsMocks; 10 import org.onlab.onos.net.intent.IntentTestsMocks;
12 import org.onlab.onos.net.intent.PathIntent; 11 import org.onlab.onos.net.intent.PathIntent;
13 import org.onlab.onos.net.intent.PointToPointIntent; 12 import org.onlab.onos.net.intent.PointToPointIntent;
14 13
14 +import java.util.List;
15 +
15 import static org.hamcrest.CoreMatchers.notNullValue; 16 import static org.hamcrest.CoreMatchers.notNullValue;
16 import static org.hamcrest.MatcherAssert.assertThat; 17 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.hamcrest.Matchers.hasSize; 18 import static org.hamcrest.Matchers.hasSize;
...@@ -24,6 +25,8 @@ import static org.onlab.onos.net.intent.LinksHaveEntryWithSourceDestinationPairM ...@@ -24,6 +25,8 @@ import static org.onlab.onos.net.intent.LinksHaveEntryWithSourceDestinationPairM
24 */ 25 */
25 public class TestPointToPointIntentCompiler { 26 public class TestPointToPointIntentCompiler {
26 27
28 + private static final ApplicationId APPID = new TestApplicationId("foo");
29 +
27 private TrafficSelector selector = new IntentTestsMocks.MockSelector(); 30 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
28 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); 31 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
29 32
...@@ -31,14 +34,12 @@ public class TestPointToPointIntentCompiler { ...@@ -31,14 +34,12 @@ public class TestPointToPointIntentCompiler {
31 * Creates a PointToPoint intent based on ingress and egress device Ids. 34 * Creates a PointToPoint intent based on ingress and egress device Ids.
32 * 35 *
33 * @param ingressIdString string for id of ingress device 36 * @param ingressIdString string for id of ingress device
34 - * @param egressIdString string for id of egress device 37 + * @param egressIdString string for id of egress device
35 * @return PointToPointIntent for the two devices 38 * @return PointToPointIntent for the two devices
36 */ 39 */
37 private PointToPointIntent makeIntent(String ingressIdString, 40 private PointToPointIntent makeIntent(String ingressIdString,
38 String egressIdString) { 41 String egressIdString) {
39 - return new PointToPointIntent(new IntentId(12), 42 + return new PointToPointIntent(APPID, selector, treatment,
40 - selector,
41 - treatment,
42 connectPoint(ingressIdString, 1), 43 connectPoint(ingressIdString, 1),
43 connectPoint(egressIdString, 1)); 44 connectPoint(egressIdString, 1));
44 } 45 }
...@@ -53,9 +54,6 @@ public class TestPointToPointIntentCompiler { ...@@ -53,9 +54,6 @@ public class TestPointToPointIntentCompiler {
53 PointToPointIntentCompiler compiler = 54 PointToPointIntentCompiler compiler =
54 new PointToPointIntentCompiler(); 55 new PointToPointIntentCompiler();
55 compiler.pathService = new IntentTestsMocks.MockPathService(hops); 56 compiler.pathService = new IntentTestsMocks.MockPathService(hops);
56 - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
57 - compiler.intentIdGenerator =
58 - new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
59 return compiler; 57 return compiler;
60 } 58 }
61 59
......
...@@ -2,6 +2,7 @@ package org.onlab.onos.store.flow.impl; ...@@ -2,6 +2,7 @@ package org.onlab.onos.store.flow.impl;
2 2
3 import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED; 3 import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
4 import static org.slf4j.LoggerFactory.getLogger; 4 import static org.slf4j.LoggerFactory.getLogger;
5 +import static org.onlab.onos.store.flow.impl.FlowStoreMessageSubjects.*;
5 6
6 import java.io.IOException; 7 import java.io.IOException;
7 import java.util.Collection; 8 import java.util.Collection;
...@@ -30,6 +31,7 @@ import org.onlab.onos.net.flow.StoredFlowEntry; ...@@ -30,6 +31,7 @@ import org.onlab.onos.net.flow.StoredFlowEntry;
30 import org.onlab.onos.store.AbstractStore; 31 import org.onlab.onos.store.AbstractStore;
31 import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; 32 import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService;
32 import org.onlab.onos.store.cluster.messaging.ClusterMessage; 33 import org.onlab.onos.store.cluster.messaging.ClusterMessage;
34 +import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler;
33 import org.onlab.onos.store.cluster.messaging.ClusterMessageResponse; 35 import org.onlab.onos.store.cluster.messaging.ClusterMessageResponse;
34 import org.onlab.onos.store.flow.ReplicaInfo; 36 import org.onlab.onos.store.flow.ReplicaInfo;
35 import org.onlab.onos.store.flow.ReplicaInfoService; 37 import org.onlab.onos.store.flow.ReplicaInfoService;
...@@ -80,10 +82,44 @@ public class DistributedFlowRuleStore ...@@ -80,10 +82,44 @@ public class DistributedFlowRuleStore
80 }; 82 };
81 83
82 // TODO: make this configurable 84 // TODO: make this configurable
83 - private static final long FLOW_RULE_STORE_TIMEOUT_MILLIS = 1000; 85 + private static final long FLOW_RULE_STORE_TIMEOUT_MILLIS = 5000;
84 86
85 @Activate 87 @Activate
86 public void activate() { 88 public void activate() {
89 + clusterCommunicator.addSubscriber(STORE_FLOW_RULE, new ClusterMessageHandler() {
90 +
91 + @Override
92 + public void handle(ClusterMessage message) {
93 + FlowRule rule = SERIALIZER.decode(message.payload());
94 + log.info("received add request for {}", rule);
95 + storeFlowEntryInternal(rule);
96 + // FIXME what to respond.
97 + try {
98 + // FIXME: #respond() not working. responded message is
99 + // handled by this sender node and never goes back.
100 + message.respond(SERIALIZER.encode("ACK"));
101 + } catch (IOException e) {
102 + log.error("Failed to respond back", e);
103 + }
104 + }
105 + });
106 +
107 + clusterCommunicator.addSubscriber(DELETE_FLOW_RULE, new ClusterMessageHandler() {
108 +
109 + @Override
110 + public void handle(ClusterMessage message) {
111 + FlowRule rule = SERIALIZER.decode(message.payload());
112 + log.info("received delete request for {}", rule);
113 + deleteFlowRuleInternal(rule);
114 + // FIXME what to respond.
115 + try {
116 + message.respond(SERIALIZER.encode("ACK"));
117 + } catch (IOException e) {
118 + log.error("Failed to respond back", e);
119 + }
120 +
121 + }
122 + });
87 log.info("Started"); 123 log.info("Started");
88 } 124 }
89 125
...@@ -131,13 +167,14 @@ public class DistributedFlowRuleStore ...@@ -131,13 +167,14 @@ public class DistributedFlowRuleStore
131 } 167 }
132 168
133 @Override 169 @Override
134 - public void storeFlowRule(FlowRule rule) { 170 + public boolean storeFlowRule(FlowRule rule) {
135 ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(rule.deviceId()); 171 ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(rule.deviceId());
136 if (replicaInfo.master().get().equals(clusterService.getLocalNode().id())) { 172 if (replicaInfo.master().get().equals(clusterService.getLocalNode().id())) {
137 - storeFlowEntryInternal(rule); 173 + return storeFlowEntryInternal(rule);
138 - return;
139 } 174 }
140 175
176 + log.warn("Not my flow forwarding to {}", replicaInfo.master().orNull());
177 +
141 ClusterMessage message = new ClusterMessage( 178 ClusterMessage message = new ClusterMessage(
142 clusterService.getLocalNode().id(), 179 clusterService.getLocalNode().id(),
143 FlowStoreMessageSubjects.STORE_FLOW_RULE, 180 FlowStoreMessageSubjects.STORE_FLOW_RULE,
...@@ -150,26 +187,29 @@ public class DistributedFlowRuleStore ...@@ -150,26 +187,29 @@ public class DistributedFlowRuleStore
150 // FIXME: throw a FlowStoreException 187 // FIXME: throw a FlowStoreException
151 throw new RuntimeException(e); 188 throw new RuntimeException(e);
152 } 189 }
190 + return false;
153 } 191 }
154 192
155 - private synchronized void storeFlowEntryInternal(FlowRule flowRule) { 193 + private synchronized boolean storeFlowEntryInternal(FlowRule flowRule) {
156 StoredFlowEntry flowEntry = new DefaultFlowEntry(flowRule); 194 StoredFlowEntry flowEntry = new DefaultFlowEntry(flowRule);
157 DeviceId deviceId = flowRule.deviceId(); 195 DeviceId deviceId = flowRule.deviceId();
158 // write to local copy. 196 // write to local copy.
159 if (!flowEntries.containsEntry(deviceId, flowEntry)) { 197 if (!flowEntries.containsEntry(deviceId, flowEntry)) {
160 flowEntries.put(deviceId, flowEntry); 198 flowEntries.put(deviceId, flowEntry);
161 flowEntriesById.put(flowRule.appId(), flowEntry); 199 flowEntriesById.put(flowRule.appId(), flowEntry);
200 + notifyDelegate(new FlowRuleEvent(Type.RULE_ADD_REQUESTED, flowRule));
201 + return true;
162 } 202 }
163 // write to backup. 203 // write to backup.
164 // TODO: write to a hazelcast map. 204 // TODO: write to a hazelcast map.
205 + return false;
165 } 206 }
166 207
167 @Override 208 @Override
168 - public synchronized void deleteFlowRule(FlowRule rule) { 209 + public synchronized boolean deleteFlowRule(FlowRule rule) {
169 ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(rule.deviceId()); 210 ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(rule.deviceId());
170 if (replicaInfo.master().get().equals(clusterService.getLocalNode().id())) { 211 if (replicaInfo.master().get().equals(clusterService.getLocalNode().id())) {
171 - deleteFlowRuleInternal(rule); 212 + return deleteFlowRuleInternal(rule);
172 - return;
173 } 213 }
174 214
175 ClusterMessage message = new ClusterMessage( 215 ClusterMessage message = new ClusterMessage(
...@@ -184,15 +224,21 @@ public class DistributedFlowRuleStore ...@@ -184,15 +224,21 @@ public class DistributedFlowRuleStore
184 // FIXME: throw a FlowStoreException 224 // FIXME: throw a FlowStoreException
185 throw new RuntimeException(e); 225 throw new RuntimeException(e);
186 } 226 }
227 + return false;
187 } 228 }
188 229
189 - private synchronized void deleteFlowRuleInternal(FlowRule flowRule) { 230 + private synchronized boolean deleteFlowRuleInternal(FlowRule flowRule) {
190 StoredFlowEntry entry = getFlowEntryInternal(flowRule); 231 StoredFlowEntry entry = getFlowEntryInternal(flowRule);
191 if (entry == null) { 232 if (entry == null) {
192 - return; 233 + return false;
193 } 234 }
194 entry.setState(FlowEntryState.PENDING_REMOVE); 235 entry.setState(FlowEntryState.PENDING_REMOVE);
236 +
195 // TODO: also update backup. 237 // TODO: also update backup.
238 +
239 + notifyDelegate(new FlowRuleEvent(Type.RULE_REMOVE_REQUESTED, flowRule));
240 +
241 + return true;
196 } 242 }
197 243
198 @Override 244 @Override
......
1 +package org.onlab.onos.store.intent.impl;
2 +
3 +import com.google.common.collect.ImmutableSet;
4 +import org.apache.felix.scr.annotations.Activate;
5 +import org.apache.felix.scr.annotations.Component;
6 +import org.apache.felix.scr.annotations.Deactivate;
7 +import org.apache.felix.scr.annotations.Service;
8 +import org.onlab.onos.net.intent.Intent;
9 +import org.onlab.onos.net.intent.IntentEvent;
10 +import org.onlab.onos.net.intent.IntentId;
11 +import org.onlab.onos.net.intent.IntentState;
12 +import org.onlab.onos.net.intent.IntentStore;
13 +import org.onlab.onos.net.intent.IntentStoreDelegate;
14 +import org.onlab.onos.store.AbstractStore;
15 +import org.slf4j.Logger;
16 +
17 +import java.util.List;
18 +import java.util.Map;
19 +import java.util.concurrent.ConcurrentHashMap;
20 +
21 +import static org.onlab.onos.net.intent.IntentState.*;
22 +import static org.slf4j.LoggerFactory.getLogger;
23 +
24 +//FIXME: I LIE I AM NOT DISTRIBUTED
25 +@Component(immediate = true)
26 +@Service
27 +public class DistributedIntentStore
28 + extends AbstractStore<IntentEvent, IntentStoreDelegate>
29 + implements IntentStore {
30 +
31 + private final Logger log = getLogger(getClass());
32 + private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>();
33 + private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>();
34 + private final Map<IntentId, List<Intent>> installable = new ConcurrentHashMap<>();
35 +
36 + @Activate
37 + public void activate() {
38 + log.info("Started");
39 + }
40 +
41 + @Deactivate
42 + public void deactivate() {
43 + log.info("Stopped");
44 + }
45 +
46 + @Override
47 + public IntentEvent createIntent(Intent intent) {
48 + intents.put(intent.id(), intent);
49 + return this.setState(intent, IntentState.SUBMITTED);
50 + }
51 +
52 + @Override
53 + public IntentEvent removeIntent(IntentId intentId) {
54 + Intent intent = intents.remove(intentId);
55 + installable.remove(intentId);
56 + IntentEvent event = this.setState(intent, WITHDRAWN);
57 + states.remove(intentId);
58 + return event;
59 + }
60 +
61 + @Override
62 + public long getIntentCount() {
63 + return intents.size();
64 + }
65 +
66 + @Override
67 + public Iterable<Intent> getIntents() {
68 + return ImmutableSet.copyOf(intents.values());
69 + }
70 +
71 + @Override
72 + public Intent getIntent(IntentId intentId) {
73 + return intents.get(intentId);
74 + }
75 +
76 + @Override
77 + public IntentState getIntentState(IntentId id) {
78 + return states.get(id);
79 + }
80 +
81 + @Override
82 + public IntentEvent setState(Intent intent, IntentState state) {
83 + IntentId id = intent.id();
84 + states.put(id, state);
85 + IntentEvent.Type type = (state == SUBMITTED ? IntentEvent.Type.SUBMITTED :
86 + (state == INSTALLED ? IntentEvent.Type.INSTALLED :
87 + (state == FAILED ? IntentEvent.Type.FAILED :
88 + state == WITHDRAWN ? IntentEvent.Type.WITHDRAWN :
89 + null)));
90 + return type == null ? null : new IntentEvent(type, intent);
91 + }
92 +
93 + @Override
94 + public void addInstallableIntents(IntentId intentId, List<Intent> result) {
95 + installable.put(intentId, result);
96 + }
97 +
98 + @Override
99 + public List<Intent> getInstallableIntents(IntentId intentId) {
100 + return installable.get(intentId);
101 + }
102 +
103 + @Override
104 + public void removeInstalledIntents(IntentId intentId) {
105 + installable.remove(intentId);
106 + }
107 +
108 +}
...@@ -8,6 +8,7 @@ import java.util.HashMap; ...@@ -8,6 +8,7 @@ import java.util.HashMap;
8 import org.onlab.onos.cluster.ControllerNode; 8 import org.onlab.onos.cluster.ControllerNode;
9 import org.onlab.onos.cluster.DefaultControllerNode; 9 import org.onlab.onos.cluster.DefaultControllerNode;
10 import org.onlab.onos.cluster.NodeId; 10 import org.onlab.onos.cluster.NodeId;
11 +import org.onlab.onos.cluster.RoleInfo;
11 import org.onlab.onos.mastership.MastershipTerm; 12 import org.onlab.onos.mastership.MastershipTerm;
12 import org.onlab.onos.net.ConnectPoint; 13 import org.onlab.onos.net.ConnectPoint;
13 import org.onlab.onos.net.DefaultAnnotations; 14 import org.onlab.onos.net.DefaultAnnotations;
...@@ -26,7 +27,12 @@ import org.onlab.onos.net.PortNumber; ...@@ -26,7 +27,12 @@ import org.onlab.onos.net.PortNumber;
26 import org.onlab.onos.net.device.DefaultDeviceDescription; 27 import org.onlab.onos.net.device.DefaultDeviceDescription;
27 import org.onlab.onos.net.device.DefaultPortDescription; 28 import org.onlab.onos.net.device.DefaultPortDescription;
28 import org.onlab.onos.net.flow.DefaultFlowRule; 29 import org.onlab.onos.net.flow.DefaultFlowRule;
30 +import org.onlab.onos.net.flow.DefaultTrafficSelector;
31 +import org.onlab.onos.net.flow.DefaultTrafficTreatment;
29 import org.onlab.onos.net.flow.FlowId; 32 import org.onlab.onos.net.flow.FlowId;
33 +import org.onlab.onos.net.flow.criteria.Criteria;
34 +import org.onlab.onos.net.flow.criteria.Criterion;
35 +import org.onlab.onos.net.flow.instructions.Instructions;
30 import org.onlab.onos.net.host.DefaultHostDescription; 36 import org.onlab.onos.net.host.DefaultHostDescription;
31 import org.onlab.onos.net.host.HostDescription; 37 import org.onlab.onos.net.host.HostDescription;
32 import org.onlab.onos.net.link.DefaultLinkDescription; 38 import org.onlab.onos.net.link.DefaultLinkDescription;
...@@ -88,7 +94,22 @@ public final class KryoNamespaces { ...@@ -88,7 +94,22 @@ public final class KryoNamespaces {
88 HostDescription.class, 94 HostDescription.class,
89 DefaultHostDescription.class, 95 DefaultHostDescription.class,
90 DefaultFlowRule.class, 96 DefaultFlowRule.class,
91 - FlowId.class 97 + FlowId.class,
98 + DefaultTrafficSelector.class,
99 + Criteria.PortCriterion.class,
100 + Criteria.EthCriterion.class,
101 + Criteria.EthTypeCriterion.class,
102 + Criteria.IPCriterion.class,
103 + Criteria.IPProtocolCriterion.class,
104 + Criteria.VlanIdCriterion.class,
105 + Criteria.VlanPcpCriterion.class,
106 + Criteria.TcpPortCriterion.class,
107 + Criterion.class,
108 + Criterion.Type.class,
109 + DefaultTrafficTreatment.class,
110 + Instructions.DropInstruction.class,
111 + Instructions.OutputInstruction.class,
112 + RoleInfo.class
92 ) 113 )
93 .register(URI.class, new URISerializer()) 114 .register(URI.class, new URISerializer())
94 .register(NodeId.class, new NodeIdSerializer()) 115 .register(NodeId.class, new NodeIdSerializer())
......
...@@ -3,6 +3,7 @@ package org.onlab.onos.store.serializers; ...@@ -3,6 +3,7 @@ package org.onlab.onos.store.serializers;
3 import static org.junit.Assert.assertEquals; 3 import static org.junit.Assert.assertEquals;
4 import static org.onlab.onos.net.DeviceId.deviceId; 4 import static org.onlab.onos.net.DeviceId.deviceId;
5 import static org.onlab.onos.net.PortNumber.portNumber; 5 import static org.onlab.onos.net.PortNumber.portNumber;
6 +import static java.util.Arrays.asList;
6 7
7 import java.nio.ByteBuffer; 8 import java.nio.ByteBuffer;
8 9
...@@ -11,6 +12,7 @@ import org.junit.Before; ...@@ -11,6 +12,7 @@ import org.junit.Before;
11 import org.junit.BeforeClass; 12 import org.junit.BeforeClass;
12 import org.junit.Test; 13 import org.junit.Test;
13 import org.onlab.onos.cluster.NodeId; 14 import org.onlab.onos.cluster.NodeId;
15 +import org.onlab.onos.cluster.RoleInfo;
14 import org.onlab.onos.mastership.MastershipTerm; 16 import org.onlab.onos.mastership.MastershipTerm;
15 import org.onlab.onos.net.Annotations; 17 import org.onlab.onos.net.Annotations;
16 import org.onlab.onos.net.ConnectPoint; 18 import org.onlab.onos.net.ConnectPoint;
...@@ -198,6 +200,12 @@ public class KryoSerializerTest { ...@@ -198,6 +200,12 @@ public class KryoSerializerTest {
198 } 200 }
199 201
200 @Test 202 @Test
203 + public void testRoleInfo() {
204 + testSerialized(new RoleInfo(new NodeId("master"),
205 + asList(new NodeId("stby1"), new NodeId("stby2"))));
206 + }
207 +
208 + @Test
201 public void testAnnotations() { 209 public void testAnnotations() {
202 // Annotations does not have equals defined, manually test equality 210 // Annotations does not have equals defined, manually test equality
203 final byte[] a1Bytes = serializer.encode(A1); 211 final byte[] a1Bytes = serializer.encode(A1);
......
...@@ -148,8 +148,9 @@ public class SimpleFlowRuleStore ...@@ -148,8 +148,9 @@ public class SimpleFlowRuleStore
148 } 148 }
149 149
150 @Override 150 @Override
151 - public void storeFlowRule(FlowRule rule) { 151 + public boolean storeFlowRule(FlowRule rule) {
152 final boolean added = storeFlowRuleInternal(rule); 152 final boolean added = storeFlowRuleInternal(rule);
153 + return added;
153 } 154 }
154 155
155 private boolean storeFlowRuleInternal(FlowRule rule) { 156 private boolean storeFlowRuleInternal(FlowRule rule) {
...@@ -166,13 +167,14 @@ public class SimpleFlowRuleStore ...@@ -166,13 +167,14 @@ public class SimpleFlowRuleStore
166 } 167 }
167 // new flow rule added 168 // new flow rule added
168 existing.add(f); 169 existing.add(f);
169 - // TODO: notify through delegate about remote event? 170 + // TODO: Should we notify only if it's "remote" event?
171 + //notifyDelegate(new FlowRuleEvent(Type.RULE_ADD_REQUESTED, rule));
170 return true; 172 return true;
171 } 173 }
172 } 174 }
173 175
174 @Override 176 @Override
175 - public void deleteFlowRule(FlowRule rule) { 177 + public boolean deleteFlowRule(FlowRule rule) {
176 178
177 List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id()); 179 List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
178 synchronized (entries) { 180 synchronized (entries) {
...@@ -180,12 +182,15 @@ public class SimpleFlowRuleStore ...@@ -180,12 +182,15 @@ public class SimpleFlowRuleStore
180 if (entry.equals(rule)) { 182 if (entry.equals(rule)) {
181 synchronized (entry) { 183 synchronized (entry) {
182 entry.setState(FlowEntryState.PENDING_REMOVE); 184 entry.setState(FlowEntryState.PENDING_REMOVE);
183 - return; 185 + // TODO: Should we notify only if it's "remote" event?
186 + //notifyDelegate(new FlowRuleEvent(Type.RULE_REMOVE_REQUESTED, rule));
187 + return true;
184 } 188 }
185 } 189 }
186 } 190 }
187 } 191 }
188 //log.warn("Cannot find rule {}", rule); 192 //log.warn("Cannot find rule {}", rule);
193 + return false;
189 } 194 }
190 195
191 @Override 196 @Override
......
1 package org.onlab.onos.store.trivial.impl; 1 package org.onlab.onos.store.trivial.impl;
2 2
3 -import static org.onlab.onos.net.intent.IntentState.FAILED; 3 +import com.google.common.collect.ImmutableSet;
4 -import static org.onlab.onos.net.intent.IntentState.INSTALLED;
5 -import static org.onlab.onos.net.intent.IntentState.SUBMITTED;
6 -import static org.onlab.onos.net.intent.IntentState.WITHDRAWN;
7 -import static org.slf4j.LoggerFactory.getLogger;
8 -
9 -import java.util.List;
10 -import java.util.Map;
11 -import java.util.concurrent.ConcurrentHashMap;
12 -
13 import org.apache.felix.scr.annotations.Activate; 4 import org.apache.felix.scr.annotations.Activate;
14 import org.apache.felix.scr.annotations.Component; 5 import org.apache.felix.scr.annotations.Component;
15 import org.apache.felix.scr.annotations.Deactivate; 6 import org.apache.felix.scr.annotations.Deactivate;
16 import org.apache.felix.scr.annotations.Service; 7 import org.apache.felix.scr.annotations.Service;
17 -import org.onlab.onos.net.intent.InstallableIntent;
18 import org.onlab.onos.net.intent.Intent; 8 import org.onlab.onos.net.intent.Intent;
19 import org.onlab.onos.net.intent.IntentEvent; 9 import org.onlab.onos.net.intent.IntentEvent;
20 import org.onlab.onos.net.intent.IntentId; 10 import org.onlab.onos.net.intent.IntentId;
...@@ -24,7 +14,12 @@ import org.onlab.onos.net.intent.IntentStoreDelegate; ...@@ -24,7 +14,12 @@ import org.onlab.onos.net.intent.IntentStoreDelegate;
24 import org.onlab.onos.store.AbstractStore; 14 import org.onlab.onos.store.AbstractStore;
25 import org.slf4j.Logger; 15 import org.slf4j.Logger;
26 16
27 -import com.google.common.collect.ImmutableSet; 17 +import java.util.List;
18 +import java.util.Map;
19 +import java.util.concurrent.ConcurrentHashMap;
20 +
21 +import static org.onlab.onos.net.intent.IntentState.*;
22 +import static org.slf4j.LoggerFactory.getLogger;
28 23
29 @Component(immediate = true) 24 @Component(immediate = true)
30 @Service 25 @Service
...@@ -35,7 +30,7 @@ public class SimpleIntentStore ...@@ -35,7 +30,7 @@ public class SimpleIntentStore
35 private final Logger log = getLogger(getClass()); 30 private final Logger log = getLogger(getClass());
36 private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>(); 31 private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>();
37 private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>(); 32 private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>();
38 - private final Map<IntentId, List<InstallableIntent>> installable = 33 + private final Map<IntentId, List<Intent>> installable =
39 new ConcurrentHashMap<>(); 34 new ConcurrentHashMap<>();
40 35
41 @Activate 36 @Activate
...@@ -96,12 +91,12 @@ public class SimpleIntentStore ...@@ -96,12 +91,12 @@ public class SimpleIntentStore
96 } 91 }
97 92
98 @Override 93 @Override
99 - public void addInstallableIntents(IntentId intentId, List<InstallableIntent> result) { 94 + public void addInstallableIntents(IntentId intentId, List<Intent> result) {
100 installable.put(intentId, result); 95 installable.put(intentId, result);
101 } 96 }
102 97
103 @Override 98 @Override
104 - public List<InstallableIntent> getInstallableIntents(IntentId intentId) { 99 + public List<Intent> getInstallableIntents(IntentId intentId) {
105 return installable.get(intentId); 100 return installable.get(intentId);
106 } 101 }
107 102
......
...@@ -572,7 +572,7 @@ ...@@ -572,7 +572,7 @@
572 <group> 572 <group>
573 <title>Sample Applications</title> 573 <title>Sample Applications</title>
574 <packages> 574 <packages>
575 - org.onlab.onos.tvue:org.onlab.onos.fwd:org.onlab.onos.ifwd:org.onlab.onos.mobility:org.onlab.onos.proxyarp:org.onlab.onos.foo:org.onlab.onos.calendar 575 + org.onlab.onos.tvue:org.onlab.onos.fwd:org.onlab.onos.ifwd:org.onlab.onos.mobility:org.onlab.onos.proxyarp:org.onlab.onos.foo:org.onlab.onos.calendar:org.onlab.onos.sdnip:org.onlab.onos.sdnip.*:org.onlab.onos.optical:org.onlab.onos.optical.*
576 </packages> 576 </packages>
577 </group> 577 </group>
578 </groups> 578 </groups>
......
...@@ -171,6 +171,7 @@ public final class KryoNamespace implements KryoFactory { ...@@ -171,6 +171,7 @@ public final class KryoNamespace implements KryoFactory {
171 Kryo kryo = getKryo(); 171 Kryo kryo = getKryo();
172 try { 172 try {
173 kryo.writeClassAndObject(out, obj); 173 kryo.writeClassAndObject(out, obj);
174 + out.flush();
174 return out.toBytes(); 175 return out.toBytes();
175 } finally { 176 } finally {
176 putKryo(kryo); 177 putKryo(kryo);
...@@ -188,6 +189,7 @@ public final class KryoNamespace implements KryoFactory { ...@@ -188,6 +189,7 @@ public final class KryoNamespace implements KryoFactory {
188 Kryo kryo = getKryo(); 189 Kryo kryo = getKryo();
189 try { 190 try {
190 kryo.writeClassAndObject(out, obj); 191 kryo.writeClassAndObject(out, obj);
192 + out.flush();
191 } finally { 193 } finally {
192 putKryo(kryo); 194 putKryo(kryo);
193 } 195 }
......