Charles Chan
Committed by Charles Chan

Segment Routing refactoring

- Change name: McastEventHandler -> McastHandler
- Separate HostHandler from SRManager
- Move storekeys to a dedicated package
- Replace SRObjevtiveContext and BridgeTableObjectiveContext with DefaultObjectiveContext

Change-Id: Iab25529487004759105e5ba60c1d2a3852ac45e6
Showing 13 changed files with 388 additions and 374 deletions
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.segmentrouting;
18 +
19 +import org.onlab.packet.Ip4Prefix;
20 +import org.onlab.packet.IpAddress;
21 +import org.onlab.packet.MacAddress;
22 +import org.onlab.packet.VlanId;
23 +import org.onosproject.core.CoreService;
24 +import org.onosproject.net.ConnectPoint;
25 +import org.onosproject.net.DeviceId;
26 +import org.onosproject.net.PortNumber;
27 +import org.onosproject.net.flow.DefaultTrafficSelector;
28 +import org.onosproject.net.flow.DefaultTrafficTreatment;
29 +import org.onosproject.net.flow.TrafficSelector;
30 +import org.onosproject.net.flow.TrafficTreatment;
31 +import org.onosproject.net.flowobjective.DefaultForwardingObjective;
32 +import org.onosproject.net.flowobjective.DefaultObjectiveContext;
33 +import org.onosproject.net.flowobjective.FlowObjectiveService;
34 +import org.onosproject.net.flowobjective.ForwardingObjective;
35 +import org.onosproject.net.flowobjective.ObjectiveContext;
36 +import org.onosproject.net.host.HostEvent;
37 +import org.onosproject.net.host.HostService;
38 +import org.slf4j.Logger;
39 +import org.slf4j.LoggerFactory;
40 +
41 +import java.util.Set;
42 +
43 +/**
44 + * Handles host-related events.
45 + */
46 +public class HostHandler {
47 + private static final Logger log = LoggerFactory.getLogger(HostHandler.class);
48 + private final SegmentRoutingManager srManager;
49 + private CoreService coreService;
50 + private HostService hostService;
51 + private FlowObjectiveService flowObjectiveService;
52 +
53 + /**
54 + * Constructs the HostHandler.
55 + *
56 + * @param srManager Segment Routing manager
57 + */
58 + public HostHandler(SegmentRoutingManager srManager) {
59 + this.srManager = srManager;
60 + coreService = srManager.coreService;
61 + hostService = srManager.hostService;
62 + flowObjectiveService = srManager.flowObjectiveService;
63 + }
64 +
65 + protected void readInitialHosts() {
66 + hostService.getHosts().forEach(host -> {
67 + MacAddress mac = host.mac();
68 + VlanId vlanId = host.vlan();
69 + DeviceId deviceId = host.location().deviceId();
70 + PortNumber port = host.location().port();
71 + Set<IpAddress> ips = host.ipAddresses();
72 + log.debug("Host {}/{} is added at {}:{}", mac, vlanId, deviceId, port);
73 +
74 + // Populate bridging table entry
75 + ForwardingObjective.Builder fob =
76 + getForwardingObjectiveBuilder(deviceId, mac, vlanId, port);
77 + ObjectiveContext context = new DefaultObjectiveContext(
78 + (objective) -> log.debug("Host rule for {} populated", host),
79 + (objective, error) ->
80 + log.warn("Failed to populate host rule for {}: {}", host, error));
81 + flowObjectiveService.forward(deviceId, fob.add(context));
82 +
83 + // Populate IP table entry
84 + ips.forEach(ip -> {
85 + if (ip.isIp4()) {
86 + srManager.routingRulePopulator.populateIpRuleForHost(
87 + deviceId, ip.getIp4Address(), mac, port);
88 + }
89 + });
90 + });
91 + }
92 +
93 + private ForwardingObjective.Builder getForwardingObjectiveBuilder(
94 + DeviceId deviceId, MacAddress mac, VlanId vlanId,
95 + PortNumber outport) {
96 + // Get assigned VLAN for the subnet
97 + VlanId outvlan = null;
98 + Ip4Prefix subnet = srManager.deviceConfiguration.getPortSubnet(deviceId, outport);
99 + if (subnet == null) {
100 + outvlan = VlanId.vlanId(SegmentRoutingManager.ASSIGNED_VLAN_NO_SUBNET);
101 + } else {
102 + outvlan = srManager.getSubnetAssignedVlanId(deviceId, subnet);
103 + }
104 +
105 + // match rule
106 + TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
107 + sbuilder.matchEthDst(mac);
108 + /*
109 + * Note: for untagged packets, match on the assigned VLAN.
110 + * for tagged packets, match on its incoming VLAN.
111 + */
112 + if (vlanId.equals(VlanId.NONE)) {
113 + sbuilder.matchVlanId(outvlan);
114 + } else {
115 + sbuilder.matchVlanId(vlanId);
116 + }
117 +
118 + TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
119 + tbuilder.immediate().popVlan();
120 + tbuilder.immediate().setOutput(outport);
121 +
122 + // for switch pipelines that need it, provide outgoing vlan as metadata
123 + TrafficSelector meta = DefaultTrafficSelector.builder()
124 + .matchVlanId(outvlan).build();
125 +
126 + // All forwarding is via Groups. Drivers can re-purpose to flow-actions if needed.
127 + int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outport,
128 + tbuilder.build(),
129 + meta);
130 +
131 + return DefaultForwardingObjective.builder()
132 + .withFlag(ForwardingObjective.Flag.SPECIFIC)
133 + .withSelector(sbuilder.build())
134 + .nextStep(portNextObjId)
135 + .withPriority(100)
136 + .fromApp(srManager.appId)
137 + .makePermanent();
138 + }
139 +
140 + protected void processHostAddedEvent(HostEvent event) {
141 + MacAddress mac = event.subject().mac();
142 + VlanId vlanId = event.subject().vlan();
143 + DeviceId deviceId = event.subject().location().deviceId();
144 + PortNumber port = event.subject().location().port();
145 + Set<IpAddress> ips = event.subject().ipAddresses();
146 + log.info("Host {}/{} is added at {}:{}", mac, vlanId, deviceId, port);
147 +
148 + if (!srManager.deviceConfiguration.suppressHost()
149 + .contains(new ConnectPoint(deviceId, port))) {
150 + // Populate bridging table entry
151 + log.debug("Populate L2 table entry for host {} at {}:{}",
152 + mac, deviceId, port);
153 + ForwardingObjective.Builder fob =
154 + getForwardingObjectiveBuilder(deviceId, mac, vlanId, port);
155 + ObjectiveContext context = new DefaultObjectiveContext(
156 + (objective) -> log.debug("Host rule for {} populated", event.subject()),
157 + (objective, error) ->
158 + log.warn("Failed to populate host rule for {}: {}", event.subject(), error));
159 + flowObjectiveService.forward(deviceId, fob.add(context));
160 +
161 + // Populate IP table entry
162 + ips.forEach(ip -> {
163 + if (ip.isIp4()) {
164 + srManager.routingRulePopulator.populateIpRuleForHost(
165 + deviceId, ip.getIp4Address(), mac, port);
166 + }
167 + });
168 + }
169 + }
170 +
171 + protected void processHostRemoveEvent(HostEvent event) {
172 + MacAddress mac = event.subject().mac();
173 + VlanId vlanId = event.subject().vlan();
174 + DeviceId deviceId = event.subject().location().deviceId();
175 + PortNumber port = event.subject().location().port();
176 + Set<IpAddress> ips = event.subject().ipAddresses();
177 + log.debug("Host {}/{} is removed from {}:{}", mac, vlanId, deviceId, port);
178 +
179 + if (!srManager.deviceConfiguration.suppressHost()
180 + .contains(new ConnectPoint(deviceId, port))) {
181 + // Revoke bridging table entry
182 + ForwardingObjective.Builder fob =
183 + getForwardingObjectiveBuilder(deviceId, mac, vlanId, port);
184 + ObjectiveContext context = new DefaultObjectiveContext(
185 + (objective) -> log.debug("Host rule for {} revoked", event.subject()),
186 + (objective, error) ->
187 + log.warn("Failed to revoke host rule for {}: {}", event.subject(), error));
188 + flowObjectiveService.forward(deviceId, fob.remove(context));
189 +
190 + // Revoke IP table entry
191 + ips.forEach(ip -> {
192 + if (ip.isIp4()) {
193 + srManager.routingRulePopulator.revokeIpRuleForHost(
194 + deviceId, ip.getIp4Address(), mac, port);
195 + }
196 + });
197 + }
198 + }
199 +
200 + protected void processHostMovedEvent(HostEvent event) {
201 + MacAddress mac = event.subject().mac();
202 + VlanId vlanId = event.subject().vlan();
203 + DeviceId prevDeviceId = event.prevSubject().location().deviceId();
204 + PortNumber prevPort = event.prevSubject().location().port();
205 + Set<IpAddress> prevIps = event.prevSubject().ipAddresses();
206 + DeviceId newDeviceId = event.subject().location().deviceId();
207 + PortNumber newPort = event.subject().location().port();
208 + Set<IpAddress> newIps = event.subject().ipAddresses();
209 + log.debug("Host {}/{} is moved from {}:{} to {}:{}",
210 + mac, vlanId, prevDeviceId, prevPort, newDeviceId, newPort);
211 +
212 + if (!srManager.deviceConfiguration.suppressHost()
213 + .contains(new ConnectPoint(prevDeviceId, prevPort))) {
214 + // Revoke previous bridging table entry
215 + ForwardingObjective.Builder prevFob =
216 + getForwardingObjectiveBuilder(prevDeviceId, mac, vlanId, prevPort);
217 + ObjectiveContext context = new DefaultObjectiveContext(
218 + (objective) -> log.debug("Host rule for {} revoked", event.subject()),
219 + (objective, error) ->
220 + log.warn("Failed to revoke host rule for {}: {}", event.subject(), error));
221 + flowObjectiveService.forward(prevDeviceId, prevFob.remove(context));
222 +
223 + // Revoke previous IP table entry
224 + prevIps.forEach(ip -> {
225 + if (ip.isIp4()) {
226 + srManager.routingRulePopulator.revokeIpRuleForHost(
227 + prevDeviceId, ip.getIp4Address(), mac, prevPort);
228 + }
229 + });
230 + }
231 +
232 + if (!srManager.deviceConfiguration.suppressHost()
233 + .contains(new ConnectPoint(newDeviceId, newPort))) {
234 + // Populate new bridging table entry
235 + ForwardingObjective.Builder newFob =
236 + getForwardingObjectiveBuilder(newDeviceId, mac, vlanId, newPort);
237 + ObjectiveContext context = new DefaultObjectiveContext(
238 + (objective) -> log.debug("Host rule for {} populated", event.subject()),
239 + (objective, error) ->
240 + log.warn("Failed to populate host rule for {}: {}", event.subject(), error));
241 + flowObjectiveService.forward(newDeviceId, newFob.add(context));
242 +
243 + // Populate new IP table entry
244 + newIps.forEach(ip -> {
245 + if (ip.isIp4()) {
246 + srManager.routingRulePopulator.populateIpRuleForHost(
247 + newDeviceId, ip.getIp4Address(), mac, newPort);
248 + }
249 + });
250 + }
251 + }
252 +
253 + protected void processHostUpdatedEvent(HostEvent event) {
254 + MacAddress mac = event.subject().mac();
255 + VlanId vlanId = event.subject().vlan();
256 + DeviceId prevDeviceId = event.prevSubject().location().deviceId();
257 + PortNumber prevPort = event.prevSubject().location().port();
258 + Set<IpAddress> prevIps = event.prevSubject().ipAddresses();
259 + DeviceId newDeviceId = event.subject().location().deviceId();
260 + PortNumber newPort = event.subject().location().port();
261 + Set<IpAddress> newIps = event.subject().ipAddresses();
262 + log.debug("Host {}/{} is updated", mac, vlanId);
263 +
264 + if (!srManager.deviceConfiguration.suppressHost()
265 + .contains(new ConnectPoint(prevDeviceId, prevPort))) {
266 + // Revoke previous IP table entry
267 + prevIps.forEach(ip -> {
268 + if (ip.isIp4()) {
269 + srManager.routingRulePopulator.revokeIpRuleForHost(
270 + prevDeviceId, ip.getIp4Address(), mac, prevPort);
271 + }
272 + });
273 + }
274 +
275 + if (!srManager.deviceConfiguration.suppressHost()
276 + .contains(new ConnectPoint(newDeviceId, newPort))) {
277 + // Populate new IP table entry
278 + newIps.forEach(ip -> {
279 + if (ip.isIp4()) {
280 + srManager.routingRulePopulator.populateIpRuleForHost(
281 + newDeviceId, ip.getIp4Address(), mac, newPort);
282 + }
283 + });
284 + }
285 + }
286 +}
...@@ -48,7 +48,7 @@ import org.onosproject.net.flowobjective.NextObjective; ...@@ -48,7 +48,7 @@ import org.onosproject.net.flowobjective.NextObjective;
48 import org.onosproject.net.mcast.McastEvent; 48 import org.onosproject.net.mcast.McastEvent;
49 import org.onosproject.net.mcast.McastRouteInfo; 49 import org.onosproject.net.mcast.McastRouteInfo;
50 import org.onosproject.net.topology.TopologyService; 50 import org.onosproject.net.topology.TopologyService;
51 -import org.onosproject.segmentrouting.grouphandler.McastNextObjectiveStoreKey; 51 +import org.onosproject.segmentrouting.storekey.McastNextObjectiveStoreKey;
52 import org.onosproject.store.serializers.KryoNamespaces; 52 import org.onosproject.store.serializers.KryoNamespaces;
53 import org.onosproject.store.service.ConsistentMap; 53 import org.onosproject.store.service.ConsistentMap;
54 import org.onosproject.store.service.Serializer; 54 import org.onosproject.store.service.Serializer;
...@@ -63,10 +63,10 @@ import java.util.Optional; ...@@ -63,10 +63,10 @@ import java.util.Optional;
63 import java.util.Set; 63 import java.util.Set;
64 64
65 /** 65 /**
66 - * Multicast event handler. 66 + * Handles multicast-related events.
67 */ 67 */
68 -public class McastEventHandler { 68 +public class McastHandler {
69 - private static final Logger log = LoggerFactory.getLogger(McastEventHandler.class); 69 + private static final Logger log = LoggerFactory.getLogger(McastHandler.class);
70 private final SegmentRoutingManager srManager; 70 private final SegmentRoutingManager srManager;
71 private final ApplicationId coreAppId; 71 private final ApplicationId coreAppId;
72 private StorageService storageService; 72 private StorageService storageService;
...@@ -79,7 +79,7 @@ public class McastEventHandler { ...@@ -79,7 +79,7 @@ public class McastEventHandler {
79 * 79 *
80 * @param srManager Segment Routing manager 80 * @param srManager Segment Routing manager
81 */ 81 */
82 - public McastEventHandler(SegmentRoutingManager srManager) { 82 + public McastHandler(SegmentRoutingManager srManager) {
83 coreAppId = srManager.coreService.getAppId(CoreService.CORE_APP_NAME); 83 coreAppId = srManager.coreService.getAppId(CoreService.CORE_APP_NAME);
84 84
85 this.srManager = srManager; 85 this.srManager = srManager;
......
...@@ -23,7 +23,9 @@ import org.onosproject.net.config.NetworkConfigEvent; ...@@ -23,7 +23,9 @@ import org.onosproject.net.config.NetworkConfigEvent;
23 import org.onosproject.net.device.DeviceService; 23 import org.onosproject.net.device.DeviceService;
24 import org.onosproject.net.flow.criteria.Criteria; 24 import org.onosproject.net.flow.criteria.Criteria;
25 import org.onosproject.net.flowobjective.DefaultFilteringObjective; 25 import org.onosproject.net.flowobjective.DefaultFilteringObjective;
26 +import org.onosproject.net.flowobjective.DefaultObjectiveContext;
26 import org.onosproject.net.flowobjective.FilteringObjective; 27 import org.onosproject.net.flowobjective.FilteringObjective;
28 +import org.onosproject.net.flowobjective.ObjectiveContext;
27 import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; 29 import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
28 import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig; 30 import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
29 import org.slf4j.Logger; 31 import org.slf4j.Logger;
...@@ -117,9 +119,11 @@ public class NetworkConfigEventHandler { ...@@ -117,9 +119,11 @@ public class NetworkConfigEventHandler {
117 return; 119 return;
118 } 120 }
119 getVRouterFlowObjBuilders(pendingAdd).forEach(foBuilder -> { 121 getVRouterFlowObjBuilders(pendingAdd).forEach(foBuilder -> {
120 - srManager.flowObjectiveService. 122 + ObjectiveContext context = new DefaultObjectiveContext(
121 - filter(deviceId, foBuilder.add(new SRObjectiveContext(deviceId, 123 + (objective) -> log.debug("vRouterMac filter for {} populated", pendingAdd),
122 - SRObjectiveContext.ObjectiveType.FILTER))); 124 + (objective, error) ->
125 + log.warn("Failed to populate vRouterMac filter for {}: {}", pendingAdd, error));
126 + srManager.flowObjectiveService.filter(deviceId, foBuilder.add(context));
123 }); 127 });
124 } 128 }
125 129
...@@ -128,9 +132,11 @@ public class NetworkConfigEventHandler { ...@@ -128,9 +132,11 @@ public class NetworkConfigEventHandler {
128 return; 132 return;
129 } 133 }
130 getVRouterFlowObjBuilders(pendingRemove).forEach(foBuilder -> { 134 getVRouterFlowObjBuilders(pendingRemove).forEach(foBuilder -> {
131 - srManager.flowObjectiveService. 135 + ObjectiveContext context = new DefaultObjectiveContext(
132 - filter(deviceId, foBuilder.remove(new SRObjectiveContext(deviceId, 136 + (objective) -> log.debug("vRouterMac filter for {} revoked", pendingRemove),
133 - SRObjectiveContext.ObjectiveType.FILTER))); 137 + (objective, error) ->
138 + log.warn("Failed to revoke vRouterMac filter for {}: {}", pendingRemove, error));
139 + srManager.flowObjectiveService.filter(deviceId, foBuilder.remove(context));
134 }); 140 });
135 } 141 }
136 142
......
...@@ -24,6 +24,8 @@ import org.onlab.packet.MacAddress; ...@@ -24,6 +24,8 @@ import org.onlab.packet.MacAddress;
24 import org.onlab.packet.MplsLabel; 24 import org.onlab.packet.MplsLabel;
25 import org.onlab.packet.VlanId; 25 import org.onlab.packet.VlanId;
26 import org.onosproject.net.ConnectPoint; 26 import org.onosproject.net.ConnectPoint;
27 +import org.onosproject.net.flowobjective.DefaultObjectiveContext;
28 +import org.onosproject.net.flowobjective.ObjectiveContext;
27 import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; 29 import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
28 import org.onosproject.segmentrouting.config.DeviceConfiguration; 30 import org.onosproject.segmentrouting.config.DeviceConfiguration;
29 import org.onosproject.segmentrouting.grouphandler.NeighborSet; 31 import org.onosproject.segmentrouting.grouphandler.NeighborSet;
...@@ -112,9 +114,11 @@ public class RoutingRulePopulator { ...@@ -112,9 +114,11 @@ public class RoutingRulePopulator {
112 log.warn(e.getMessage() + " Aborting populateIpRuleForHost."); 114 log.warn(e.getMessage() + " Aborting populateIpRuleForHost.");
113 return; 115 return;
114 } 116 }
115 - srManager.flowObjectiveService. 117 + ObjectiveContext context = new DefaultObjectiveContext(
116 - forward(deviceId, fwdBuilder.add(new SRObjectiveContext(deviceId, 118 + (objective) -> log.debug("IP rule for host {} populated", hostIp),
117 - SRObjectiveContext.ObjectiveType.FORWARDING))); 119 + (objective, error) ->
120 + log.warn("Failed to populate IP rule for host {}: {}", hostIp, error));
121 + srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context));
118 rulePopulationCounter.incrementAndGet(); 122 rulePopulationCounter.incrementAndGet();
119 } 123 }
120 124
...@@ -138,9 +142,11 @@ public class RoutingRulePopulator { ...@@ -138,9 +142,11 @@ public class RoutingRulePopulator {
138 log.warn(e.getMessage() + " Aborting revokeIpRuleForHost."); 142 log.warn(e.getMessage() + " Aborting revokeIpRuleForHost.");
139 return; 143 return;
140 } 144 }
141 - srManager.flowObjectiveService. 145 + ObjectiveContext context = new DefaultObjectiveContext(
142 - forward(deviceId, fwdBuilder.remove(new SRObjectiveContext(deviceId, 146 + (objective) -> log.debug("IP rule for host {} revoked", hostIp),
143 - SRObjectiveContext.ObjectiveType.FORWARDING))); 147 + (objective, error) ->
148 + log.warn("Failed to revoke IP rule for host {}: {}", hostIp, error));
149 + srManager.flowObjectiveService.forward(deviceId, fwdBuilder.remove(context));
144 } 150 }
145 151
146 private ForwardingObjective.Builder getForwardingObjectiveBuilder( 152 private ForwardingObjective.Builder getForwardingObjectiveBuilder(
...@@ -285,11 +291,11 @@ public class RoutingRulePopulator { ...@@ -285,11 +291,11 @@ public class RoutingRulePopulator {
285 + "for router IP/subnet {} in switch {}", 291 + "for router IP/subnet {} in switch {}",
286 ipPrefix, 292 ipPrefix,
287 deviceId); 293 deviceId);
288 - srManager.flowObjectiveService. 294 + ObjectiveContext context = new DefaultObjectiveContext(
289 - forward(deviceId, 295 + (objective) -> log.debug("IP rule for router {} populated", ipPrefix),
290 - fwdBuilder. 296 + (objective, error) ->
291 - add(new SRObjectiveContext(deviceId, 297 + log.warn("Failed to populate IP rule for router {}: {}", ipPrefix, error));
292 - SRObjectiveContext.ObjectiveType.FORWARDING))); 298 + srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context));
293 rulePopulationCounter.incrementAndGet(); 299 rulePopulationCounter.incrementAndGet();
294 300
295 return true; 301 return true;
...@@ -387,11 +393,11 @@ public class RoutingRulePopulator { ...@@ -387,11 +393,11 @@ public class RoutingRulePopulator {
387 .makePermanent()).withSelector(selector) 393 .makePermanent()).withSelector(selector)
388 .withPriority(SegmentRoutingService.DEFAULT_PRIORITY)) 394 .withPriority(SegmentRoutingService.DEFAULT_PRIORITY))
389 .withFlag(ForwardingObjective.Flag.SPECIFIC); 395 .withFlag(ForwardingObjective.Flag.SPECIFIC);
390 - srManager.flowObjectiveService. 396 + ObjectiveContext context = new DefaultObjectiveContext(
391 - forward(deviceId, 397 + (objective) -> log.debug("MPLS rule for SID {} populated", segmentId),
392 - fwdObjBuilder. 398 + (objective, error) ->
393 - add(new SRObjectiveContext(deviceId, 399 + log.warn("Failed to populate MPLS rule for SID {}: {}", segmentId, error));
394 - SRObjectiveContext.ObjectiveType.FORWARDING))); 400 + srManager.flowObjectiveService.forward(deviceId, fwdObjBuilder.add(context));
395 rulePopulationCounter.incrementAndGet(); 401 rulePopulationCounter.incrementAndGet();
396 } 402 }
397 403
...@@ -471,9 +477,9 @@ public class RoutingRulePopulator { ...@@ -471,9 +477,9 @@ public class RoutingRulePopulator {
471 } 477 }
472 478
473 for (Port port : srManager.deviceService.getPorts(deviceId)) { 479 for (Port port : srManager.deviceService.getPorts(deviceId)) {
474 - ConnectPoint cp = new ConnectPoint(deviceId, port.number()); 480 + ConnectPoint connectPoint = new ConnectPoint(deviceId, port.number());
475 // TODO: Handles dynamic port events when we are ready for dynamic config 481 // TODO: Handles dynamic port events when we are ready for dynamic config
476 - if (!srManager.deviceConfiguration.suppressSubnet().contains(cp) && 482 + if (!srManager.deviceConfiguration.suppressSubnet().contains(connectPoint) &&
477 port.isEnabled()) { 483 port.isEnabled()) {
478 Ip4Prefix portSubnet = config.getPortSubnet(deviceId, port.number()); 484 Ip4Prefix portSubnet = config.getPortSubnet(deviceId, port.number());
479 VlanId assignedVlan = (portSubnet == null) 485 VlanId assignedVlan = (portSubnet == null)
...@@ -492,9 +498,11 @@ public class RoutingRulePopulator { ...@@ -492,9 +498,11 @@ public class RoutingRulePopulator {
492 fob.withMeta(tt); 498 fob.withMeta(tt);
493 } 499 }
494 fob.permit().fromApp(srManager.appId); 500 fob.permit().fromApp(srManager.appId);
495 - srManager.flowObjectiveService. 501 + ObjectiveContext context = new DefaultObjectiveContext(
496 - filter(deviceId, fob.add(new SRObjectiveContext(deviceId, 502 + (objective) -> log.debug("Filter for {} populated", connectPoint),
497 - SRObjectiveContext.ObjectiveType.FILTER))); 503 + (objective, error) ->
504 + log.warn("Failed to populate filter for {}: {}", connectPoint, error));
505 + srManager.flowObjectiveService.filter(deviceId, fob.add(context));
498 } 506 }
499 } 507 }
500 } 508 }
...@@ -537,11 +545,11 @@ public class RoutingRulePopulator { ...@@ -537,11 +545,11 @@ public class RoutingRulePopulator {
537 .withPriority(SegmentRoutingService.HIGHEST_PRIORITY) 545 .withPriority(SegmentRoutingService.HIGHEST_PRIORITY)
538 .makePermanent() 546 .makePermanent()
539 .fromApp(srManager.appId); 547 .fromApp(srManager.appId);
540 - log.debug("Installing forwarding objective to punt port IP addresses"); 548 + ObjectiveContext context = new DefaultObjectiveContext(
541 - srManager.flowObjectiveService. 549 + (objective) -> log.debug("IP punt rule for {} populated", ipaddr),
542 - forward(deviceId, 550 + (objective, error) ->
543 - puntIp.add(new SRObjectiveContext(deviceId, 551 + log.warn("Failed to populate IP punt rule for {}: {}", ipaddr, error));
544 - SRObjectiveContext.ObjectiveType.FORWARDING))); 552 + srManager.flowObjectiveService.forward(deviceId, puntIp.add(context));
545 } 553 }
546 } 554 }
547 555
...@@ -585,14 +593,11 @@ public class RoutingRulePopulator { ...@@ -585,14 +593,11 @@ public class RoutingRulePopulator {
585 .withPriority(SegmentRoutingService.FLOOD_PRIORITY) 593 .withPriority(SegmentRoutingService.FLOOD_PRIORITY)
586 .fromApp(srManager.appId) 594 .fromApp(srManager.appId)
587 .makePermanent(); 595 .makePermanent();
588 - 596 + ObjectiveContext context = new DefaultObjectiveContext(
589 - srManager.flowObjectiveService.forward( 597 + (objective) -> log.debug("Subnet broadcast rule for {} populated", subnet),
590 - deviceId, 598 + (objective, error) ->
591 - fob.add(new SRObjectiveContext( 599 + log.warn("Failed to populate subnet broadcast rule for {}: {}", subnet, error));
592 - deviceId, 600 + srManager.flowObjectiveService.forward(deviceId, fob.add(context));
593 - SRObjectiveContext.ObjectiveType.FORWARDING)
594 - )
595 - );
596 }); 601 });
597 } 602 }
598 603
...@@ -618,11 +623,12 @@ public class RoutingRulePopulator { ...@@ -618,11 +623,12 @@ public class RoutingRulePopulator {
618 .addCondition(Criteria.matchVlanId(vlanId)) 623 .addCondition(Criteria.matchVlanId(vlanId))
619 .addCondition(Criteria.matchEthDst(MacAddress.NONE)) 624 .addCondition(Criteria.matchEthDst(MacAddress.NONE))
620 .withPriority(SegmentRoutingService.XCONNECT_PRIORITY); 625 .withPriority(SegmentRoutingService.XCONNECT_PRIORITY);
621 -
622 fob.permit().fromApp(srManager.appId); 626 fob.permit().fromApp(srManager.appId);
623 - srManager.flowObjectiveService 627 + ObjectiveContext context = new DefaultObjectiveContext(
624 - .filter(deviceId, fob.add(new SRObjectiveContext(deviceId, 628 + (objective) -> log.debug("XConnect filter for {} populated", connectPoint),
625 - SRObjectiveContext.ObjectiveType.FILTER))); 629 + (objective, error) ->
630 + log.warn("Failed to populate xconnect filter for {}: {}", connectPoint, error));
631 + srManager.flowObjectiveService.filter(deviceId, fob.add(context));
626 }); 632 });
627 }); 633 });
628 } 634 }
...@@ -666,14 +672,11 @@ public class RoutingRulePopulator { ...@@ -666,14 +672,11 @@ public class RoutingRulePopulator {
666 .withPriority(SegmentRoutingService.DEFAULT_PRIORITY) 672 .withPriority(SegmentRoutingService.DEFAULT_PRIORITY)
667 .fromApp(srManager.appId) 673 .fromApp(srManager.appId)
668 .makePermanent(); 674 .makePermanent();
669 - 675 + ObjectiveContext context = new DefaultObjectiveContext(
670 - srManager.flowObjectiveService.forward( 676 + (objective) -> log.debug("XConnect rule for {} populated", xConnects),
671 - deviceId, 677 + (objective, error) ->
672 - fob.add(new SRObjectiveContext( 678 + log.warn("Failed to populate xconnect rule for {}: {}", xConnects, error));
673 - deviceId, 679 + srManager.flowObjectiveService.forward(deviceId, fob.add(context));
674 - SRObjectiveContext.ObjectiveType.FORWARDING)
675 - )
676 - );
677 }); 680 });
678 } 681 }
679 682
......
...@@ -24,9 +24,7 @@ import org.apache.felix.scr.annotations.Service; ...@@ -24,9 +24,7 @@ import org.apache.felix.scr.annotations.Service;
24 import org.onlab.packet.Ethernet; 24 import org.onlab.packet.Ethernet;
25 import org.onlab.packet.IPv4; 25 import org.onlab.packet.IPv4;
26 import org.onlab.packet.Ip4Prefix; 26 import org.onlab.packet.Ip4Prefix;
27 -import org.onlab.packet.IpAddress;
28 import org.onlab.packet.IpPrefix; 27 import org.onlab.packet.IpPrefix;
29 -import org.onlab.packet.MacAddress;
30 import org.onlab.packet.VlanId; 28 import org.onlab.packet.VlanId;
31 import org.onlab.util.KryoNamespace; 29 import org.onlab.util.KryoNamespace;
32 import org.onosproject.cfg.ComponentConfigService; 30 import org.onosproject.cfg.ComponentConfigService;
...@@ -35,7 +33,6 @@ import org.onosproject.core.CoreService; ...@@ -35,7 +33,6 @@ import org.onosproject.core.CoreService;
35 import org.onosproject.event.Event; 33 import org.onosproject.event.Event;
36 import org.onosproject.incubator.net.config.basics.McastConfig; 34 import org.onosproject.incubator.net.config.basics.McastConfig;
37 import org.onosproject.mastership.MastershipService; 35 import org.onosproject.mastership.MastershipService;
38 -import org.onosproject.net.ConnectPoint;
39 import org.onosproject.net.Device; 36 import org.onosproject.net.Device;
40 import org.onosproject.net.DeviceId; 37 import org.onosproject.net.DeviceId;
41 import org.onosproject.net.Link; 38 import org.onosproject.net.Link;
...@@ -50,15 +47,9 @@ import org.onosproject.net.device.DeviceEvent; ...@@ -50,15 +47,9 @@ import org.onosproject.net.device.DeviceEvent;
50 import org.onosproject.net.device.DeviceListener; 47 import org.onosproject.net.device.DeviceListener;
51 import org.onosproject.net.device.DeviceService; 48 import org.onosproject.net.device.DeviceService;
52 import org.onosproject.net.flow.DefaultTrafficSelector; 49 import org.onosproject.net.flow.DefaultTrafficSelector;
53 -import org.onosproject.net.flow.DefaultTrafficTreatment;
54 import org.onosproject.net.flow.TrafficSelector; 50 import org.onosproject.net.flow.TrafficSelector;
55 import org.onosproject.net.flow.TrafficTreatment; 51 import org.onosproject.net.flow.TrafficTreatment;
56 -import org.onosproject.net.flowobjective.DefaultForwardingObjective;
57 import org.onosproject.net.flowobjective.FlowObjectiveService; 52 import org.onosproject.net.flowobjective.FlowObjectiveService;
58 -import org.onosproject.net.flowobjective.ForwardingObjective;
59 -import org.onosproject.net.flowobjective.Objective;
60 -import org.onosproject.net.flowobjective.ObjectiveContext;
61 -import org.onosproject.net.flowobjective.ObjectiveError;
62 import org.onosproject.net.host.HostEvent; 53 import org.onosproject.net.host.HostEvent;
63 import org.onosproject.net.host.HostListener; 54 import org.onosproject.net.host.HostListener;
64 import org.onosproject.net.mcast.McastEvent; 55 import org.onosproject.net.mcast.McastEvent;
...@@ -72,8 +63,8 @@ import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig; ...@@ -72,8 +63,8 @@ import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig;
72 import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig; 63 import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
73 import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; 64 import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler;
74 import org.onosproject.segmentrouting.grouphandler.NeighborSet; 65 import org.onosproject.segmentrouting.grouphandler.NeighborSet;
75 -import org.onosproject.segmentrouting.grouphandler.NeighborSetNextObjectiveStoreKey; 66 +import org.onosproject.segmentrouting.storekey.NeighborSetNextObjectiveStoreKey;
76 -import org.onosproject.segmentrouting.grouphandler.PortNextObjectiveStoreKey; 67 +import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
77 import org.onosproject.net.host.HostService; 68 import org.onosproject.net.host.HostService;
78 import org.onosproject.net.link.LinkEvent; 69 import org.onosproject.net.link.LinkEvent;
79 import org.onosproject.net.link.LinkListener; 70 import org.onosproject.net.link.LinkListener;
...@@ -82,8 +73,9 @@ import org.onosproject.net.packet.InboundPacket; ...@@ -82,8 +73,9 @@ import org.onosproject.net.packet.InboundPacket;
82 import org.onosproject.net.packet.PacketContext; 73 import org.onosproject.net.packet.PacketContext;
83 import org.onosproject.net.packet.PacketProcessor; 74 import org.onosproject.net.packet.PacketProcessor;
84 import org.onosproject.net.packet.PacketService; 75 import org.onosproject.net.packet.PacketService;
85 -import org.onosproject.segmentrouting.grouphandler.SubnetNextObjectiveStoreKey; 76 +import org.onosproject.segmentrouting.storekey.SubnetAssignedVidStoreKey;
86 -import org.onosproject.segmentrouting.grouphandler.XConnectNextObjectiveStoreKey; 77 +import org.onosproject.segmentrouting.storekey.SubnetNextObjectiveStoreKey;
78 +import org.onosproject.segmentrouting.storekey.XConnectNextObjectiveStoreKey;
87 import org.onosproject.store.serializers.KryoNamespaces; 79 import org.onosproject.store.serializers.KryoNamespaces;
88 import org.onosproject.store.service.EventuallyConsistentMap; 80 import org.onosproject.store.service.EventuallyConsistentMap;
89 import org.onosproject.store.service.EventuallyConsistentMapBuilder; 81 import org.onosproject.store.service.EventuallyConsistentMapBuilder;
...@@ -168,7 +160,8 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -168,7 +160,8 @@ public class SegmentRoutingManager implements SegmentRoutingService {
168 private InternalLinkListener linkListener = null; 160 private InternalLinkListener linkListener = null;
169 private InternalDeviceListener deviceListener = null; 161 private InternalDeviceListener deviceListener = null;
170 private NetworkConfigEventHandler netcfgHandler = null; 162 private NetworkConfigEventHandler netcfgHandler = null;
171 - private McastEventHandler mcastEventHandler = null; 163 + private McastHandler mcastHandler = null;
164 + private HostHandler hostHandler = null;
172 private InternalEventHandler eventHandler = new InternalEventHandler(); 165 private InternalEventHandler eventHandler = new InternalEventHandler();
173 private final InternalHostListener hostListener = new InternalHostListener(); 166 private final InternalHostListener hostListener = new InternalHostListener();
174 private final InternalConfigListener cfgListener = new InternalConfigListener(this); 167 private final InternalConfigListener cfgListener = new InternalConfigListener(this);
...@@ -329,7 +322,8 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -329,7 +322,8 @@ public class SegmentRoutingManager implements SegmentRoutingService {
329 linkListener = new InternalLinkListener(); 322 linkListener = new InternalLinkListener();
330 deviceListener = new InternalDeviceListener(); 323 deviceListener = new InternalDeviceListener();
331 netcfgHandler = new NetworkConfigEventHandler(this); 324 netcfgHandler = new NetworkConfigEventHandler(this);
332 - mcastEventHandler = new McastEventHandler(this); 325 + mcastHandler = new McastHandler(this);
326 + hostHandler = new HostHandler(this);
333 327
334 cfgService.addListener(cfgListener); 328 cfgService.addListener(cfgListener);
335 cfgService.registerConfigFactory(deviceConfigFactory); 329 cfgService.registerConfigFactory(deviceConfigFactory);
...@@ -807,7 +801,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -807,7 +801,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
807 // port addressing rules to the driver as well irrespective of whether 801 // port addressing rules to the driver as well irrespective of whether
808 // this instance is the master or not. 802 // this instance is the master or not.
809 defaultRoutingHandler.populatePortAddressingRules(device.id()); 803 defaultRoutingHandler.populatePortAddressingRules(device.id());
810 - hostListener.readInitialHosts(); 804 + hostHandler.readInitialHosts();
811 } 805 }
812 if (mastershipService.isLocalMaster(device.id())) { 806 if (mastershipService.isLocalMaster(device.id())) {
813 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id()); 807 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
...@@ -924,7 +918,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -924,7 +918,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
924 // port addressing rules to the driver as well, irrespective of whether 918 // port addressing rules to the driver as well, irrespective of whether
925 // this instance is the master or not. 919 // this instance is the master or not.
926 defaultRoutingHandler.populatePortAddressingRules(device.id()); 920 defaultRoutingHandler.populatePortAddressingRules(device.id());
927 - hostListener.readInitialHosts(); 921 + hostHandler.readInitialHosts();
928 } 922 }
929 if (mastershipService.isLocalMaster(device.id())) { 923 if (mastershipService.isLocalMaster(device.id())) {
930 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id()); 924 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
...@@ -973,220 +967,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -973,220 +967,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
973 } 967 }
974 } 968 }
975 969
976 - // TODO Move bridging table population to a separate class
977 private class InternalHostListener implements HostListener { 970 private class InternalHostListener implements HostListener {
978 - private void readInitialHosts() {
979 - hostService.getHosts().forEach(host -> {
980 - MacAddress mac = host.mac();
981 - VlanId vlanId = host.vlan();
982 - DeviceId deviceId = host.location().deviceId();
983 - PortNumber port = host.location().port();
984 - Set<IpAddress> ips = host.ipAddresses();
985 - log.debug("Host {}/{} is added at {}:{}", mac, vlanId, deviceId, port);
986 -
987 - // Populate bridging table entry
988 - ForwardingObjective.Builder fob =
989 - getForwardingObjectiveBuilder(deviceId, mac, vlanId, port);
990 - flowObjectiveService.forward(deviceId, fob.add(
991 - new BridgingTableObjectiveContext(mac, vlanId)
992 - ));
993 -
994 - // Populate IP table entry
995 - ips.forEach(ip -> {
996 - if (ip.isIp4()) {
997 - routingRulePopulator.populateIpRuleForHost(
998 - deviceId, ip.getIp4Address(), mac, port);
999 - }
1000 - });
1001 - });
1002 - }
1003 -
1004 - private ForwardingObjective.Builder getForwardingObjectiveBuilder(
1005 - DeviceId deviceId, MacAddress mac, VlanId vlanId,
1006 - PortNumber outport) {
1007 - // Get assigned VLAN for the subnet
1008 - VlanId outvlan = null;
1009 - Ip4Prefix subnet = deviceConfiguration.getPortSubnet(deviceId, outport);
1010 - if (subnet == null) {
1011 - outvlan = VlanId.vlanId(ASSIGNED_VLAN_NO_SUBNET);
1012 - } else {
1013 - outvlan = getSubnetAssignedVlanId(deviceId, subnet);
1014 - }
1015 -
1016 - // match rule
1017 - TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
1018 - sbuilder.matchEthDst(mac);
1019 - /*
1020 - * Note: for untagged packets, match on the assigned VLAN.
1021 - * for tagged packets, match on its incoming VLAN.
1022 - */
1023 - if (vlanId.equals(VlanId.NONE)) {
1024 - sbuilder.matchVlanId(outvlan);
1025 - } else {
1026 - sbuilder.matchVlanId(vlanId);
1027 - }
1028 -
1029 - TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
1030 - tbuilder.immediate().popVlan();
1031 - tbuilder.immediate().setOutput(outport);
1032 -
1033 - // for switch pipelines that need it, provide outgoing vlan as metadata
1034 - TrafficSelector meta = DefaultTrafficSelector.builder()
1035 - .matchVlanId(outvlan).build();
1036 -
1037 - // All forwarding is via Groups. Drivers can re-purpose to flow-actions if needed.
1038 - int portNextObjId = getPortNextObjectiveId(deviceId, outport,
1039 - tbuilder.build(),
1040 - meta);
1041 -
1042 - return DefaultForwardingObjective.builder()
1043 - .withFlag(ForwardingObjective.Flag.SPECIFIC)
1044 - .withSelector(sbuilder.build())
1045 - .nextStep(portNextObjId)
1046 - .withPriority(100)
1047 - .fromApp(appId)
1048 - .makePermanent();
1049 - }
1050 -
1051 - private void processHostAddedEvent(HostEvent event) {
1052 - MacAddress mac = event.subject().mac();
1053 - VlanId vlanId = event.subject().vlan();
1054 - DeviceId deviceId = event.subject().location().deviceId();
1055 - PortNumber port = event.subject().location().port();
1056 - Set<IpAddress> ips = event.subject().ipAddresses();
1057 - log.info("Host {}/{} is added at {}:{}", mac, vlanId, deviceId, port);
1058 -
1059 - if (!deviceConfiguration.suppressHost()
1060 - .contains(new ConnectPoint(deviceId, port))) {
1061 - // Populate bridging table entry
1062 - log.debug("Populate L2 table entry for host {} at {}:{}",
1063 - mac, deviceId, port);
1064 - ForwardingObjective.Builder fob =
1065 - getForwardingObjectiveBuilder(deviceId, mac, vlanId, port);
1066 - flowObjectiveService.forward(deviceId, fob.add(
1067 - new BridgingTableObjectiveContext(mac, vlanId)
1068 - ));
1069 -
1070 - // Populate IP table entry
1071 - ips.forEach(ip -> {
1072 - if (ip.isIp4()) {
1073 - routingRulePopulator.populateIpRuleForHost(
1074 - deviceId, ip.getIp4Address(), mac, port);
1075 - }
1076 - });
1077 - }
1078 - }
1079 -
1080 - private void processHostRemoveEvent(HostEvent event) {
1081 - MacAddress mac = event.subject().mac();
1082 - VlanId vlanId = event.subject().vlan();
1083 - DeviceId deviceId = event.subject().location().deviceId();
1084 - PortNumber port = event.subject().location().port();
1085 - Set<IpAddress> ips = event.subject().ipAddresses();
1086 - log.debug("Host {}/{} is removed from {}:{}", mac, vlanId, deviceId, port);
1087 -
1088 - if (!deviceConfiguration.suppressHost()
1089 - .contains(new ConnectPoint(deviceId, port))) {
1090 - // Revoke bridging table entry
1091 - ForwardingObjective.Builder fob =
1092 - getForwardingObjectiveBuilder(deviceId, mac, vlanId, port);
1093 - flowObjectiveService.forward(deviceId, fob.remove(
1094 - new BridgingTableObjectiveContext(mac, vlanId)
1095 - ));
1096 -
1097 - // Revoke IP table entry
1098 - ips.forEach(ip -> {
1099 - if (ip.isIp4()) {
1100 - routingRulePopulator.revokeIpRuleForHost(
1101 - deviceId, ip.getIp4Address(), mac, port);
1102 - }
1103 - });
1104 - }
1105 - }
1106 -
1107 - private void processHostMovedEvent(HostEvent event) {
1108 - MacAddress mac = event.subject().mac();
1109 - VlanId vlanId = event.subject().vlan();
1110 - DeviceId prevDeviceId = event.prevSubject().location().deviceId();
1111 - PortNumber prevPort = event.prevSubject().location().port();
1112 - Set<IpAddress> prevIps = event.prevSubject().ipAddresses();
1113 - DeviceId newDeviceId = event.subject().location().deviceId();
1114 - PortNumber newPort = event.subject().location().port();
1115 - Set<IpAddress> newIps = event.subject().ipAddresses();
1116 - log.debug("Host {}/{} is moved from {}:{} to {}:{}",
1117 - mac, vlanId, prevDeviceId, prevPort, newDeviceId, newPort);
1118 -
1119 - if (!deviceConfiguration.suppressHost()
1120 - .contains(new ConnectPoint(prevDeviceId, prevPort))) {
1121 - // Revoke previous bridging table entry
1122 - ForwardingObjective.Builder prevFob =
1123 - getForwardingObjectiveBuilder(prevDeviceId, mac, vlanId, prevPort);
1124 - flowObjectiveService.forward(prevDeviceId, prevFob.remove(
1125 - new BridgingTableObjectiveContext(mac, vlanId)
1126 - ));
1127 -
1128 - // Revoke previous IP table entry
1129 - prevIps.forEach(ip -> {
1130 - if (ip.isIp4()) {
1131 - routingRulePopulator.revokeIpRuleForHost(
1132 - prevDeviceId, ip.getIp4Address(), mac, prevPort);
1133 - }
1134 - });
1135 - }
1136 -
1137 - if (!deviceConfiguration.suppressHost()
1138 - .contains(new ConnectPoint(newDeviceId, newPort))) {
1139 - // Populate new bridging table entry
1140 - ForwardingObjective.Builder newFob =
1141 - getForwardingObjectiveBuilder(newDeviceId, mac, vlanId, newPort);
1142 - flowObjectiveService.forward(newDeviceId, newFob.add(
1143 - new BridgingTableObjectiveContext(mac, vlanId)
1144 - ));
1145 -
1146 - // Populate new IP table entry
1147 - newIps.forEach(ip -> {
1148 - if (ip.isIp4()) {
1149 - routingRulePopulator.populateIpRuleForHost(
1150 - newDeviceId, ip.getIp4Address(), mac, newPort);
1151 - }
1152 - });
1153 - }
1154 - }
1155 -
1156 - private void processHostUpdatedEvent(HostEvent event) {
1157 - MacAddress mac = event.subject().mac();
1158 - VlanId vlanId = event.subject().vlan();
1159 - DeviceId prevDeviceId = event.prevSubject().location().deviceId();
1160 - PortNumber prevPort = event.prevSubject().location().port();
1161 - Set<IpAddress> prevIps = event.prevSubject().ipAddresses();
1162 - DeviceId newDeviceId = event.subject().location().deviceId();
1163 - PortNumber newPort = event.subject().location().port();
1164 - Set<IpAddress> newIps = event.subject().ipAddresses();
1165 - log.debug("Host {}/{} is updated", mac, vlanId);
1166 -
1167 - if (!deviceConfiguration.suppressHost()
1168 - .contains(new ConnectPoint(prevDeviceId, prevPort))) {
1169 - // Revoke previous IP table entry
1170 - prevIps.forEach(ip -> {
1171 - if (ip.isIp4()) {
1172 - routingRulePopulator.revokeIpRuleForHost(
1173 - prevDeviceId, ip.getIp4Address(), mac, prevPort);
1174 - }
1175 - });
1176 - }
1177 -
1178 - if (!deviceConfiguration.suppressHost()
1179 - .contains(new ConnectPoint(newDeviceId, newPort))) {
1180 - // Populate new IP table entry
1181 - newIps.forEach(ip -> {
1182 - if (ip.isIp4()) {
1183 - routingRulePopulator.populateIpRuleForHost(
1184 - newDeviceId, ip.getIp4Address(), mac, newPort);
1185 - }
1186 - });
1187 - }
1188 - }
1189 -
1190 @Override 971 @Override
1191 public void event(HostEvent event) { 972 public void event(HostEvent event) {
1192 // Do not proceed without mastership 973 // Do not proceed without mastership
...@@ -1197,16 +978,16 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -1197,16 +978,16 @@ public class SegmentRoutingManager implements SegmentRoutingService {
1197 978
1198 switch (event.type()) { 979 switch (event.type()) {
1199 case HOST_ADDED: 980 case HOST_ADDED:
1200 - processHostAddedEvent(event); 981 + hostHandler.processHostAddedEvent(event);
1201 break; 982 break;
1202 case HOST_MOVED: 983 case HOST_MOVED:
1203 - processHostMovedEvent(event); 984 + hostHandler.processHostMovedEvent(event);
1204 break; 985 break;
1205 case HOST_REMOVED: 986 case HOST_REMOVED:
1206 - processHostRemoveEvent(event); 987 + hostHandler.processHostRemoveEvent(event);
1207 break; 988 break;
1208 case HOST_UPDATED: 989 case HOST_UPDATED:
1209 - processHostUpdatedEvent(event); 990 + hostHandler.processHostUpdatedEvent(event);
1210 break; 991 break;
1211 default: 992 default:
1212 log.warn("Unsupported host event type: {}", event.type()); 993 log.warn("Unsupported host event type: {}", event.type());
...@@ -1220,13 +1001,13 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -1220,13 +1001,13 @@ public class SegmentRoutingManager implements SegmentRoutingService {
1220 public void event(McastEvent event) { 1001 public void event(McastEvent event) {
1221 switch (event.type()) { 1002 switch (event.type()) {
1222 case SOURCE_ADDED: 1003 case SOURCE_ADDED:
1223 - mcastEventHandler.processSourceAdded(event); 1004 + mcastHandler.processSourceAdded(event);
1224 break; 1005 break;
1225 case SINK_ADDED: 1006 case SINK_ADDED:
1226 - mcastEventHandler.processSinkAdded(event); 1007 + mcastHandler.processSinkAdded(event);
1227 break; 1008 break;
1228 case SINK_REMOVED: 1009 case SINK_REMOVED:
1229 - mcastEventHandler.processSinkRemoved(event); 1010 + mcastHandler.processSinkRemoved(event);
1230 break; 1011 break;
1231 case ROUTE_ADDED: 1012 case ROUTE_ADDED:
1232 case ROUTE_REMOVED: 1013 case ROUTE_REMOVED:
...@@ -1235,36 +1016,4 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -1235,36 +1016,4 @@ public class SegmentRoutingManager implements SegmentRoutingService {
1235 } 1016 }
1236 } 1017 }
1237 } 1018 }
1238 -
1239 - private static class BridgingTableObjectiveContext implements ObjectiveContext {
1240 - final MacAddress mac;
1241 - final VlanId vlanId;
1242 -
1243 - BridgingTableObjectiveContext(MacAddress mac, VlanId vlanId) {
1244 - this.mac = mac;
1245 - this.vlanId = vlanId;
1246 - }
1247 -
1248 - @Override
1249 - public void onSuccess(Objective objective) {
1250 - if (objective.op() == Objective.Operation.ADD) {
1251 - log.debug("Successfully populate bridging table entry for {}/{}",
1252 - mac, vlanId);
1253 - } else {
1254 - log.debug("Successfully revoke bridging table entry for {}/{}",
1255 - mac, vlanId);
1256 - }
1257 - }
1258 -
1259 - @Override
1260 - public void onError(Objective objective, ObjectiveError error) {
1261 - if (objective.op() == Objective.Operation.ADD) {
1262 - log.debug("Fail to populate bridging table entry for {}/{}. {}",
1263 - mac, vlanId, error);
1264 - } else {
1265 - log.debug("Fail to revoke bridging table entry for {}/{}. {}",
1266 - mac, vlanId, error);
1267 - }
1268 - }
1269 - }
1270 } 1019 }
......
...@@ -53,6 +53,10 @@ import org.onosproject.net.link.LinkService; ...@@ -53,6 +53,10 @@ import org.onosproject.net.link.LinkService;
53 import org.onosproject.segmentrouting.SegmentRoutingManager; 53 import org.onosproject.segmentrouting.SegmentRoutingManager;
54 import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; 54 import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
55 import org.onosproject.segmentrouting.config.DeviceProperties; 55 import org.onosproject.segmentrouting.config.DeviceProperties;
56 +import org.onosproject.segmentrouting.storekey.NeighborSetNextObjectiveStoreKey;
57 +import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
58 +import org.onosproject.segmentrouting.storekey.SubnetNextObjectiveStoreKey;
59 +import org.onosproject.segmentrouting.storekey.XConnectNextObjectiveStoreKey;
56 import org.onosproject.store.service.EventuallyConsistentMap; 60 import org.onosproject.store.service.EventuallyConsistentMap;
57 import org.slf4j.Logger; 61 import org.slf4j.Logger;
58 62
......
1 /* 1 /*
2 - * Copyright 2015-present Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.segmentrouting.grouphandler; 17 +package org.onosproject.segmentrouting.storekey;
18 18
19 import org.onlab.packet.IpAddress; 19 import org.onlab.packet.IpAddress;
20 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
......
1 /* 1 /*
2 - * Copyright 2015-present Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -14,11 +14,12 @@ ...@@ -14,11 +14,12 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.segmentrouting.grouphandler; 17 +package org.onosproject.segmentrouting.storekey;
18 18
19 import java.util.Objects; 19 import java.util.Objects;
20 20
21 import org.onosproject.net.DeviceId; 21 import org.onosproject.net.DeviceId;
22 +import org.onosproject.segmentrouting.grouphandler.NeighborSet;
22 23
23 /** 24 /**
24 * Key of Neighborset next objective store. 25 * Key of Neighborset next objective store.
......
1 /* 1 /*
2 - * Copyright 2015-present Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.segmentrouting.grouphandler; 16 +package org.onosproject.segmentrouting.storekey;
17 17
18 import org.onosproject.net.DeviceId; 18 import org.onosproject.net.DeviceId;
19 import org.onosproject.net.PortNumber; 19 import org.onosproject.net.PortNumber;
......
1 /* 1 /*
2 - * Copyright 2015-present Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.segmentrouting; 16 +package org.onosproject.segmentrouting.storekey;
17 17
18 import java.util.Objects; 18 import java.util.Objects;
19 19
......
1 /* 1 /*
2 - * Copyright 2015-present Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.segmentrouting.grouphandler; 17 +package org.onosproject.segmentrouting.storekey;
18 18
19 import org.onlab.packet.IpPrefix; 19 import org.onlab.packet.IpPrefix;
20 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.segmentrouting.grouphandler; 17 +package org.onosproject.segmentrouting.storekey;
18 18
19 import org.onlab.packet.VlanId; 19 import org.onlab.packet.VlanId;
20 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
......
...@@ -13,43 +13,8 @@ ...@@ -13,43 +13,8 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.segmentrouting;
17 -
18 -import org.onosproject.net.DeviceId;
19 -import org.onosproject.net.flowobjective.Objective;
20 -import org.onosproject.net.flowobjective.ObjectiveContext;
21 -import org.onosproject.net.flowobjective.ObjectiveError;
22 -import org.slf4j.Logger;
23 -import org.slf4j.LoggerFactory;
24 16
25 /** 17 /**
26 - * Segment Routing Flow Objective Context. 18 + * Key data structure of various stores used by Segment Routing.
27 */ 19 */
28 -public class SRObjectiveContext implements ObjectiveContext { 20 +package org.onosproject.segmentrouting.storekey;
29 - enum ObjectiveType {
30 - FILTER,
31 - FORWARDING
32 - }
33 - private final DeviceId deviceId;
34 - private final ObjectiveType type;
35 -
36 - private static final Logger log = LoggerFactory
37 - .getLogger(SegmentRoutingManager.class);
38 -
39 - SRObjectiveContext(DeviceId deviceId, ObjectiveType type) {
40 - this.deviceId = deviceId;
41 - this.type = type;
42 - }
43 - @Override
44 - public void onSuccess(Objective objective) {
45 - log.debug("{} objective operation successful in device {}",
46 - type.name(), deviceId);
47 - }
48 -
49 - @Override
50 - public void onError(Objective objective, ObjectiveError error) {
51 - log.warn("{} objective {} operation failed with error: {} in device {}",
52 - type.name(), objective, error, deviceId);
53 - }
54 -}
55 -
...\ No newline at end of file ...\ No newline at end of file
......