Showing
28 changed files
with
440 additions
and
576 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 { | ... | ... |
... | @@ -26,9 +26,8 @@ public class IntentRemoveCommand extends AbstractShellCommand { | ... | @@ -26,9 +26,8 @@ public class IntentRemoveCommand extends AbstractShellCommand { |
26 | if (radix == 16) { | 26 | if (radix == 16) { |
27 | id = id.replaceFirst("0x", ""); | 27 | id = id.replaceFirst("0x", ""); |
28 | } | 28 | } |
29 | - IntentId intentId = new IntentId(Long.parseLong(id, radix)); | ||
30 | - | ||
31 | 29 | ||
30 | + IntentId intentId = IntentId.valueOf(Long.parseLong(id, radix)); | ||
32 | Intent intent = service.getIntent(intentId); | 31 | Intent intent = service.getIntent(intentId); |
33 | if (intent != null) { | 32 | if (intent != null) { |
34 | service.withdraw(intent); | 33 | service.withdraw(intent); | ... | ... |
... | @@ -15,7 +15,7 @@ public final class IntentId implements BatchOperationTarget { | ... | @@ -15,7 +15,7 @@ public final class IntentId implements BatchOperationTarget { |
15 | * @param fingerprint long value | 15 | * @param fingerprint long value |
16 | * @return intent identifier | 16 | * @return intent identifier |
17 | */ | 17 | */ |
18 | - static IntentId valueOf(long fingerprint) { | 18 | + public static IntentId valueOf(long fingerprint) { |
19 | return new IntentId(fingerprint); | 19 | return new IntentId(fingerprint); |
20 | } | 20 | } |
21 | 21 | ... | ... |
... | @@ -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 | ... | ... |
... | @@ -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 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 instanceof Intent) { |
269 | - return ImmutableList.of((InstallableIntent) intent); | 261 | + return ImmutableList.of((Intent) 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 | } |
... | @@ -51,23 +51,8 @@ public class TestHostToHostIntent { | ... | @@ -51,23 +51,8 @@ public class TestHostToHostIntent { |
51 | 51 | ||
52 | HostId one = hid("00:00:00:00:00:01/-1"); | 52 | HostId one = hid("00:00:00:00:00:01/-1"); |
53 | HostId two = hid("00:00:00:00:00:02/-1"); | 53 | HostId two = hid("00:00:00:00:00:02/-1"); |
54 | - HostToHostIntent i1 = makeHostToHost(12, one, two); | 54 | + HostToHostIntent i1 = makeHostToHost(one, two); |
55 | - HostToHostIntent i2 = makeHostToHost(12, two, one); | 55 | + HostToHostIntent i2 = makeHostToHost(two, one); |
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 | - | ||
65 | - @Test | ||
66 | - public void testBaseDifferentEquals() { | ||
67 | - HostId one = hid("00:00:00:00:00:01/-1"); | ||
68 | - HostId two = hid("00:00:00:00:00:02/-1"); | ||
69 | - HostToHostIntent i1 = makeHostToHost(12, one, two); | ||
70 | - HostToHostIntent i2 = makeHostToHost(11, one, two); | ||
71 | 56 | ||
72 | assertThat(i1, is(not(equalTo(i2)))); | 57 | assertThat(i1, is(not(equalTo(i2)))); |
73 | } | 58 | } |
... | @@ -76,13 +61,12 @@ public class TestHostToHostIntent { | ... | @@ -76,13 +61,12 @@ public class TestHostToHostIntent { |
76 | * Tests that the hashCode() values for two equivalent HostToHostIntent | 61 | * Tests that the hashCode() values for two equivalent HostToHostIntent |
77 | * objects are the same. | 62 | * objects are the same. |
78 | */ | 63 | */ |
79 | - | ||
80 | @Test | 64 | @Test |
81 | public void testHashCodeEquals() { | 65 | public void testHashCodeEquals() { |
82 | HostId one = hid("00:00:00:00:00:01/-1"); | 66 | HostId one = hid("00:00:00:00:00:01/-1"); |
83 | HostId two = hid("00:00:00:00:00:02/-1"); | 67 | HostId two = hid("00:00:00:00:00:02/-1"); |
84 | - HostToHostIntent i1 = makeHostToHost(12, one, two); | 68 | + HostToHostIntent i1 = makeHostToHost(one, two); |
85 | - HostToHostIntent i2 = makeHostToHost(12, one, two); | 69 | + HostToHostIntent i2 = makeHostToHost(one, two); |
86 | 70 | ||
87 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); | 71 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); |
88 | } | 72 | } |
... | @@ -91,13 +75,12 @@ public class TestHostToHostIntent { | ... | @@ -91,13 +75,12 @@ public class TestHostToHostIntent { |
91 | * Tests that the hashCode() values for two distinct LinkCollectionIntent | 75 | * Tests that the hashCode() values for two distinct LinkCollectionIntent |
92 | * objects are different. | 76 | * objects are different. |
93 | */ | 77 | */ |
94 | - | ||
95 | @Test | 78 | @Test |
96 | public void testHashCodeDifferent() { | 79 | public void testHashCodeDifferent() { |
97 | HostId one = hid("00:00:00:00:00:01/-1"); | 80 | HostId one = hid("00:00:00:00:00:01/-1"); |
98 | HostId two = hid("00:00:00:00:00:02/-1"); | 81 | HostId two = hid("00:00:00:00:00:02/-1"); |
99 | - HostToHostIntent i1 = makeHostToHost(12, one, two); | 82 | + HostToHostIntent i1 = makeHostToHost(one, two); |
100 | - HostToHostIntent i2 = makeHostToHost(112, one, two); | 83 | + HostToHostIntent i2 = makeHostToHost(two, one); |
101 | 84 | ||
102 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); | 85 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); |
103 | } | 86 | } | ... | ... |
... | @@ -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 | ... | ... |
core/net/src/test/java/org/onlab/onos/net/intent/impl/TestMultiPointToSinglePointIntentCompiler.java
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 | ... | ... |
1 | package org.onlab.onos.store.intent.impl; | 1 | package org.onlab.onos.store.intent.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 | //FIXME: I LIE I AM NOT DISTRIBUTED | 24 | //FIXME: I LIE I AM NOT DISTRIBUTED |
30 | @Component(immediate = true) | 25 | @Component(immediate = true) |
... | @@ -36,8 +31,7 @@ public class DistributedIntentStore | ... | @@ -36,8 +31,7 @@ public class DistributedIntentStore |
36 | private final Logger log = getLogger(getClass()); | 31 | private final Logger log = getLogger(getClass()); |
37 | private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>(); | 32 | private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>(); |
38 | private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>(); | 33 | private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>(); |
39 | - private final Map<IntentId, List<InstallableIntent>> installable = | 34 | + private final Map<IntentId, List<Intent>> installable = new ConcurrentHashMap<>(); |
40 | - new ConcurrentHashMap<>(); | ||
41 | 35 | ||
42 | @Activate | 36 | @Activate |
43 | public void activate() { | 37 | public void activate() { |
... | @@ -97,12 +91,12 @@ public class DistributedIntentStore | ... | @@ -97,12 +91,12 @@ public class DistributedIntentStore |
97 | } | 91 | } |
98 | 92 | ||
99 | @Override | 93 | @Override |
100 | - public void addInstallableIntents(IntentId intentId, List<InstallableIntent> result) { | 94 | + public void addInstallableIntents(IntentId intentId, List<Intent> result) { |
101 | installable.put(intentId, result); | 95 | installable.put(intentId, result); |
102 | } | 96 | } |
103 | 97 | ||
104 | @Override | 98 | @Override |
105 | - public List<InstallableIntent> getInstallableIntents(IntentId intentId) { | 99 | + public List<Intent> getInstallableIntents(IntentId intentId) { |
106 | return installable.get(intentId); | 100 | return installable.get(intentId); |
107 | } | 101 | } |
108 | 102 | ... | ... |
-
Please register or login to post a comment