Committed by
Gerrit Code Review
- Adds error handling for Segment routing CLI
- Removes SegmentRoutingManager reference from TunnelHandler and PolicyHandler Change-Id: Iab6acdc489d41a63ebf6b37b65d0e82448a8b25a
Showing
8 changed files
with
195 additions
and
102 deletions
... | @@ -19,10 +19,12 @@ package org.onosproject.segmentrouting; | ... | @@ -19,10 +19,12 @@ package org.onosproject.segmentrouting; |
19 | import org.onlab.packet.Ethernet; | 19 | import org.onlab.packet.Ethernet; |
20 | import org.onlab.packet.IpPrefix; | 20 | import org.onlab.packet.IpPrefix; |
21 | import org.onosproject.cli.net.IpProtocol; | 21 | import org.onosproject.cli.net.IpProtocol; |
22 | +import org.onosproject.core.ApplicationId; | ||
22 | import org.onosproject.net.DeviceId; | 23 | import org.onosproject.net.DeviceId; |
23 | import org.onosproject.net.flow.DefaultTrafficSelector; | 24 | import org.onosproject.net.flow.DefaultTrafficSelector; |
24 | import org.onosproject.net.flow.TrafficSelector; | 25 | import org.onosproject.net.flow.TrafficSelector; |
25 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; | 26 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
27 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
26 | import org.onosproject.net.flowobjective.ForwardingObjective; | 28 | import org.onosproject.net.flowobjective.ForwardingObjective; |
27 | import org.onosproject.store.service.EventuallyConsistentMap; | 29 | import org.onosproject.store.service.EventuallyConsistentMap; |
28 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
... | @@ -39,19 +41,38 @@ public class PolicyHandler { | ... | @@ -39,19 +41,38 @@ public class PolicyHandler { |
39 | 41 | ||
40 | protected final Logger log = getLogger(getClass()); | 42 | protected final Logger log = getLogger(getClass()); |
41 | 43 | ||
42 | - // FIXME: references to manager components should be avoided | 44 | + private ApplicationId appId; |
43 | - private final SegmentRoutingManager srManager; | 45 | + private DeviceConfiguration deviceConfiguration; |
46 | + private FlowObjectiveService flowObjectiveService; | ||
47 | + private TunnelHandler tunnelHandler; | ||
44 | private final EventuallyConsistentMap<String, Policy> policyStore; | 48 | private final EventuallyConsistentMap<String, Policy> policyStore; |
45 | 49 | ||
50 | + public enum Result { | ||
51 | + SUCCESS, | ||
52 | + POLICY_EXISTS, | ||
53 | + ID_EXISTS, | ||
54 | + TUNNEL_NOT_FOUND, | ||
55 | + POLICY_NOT_FOUND, | ||
56 | + UNSUPPORTED_TYPE | ||
57 | + } | ||
58 | + | ||
46 | /** | 59 | /** |
47 | * Creates a reference. | 60 | * Creates a reference. |
48 | * | 61 | * |
49 | - * @param srManager segment routing manager | 62 | + * @param appId segment routing application ID |
63 | + * @param deviceConfiguration DeviceConfiguration reference | ||
64 | + * @param flowObjectiveService FlowObjectiveService reference | ||
50 | * @param policyStore policy store | 65 | * @param policyStore policy store |
51 | */ | 66 | */ |
52 | - public PolicyHandler(SegmentRoutingManager srManager, | 67 | + public PolicyHandler(ApplicationId appId, |
68 | + DeviceConfiguration deviceConfiguration, | ||
69 | + FlowObjectiveService flowObjectiveService, | ||
70 | + TunnelHandler tunnelHandler, | ||
53 | EventuallyConsistentMap<String, Policy> policyStore) { | 71 | EventuallyConsistentMap<String, Policy> policyStore) { |
54 | - this.srManager = srManager; | 72 | + this.appId = appId; |
73 | + this.deviceConfiguration = deviceConfiguration; | ||
74 | + this.flowObjectiveService = flowObjectiveService; | ||
75 | + this.tunnelHandler = tunnelHandler; | ||
55 | this.policyStore = policyStore; | 76 | this.policyStore = policyStore; |
56 | } | 77 | } |
57 | 78 | ||
... | @@ -70,79 +91,89 @@ public class PolicyHandler { | ... | @@ -70,79 +91,89 @@ public class PolicyHandler { |
70 | 91 | ||
71 | /** | 92 | /** |
72 | * Creates a policy using the policy information given. | 93 | * Creates a policy using the policy information given. |
73 | - * | 94 | + * @param policy policy reference to create |
74 | - * @param policy policy reference to create | 95 | + * @return ID_EXISTS if the same policy ID exists, |
96 | + * POLICY_EXISTS if the same policy exists, TUNNEL_NOT_FOUND if the tunnel | ||
97 | + * does not exists, UNSUPPORTED_TYPE if the policy type is not supported, | ||
98 | + * SUCCESS if the policy is created successfully | ||
75 | */ | 99 | */ |
76 | - public void createPolicy(Policy policy) { | 100 | + public Result createPolicy(Policy policy) { |
77 | 101 | ||
78 | if (policyStore.containsKey(policy.id())) { | 102 | if (policyStore.containsKey(policy.id())) { |
79 | log.warn("The policy id {} exists already", policy.id()); | 103 | log.warn("The policy id {} exists already", policy.id()); |
80 | - return; | 104 | + return Result.ID_EXISTS; |
81 | } | 105 | } |
82 | 106 | ||
83 | if (policyStore.containsValue(policy)) { | 107 | if (policyStore.containsValue(policy)) { |
84 | log.warn("The same policy exists already"); | 108 | log.warn("The same policy exists already"); |
85 | - return; | 109 | + return Result.POLICY_EXISTS; |
86 | } | 110 | } |
87 | 111 | ||
88 | if (policy.type() == Policy.Type.TUNNEL_FLOW) { | 112 | if (policy.type() == Policy.Type.TUNNEL_FLOW) { |
89 | 113 | ||
90 | TunnelPolicy tunnelPolicy = (TunnelPolicy) policy; | 114 | TunnelPolicy tunnelPolicy = (TunnelPolicy) policy; |
91 | - Tunnel tunnel = srManager.getTunnel(tunnelPolicy.tunnelId()); | 115 | + Tunnel tunnel = tunnelHandler.getTunnel(tunnelPolicy.tunnelId()); |
92 | if (tunnel == null) { | 116 | if (tunnel == null) { |
93 | - log.error("Tunnel {} does not exists"); | 117 | + return Result.TUNNEL_NOT_FOUND; |
94 | - return; | ||
95 | } | 118 | } |
96 | 119 | ||
97 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective | 120 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
98 | .builder() | 121 | .builder() |
99 | - .fromApp(srManager.appId) | 122 | + .fromApp(appId) |
100 | .makePermanent() | 123 | .makePermanent() |
101 | .nextStep(tunnel.groupId()) | 124 | .nextStep(tunnel.groupId()) |
102 | .withPriority(tunnelPolicy.priority()) | 125 | .withPriority(tunnelPolicy.priority()) |
103 | .withSelector(buildSelector(policy)) | 126 | .withSelector(buildSelector(policy)) |
104 | .withFlag(ForwardingObjective.Flag.VERSATILE); | 127 | .withFlag(ForwardingObjective.Flag.VERSATILE); |
105 | 128 | ||
106 | - DeviceId source = srManager.deviceConfiguration.getDeviceId(tunnel.labelIds().get(0)); | 129 | + DeviceId source = deviceConfiguration.getDeviceId(tunnel.labelIds().get(0)); |
107 | - srManager.flowObjectiveService.forward(source, fwdBuilder.add()); | 130 | + flowObjectiveService.forward(source, fwdBuilder.add()); |
108 | 131 | ||
109 | } else { | 132 | } else { |
110 | log.warn("Policy type {} is not supported yet.", policy.type()); | 133 | log.warn("Policy type {} is not supported yet.", policy.type()); |
134 | + return Result.UNSUPPORTED_TYPE; | ||
111 | } | 135 | } |
112 | 136 | ||
113 | policyStore.put(policy.id(), policy); | 137 | policyStore.put(policy.id(), policy); |
138 | + | ||
139 | + return Result.SUCCESS; | ||
114 | } | 140 | } |
115 | 141 | ||
116 | /** | 142 | /** |
117 | * Removes the policy given. | 143 | * Removes the policy given. |
118 | * | 144 | * |
119 | * @param policyInfo policy information to remove | 145 | * @param policyInfo policy information to remove |
146 | + * @return POLICY_NOT_FOUND if the policy to remove does not exists, | ||
147 | + * SUCCESS if it is removed successfully | ||
120 | */ | 148 | */ |
121 | - public void removePolicy(Policy policyInfo) { | 149 | + public Result removePolicy(Policy policyInfo) { |
122 | 150 | ||
123 | if (policyStore.get(policyInfo.id()) != null) { | 151 | if (policyStore.get(policyInfo.id()) != null) { |
124 | Policy policy = policyStore.get(policyInfo.id()); | 152 | Policy policy = policyStore.get(policyInfo.id()); |
125 | if (policy.type() == Policy.Type.TUNNEL_FLOW) { | 153 | if (policy.type() == Policy.Type.TUNNEL_FLOW) { |
126 | TunnelPolicy tunnelPolicy = (TunnelPolicy) policy; | 154 | TunnelPolicy tunnelPolicy = (TunnelPolicy) policy; |
127 | - Tunnel tunnel = srManager.getTunnel(tunnelPolicy.tunnelId()); | 155 | + Tunnel tunnel = tunnelHandler.getTunnel(tunnelPolicy.tunnelId()); |
128 | 156 | ||
129 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective | 157 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
130 | .builder() | 158 | .builder() |
131 | - .fromApp(srManager.appId) | 159 | + .fromApp(appId) |
132 | .makePermanent() | 160 | .makePermanent() |
133 | .withSelector(buildSelector(policy)) | 161 | .withSelector(buildSelector(policy)) |
134 | .withPriority(tunnelPolicy.priority()) | 162 | .withPriority(tunnelPolicy.priority()) |
135 | .nextStep(tunnel.groupId()) | 163 | .nextStep(tunnel.groupId()) |
136 | .withFlag(ForwardingObjective.Flag.VERSATILE); | 164 | .withFlag(ForwardingObjective.Flag.VERSATILE); |
137 | 165 | ||
138 | - DeviceId source = srManager.deviceConfiguration.getDeviceId(tunnel.labelIds().get(0)); | 166 | + DeviceId source = deviceConfiguration.getDeviceId(tunnel.labelIds().get(0)); |
139 | - srManager.flowObjectiveService.forward(source, fwdBuilder.remove()); | 167 | + flowObjectiveService.forward(source, fwdBuilder.remove()); |
140 | 168 | ||
141 | policyStore.remove(policyInfo.id()); | 169 | policyStore.remove(policyInfo.id()); |
142 | } | 170 | } |
143 | } else { | 171 | } else { |
144 | log.warn("Policy {} was not found", policyInfo.id()); | 172 | log.warn("Policy {} was not found", policyInfo.id()); |
173 | + return Result.POLICY_NOT_FOUND; | ||
145 | } | 174 | } |
175 | + | ||
176 | + return Result.SUCCESS; | ||
146 | } | 177 | } |
147 | 178 | ||
148 | 179 | ... | ... |
... | @@ -199,8 +199,10 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -199,8 +199,10 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
199 | ipHandler = new IpHandler(this); | 199 | ipHandler = new IpHandler(this); |
200 | routingRulePopulator = new RoutingRulePopulator(this); | 200 | routingRulePopulator = new RoutingRulePopulator(this); |
201 | defaultRoutingHandler = new DefaultRoutingHandler(this); | 201 | defaultRoutingHandler = new DefaultRoutingHandler(this); |
202 | - tunnelHandler = new TunnelHandler(this, tunnelStore); | 202 | + tunnelHandler = new TunnelHandler(linkService, deviceConfiguration, |
203 | - policyHandler = new PolicyHandler(this, policyStore); | 203 | + groupHandlerMap, tunnelStore); |
204 | + policyHandler = new PolicyHandler(appId, deviceConfiguration, | ||
205 | + flowObjectiveService, tunnelHandler, policyStore); | ||
204 | 206 | ||
205 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); | 207 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); |
206 | linkService.addListener(new InternalLinkListener()); | 208 | linkService.addListener(new InternalLinkListener()); |
... | @@ -240,33 +242,32 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -240,33 +242,32 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
240 | } | 242 | } |
241 | 243 | ||
242 | @Override | 244 | @Override |
243 | - public void createTunnel(Tunnel tunnel) { | 245 | + public TunnelHandler.Result createTunnel(Tunnel tunnel) { |
244 | - tunnelHandler.createTunnel(tunnel); | 246 | + return tunnelHandler.createTunnel(tunnel); |
245 | } | 247 | } |
246 | 248 | ||
247 | @Override | 249 | @Override |
248 | - public void removeTunnel(Tunnel tunnel) { | 250 | + public TunnelHandler.Result removeTunnel(Tunnel tunnel) { |
249 | for (Policy policy: policyHandler.getPolicies()) { | 251 | for (Policy policy: policyHandler.getPolicies()) { |
250 | if (policy.type() == Policy.Type.TUNNEL_FLOW) { | 252 | if (policy.type() == Policy.Type.TUNNEL_FLOW) { |
251 | TunnelPolicy tunnelPolicy = (TunnelPolicy) policy; | 253 | TunnelPolicy tunnelPolicy = (TunnelPolicy) policy; |
252 | if (tunnelPolicy.tunnelId().equals(tunnel.id())) { | 254 | if (tunnelPolicy.tunnelId().equals(tunnel.id())) { |
253 | log.warn("Cannot remove the tunnel used by a policy"); | 255 | log.warn("Cannot remove the tunnel used by a policy"); |
254 | - return; | 256 | + return TunnelHandler.Result.TUNNEL_IN_USE; |
255 | } | 257 | } |
256 | } | 258 | } |
257 | } | 259 | } |
258 | - tunnelHandler.removeTunnel(tunnel); | 260 | + return tunnelHandler.removeTunnel(tunnel); |
259 | } | 261 | } |
260 | 262 | ||
261 | @Override | 263 | @Override |
262 | - public void removePolicy(Policy policy) { | 264 | + public PolicyHandler.Result removePolicy(Policy policy) { |
263 | - policyHandler.removePolicy(policy); | 265 | + return policyHandler.removePolicy(policy); |
264 | - | ||
265 | } | 266 | } |
266 | 267 | ||
267 | @Override | 268 | @Override |
268 | - public void createPolicy(Policy policy) { | 269 | + public PolicyHandler.Result createPolicy(Policy policy) { |
269 | - policyHandler.createPolicy(policy); | 270 | + return policyHandler.createPolicy(policy); |
270 | } | 271 | } |
271 | 272 | ||
272 | @Override | 273 | @Override |
... | @@ -319,35 +320,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -319,35 +320,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
319 | } | 320 | } |
320 | } | 321 | } |
321 | 322 | ||
322 | - /** | ||
323 | - * Checks if the next objective ID (group) for the neighbor set exists or not in the device. | ||
324 | - * | ||
325 | - * @param deviceId Device ID to check | ||
326 | - * @param ns neighbor set to check | ||
327 | - * @return true if it exists, false otherwise | ||
328 | - */ | ||
329 | - public boolean hasNextObjectiveId(DeviceId deviceId, NeighborSet ns) { | ||
330 | - if (groupHandlerMap.get(deviceId) != null) { | ||
331 | - log.trace("getNextObjectiveId query in device {}", deviceId); | ||
332 | - return groupHandlerMap | ||
333 | - .get(deviceId).hasNextObjectiveId(ns); | ||
334 | - } else { | ||
335 | - log.warn("getNextObjectiveId query in device {} not found", deviceId); | ||
336 | - return false; | ||
337 | - } | ||
338 | - } | ||
339 | - | ||
340 | - /** | ||
341 | - * Removes the next objective ID. | ||
342 | - * | ||
343 | - * @param deviceId Device ID | ||
344 | - * @param objectiveId next objective ID to remove | ||
345 | - * @return true, if succeeds, false otherwise | ||
346 | - */ | ||
347 | - public boolean removeNextObjective(DeviceId deviceId, int objectiveId) { | ||
348 | - return groupHandlerMap.get(deviceId).removeGroup(objectiveId); | ||
349 | - } | ||
350 | - | ||
351 | private class InternalPacketProcessor implements PacketProcessor { | 323 | private class InternalPacketProcessor implements PacketProcessor { |
352 | 324 | ||
353 | @Override | 325 | @Override | ... | ... |
... | @@ -33,8 +33,12 @@ public interface SegmentRoutingService { | ... | @@ -33,8 +33,12 @@ public interface SegmentRoutingService { |
33 | * Creates a tunnel. | 33 | * Creates a tunnel. |
34 | * | 34 | * |
35 | * @param tunnel tunnel reference to create | 35 | * @param tunnel tunnel reference to create |
36 | + * @return WRONG_PATH if the tunnel path is wrong, ID_EXISTS if the tunnel ID | ||
37 | + * exists already, TUNNEL_EXISTS if the same tunnel exists, INTERNAL_ERROR | ||
38 | + * if the tunnel creation failed internally, SUCCESS if the tunnel is created | ||
39 | + * successfully | ||
36 | */ | 40 | */ |
37 | - void createTunnel(Tunnel tunnel); | 41 | + TunnelHandler.Result createTunnel(Tunnel tunnel); |
38 | 42 | ||
39 | /** | 43 | /** |
40 | * Returns all policies. | 44 | * Returns all policies. |
... | @@ -47,20 +51,29 @@ public interface SegmentRoutingService { | ... | @@ -47,20 +51,29 @@ public interface SegmentRoutingService { |
47 | * Creates a policy. | 51 | * Creates a policy. |
48 | * | 52 | * |
49 | * @param policy policy reference to create | 53 | * @param policy policy reference to create |
54 | + * @return ID_EXISTS if the same policy ID exists, | ||
55 | + * POLICY_EXISTS if the same policy exists, TUNNEL_NOT_FOUND if the tunnel | ||
56 | + * does not exists, UNSUPPORTED_TYPE if the policy type is not supported, | ||
57 | + * SUCCESS if the policy is created successfully. | ||
50 | */ | 58 | */ |
51 | - void createPolicy(Policy policy); | 59 | + PolicyHandler.Result createPolicy(Policy policy); |
52 | 60 | ||
53 | /** | 61 | /** |
54 | * Removes a tunnel. | 62 | * Removes a tunnel. |
55 | * | 63 | * |
56 | * @param tunnel tunnel reference to remove | 64 | * @param tunnel tunnel reference to remove |
65 | + * @return TUNNEL_NOT_FOUND if the tunnel to remove does not exists, | ||
66 | + * INTERNAL_ERROR if the tunnel creation failed internally, SUCCESS | ||
67 | + * if the tunnel is created successfully. | ||
57 | */ | 68 | */ |
58 | - void removeTunnel(Tunnel tunnel); | 69 | + TunnelHandler.Result removeTunnel(Tunnel tunnel); |
59 | 70 | ||
60 | /** | 71 | /** |
61 | * Removes a policy. | 72 | * Removes a policy. |
62 | * | 73 | * |
63 | * @param policy policy reference to remove | 74 | * @param policy policy reference to remove |
75 | + * @return POLICY_NOT_FOUND if the policy to remove does not exists, | ||
76 | + * SUCCESS if it is removed successfully | ||
64 | */ | 77 | */ |
65 | - void removePolicy(Policy policy); | 78 | + PolicyHandler.Result removePolicy(Policy policy); |
66 | } | 79 | } | ... | ... |
... | @@ -17,6 +17,8 @@ package org.onosproject.segmentrouting; | ... | @@ -17,6 +17,8 @@ package org.onosproject.segmentrouting; |
17 | 17 | ||
18 | import org.onosproject.net.DeviceId; | 18 | import org.onosproject.net.DeviceId; |
19 | import org.onosproject.net.Link; | 19 | import org.onosproject.net.Link; |
20 | +import org.onosproject.net.link.LinkService; | ||
21 | +import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; | ||
20 | import org.onosproject.segmentrouting.grouphandler.NeighborSet; | 22 | import org.onosproject.segmentrouting.grouphandler.NeighborSet; |
21 | import org.onosproject.store.service.EventuallyConsistentMap; | 23 | import org.onosproject.store.service.EventuallyConsistentMap; |
22 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
... | @@ -24,9 +26,9 @@ import org.slf4j.Logger; | ... | @@ -24,9 +26,9 @@ import org.slf4j.Logger; |
24 | import java.util.ArrayList; | 26 | import java.util.ArrayList; |
25 | import java.util.HashSet; | 27 | import java.util.HashSet; |
26 | import java.util.List; | 28 | import java.util.List; |
29 | +import java.util.Map; | ||
27 | import java.util.Set; | 30 | import java.util.Set; |
28 | 31 | ||
29 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
30 | import static org.slf4j.LoggerFactory.getLogger; | 32 | import static org.slf4j.LoggerFactory.getLogger; |
31 | 33 | ||
32 | /** | 34 | /** |
... | @@ -35,14 +37,28 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -35,14 +37,28 @@ import static org.slf4j.LoggerFactory.getLogger; |
35 | public class TunnelHandler { | 37 | public class TunnelHandler { |
36 | protected final Logger log = getLogger(getClass()); | 38 | protected final Logger log = getLogger(getClass()); |
37 | 39 | ||
38 | - private final SegmentRoutingManager srManager; | ||
39 | private final DeviceConfiguration config; | 40 | private final DeviceConfiguration config; |
40 | private final EventuallyConsistentMap<String, Tunnel> tunnelStore; | 41 | private final EventuallyConsistentMap<String, Tunnel> tunnelStore; |
42 | + private Map<DeviceId, DefaultGroupHandler> groupHandlerMap; | ||
43 | + private LinkService linkService; | ||
44 | + | ||
45 | + public enum Result { | ||
46 | + SUCCESS, | ||
47 | + WRONG_PATH, | ||
48 | + TUNNEL_EXISTS, | ||
49 | + ID_EXISTS, | ||
50 | + TUNNEL_NOT_FOUND, | ||
51 | + TUNNEL_IN_USE, | ||
52 | + INTERNAL_ERROR | ||
53 | + } | ||
41 | 54 | ||
42 | - public TunnelHandler(SegmentRoutingManager srm, | 55 | + public TunnelHandler(LinkService linkService, |
56 | + DeviceConfiguration deviceConfiguration, | ||
57 | + Map<DeviceId, DefaultGroupHandler> groupHandlerMap, | ||
43 | EventuallyConsistentMap<String, Tunnel> tunnelStore) { | 58 | EventuallyConsistentMap<String, Tunnel> tunnelStore) { |
44 | - this.srManager = checkNotNull(srm); | 59 | + this.linkService = linkService; |
45 | - this.config = srm.deviceConfiguration; | 60 | + this.config = deviceConfiguration; |
61 | + this.groupHandlerMap = groupHandlerMap; | ||
46 | this.tunnelStore = tunnelStore; | 62 | this.tunnelStore = tunnelStore; |
47 | } | 63 | } |
48 | 64 | ||
... | @@ -50,60 +66,70 @@ public class TunnelHandler { | ... | @@ -50,60 +66,70 @@ public class TunnelHandler { |
50 | * Creates a tunnel. | 66 | * Creates a tunnel. |
51 | * | 67 | * |
52 | * @param tunnel tunnel reference to create a tunnel | 68 | * @param tunnel tunnel reference to create a tunnel |
53 | - * @return true if creation succeeded | 69 | + * @return WRONG_PATH if the tunnel path is wrong, ID_EXISTS if the tunnel ID |
70 | + * exists already, TUNNEL_EXISTS if the same tunnel exists, INTERNAL_ERROR | ||
71 | + * if the tunnel creation failed internally, SUCCESS if the tunnel is created | ||
72 | + * successfully | ||
54 | */ | 73 | */ |
55 | - public boolean createTunnel(Tunnel tunnel) { | 74 | + public Result createTunnel(Tunnel tunnel) { |
56 | 75 | ||
57 | if (tunnel.labelIds().isEmpty() || tunnel.labelIds().size() < 3) { | 76 | if (tunnel.labelIds().isEmpty() || tunnel.labelIds().size() < 3) { |
58 | log.error("More than one router needs to specified to created a tunnel"); | 77 | log.error("More than one router needs to specified to created a tunnel"); |
59 | - return false; | 78 | + return Result.WRONG_PATH; |
60 | } | 79 | } |
61 | 80 | ||
62 | if (tunnelStore.containsKey(tunnel.id())) { | 81 | if (tunnelStore.containsKey(tunnel.id())) { |
63 | log.warn("The same tunnel ID exists already"); | 82 | log.warn("The same tunnel ID exists already"); |
64 | - return false; | 83 | + return Result.ID_EXISTS; |
65 | } | 84 | } |
66 | 85 | ||
67 | if (tunnelStore.containsValue(tunnel)) { | 86 | if (tunnelStore.containsValue(tunnel)) { |
68 | log.warn("The same tunnel exists already"); | 87 | log.warn("The same tunnel exists already"); |
69 | - return false; | 88 | + return Result.TUNNEL_EXISTS; |
70 | } | 89 | } |
71 | 90 | ||
72 | int groupId = createGroupsForTunnel(tunnel); | 91 | int groupId = createGroupsForTunnel(tunnel); |
73 | if (groupId < 0) { | 92 | if (groupId < 0) { |
74 | log.error("Failed to create groups for the tunnel"); | 93 | log.error("Failed to create groups for the tunnel"); |
75 | - return false; | 94 | + return Result.INTERNAL_ERROR; |
76 | } | 95 | } |
77 | 96 | ||
78 | tunnel.setGroupId(groupId); | 97 | tunnel.setGroupId(groupId); |
79 | tunnelStore.put(tunnel.id(), tunnel); | 98 | tunnelStore.put(tunnel.id(), tunnel); |
80 | 99 | ||
81 | - return true; | 100 | + return Result.SUCCESS; |
82 | } | 101 | } |
83 | 102 | ||
84 | /** | 103 | /** |
85 | * Removes the tunnel with the tunnel ID given. | 104 | * Removes the tunnel with the tunnel ID given. |
86 | * | 105 | * |
87 | * @param tunnelInfo tunnel information to delete tunnels | 106 | * @param tunnelInfo tunnel information to delete tunnels |
107 | + * @return TUNNEL_NOT_FOUND if the tunnel to remove does not exists, | ||
108 | + * INTERNAL_ERROR if the tunnel creation failed internally, SUCCESS | ||
109 | + * if the tunnel is created successfully. | ||
88 | */ | 110 | */ |
89 | - public void removeTunnel(Tunnel tunnelInfo) { | 111 | + public Result removeTunnel(Tunnel tunnelInfo) { |
90 | 112 | ||
91 | Tunnel tunnel = tunnelStore.get(tunnelInfo.id()); | 113 | Tunnel tunnel = tunnelStore.get(tunnelInfo.id()); |
92 | if (tunnel != null) { | 114 | if (tunnel != null) { |
93 | DeviceId deviceId = config.getDeviceId(tunnel.labelIds().get(0)); | 115 | DeviceId deviceId = config.getDeviceId(tunnel.labelIds().get(0)); |
94 | if (tunnel.isAllowedToRemoveGroup()) { | 116 | if (tunnel.isAllowedToRemoveGroup()) { |
95 | - if (srManager.removeNextObjective(deviceId, tunnel.groupId())) { | 117 | + if (groupHandlerMap.get(deviceId).removeGroup(tunnel.groupId())) { |
96 | tunnelStore.remove(tunnel.id()); | 118 | tunnelStore.remove(tunnel.id()); |
97 | } else { | 119 | } else { |
98 | log.error("Failed to remove the tunnel {}", tunnelInfo.id()); | 120 | log.error("Failed to remove the tunnel {}", tunnelInfo.id()); |
121 | + return Result.INTERNAL_ERROR; | ||
99 | } | 122 | } |
100 | } else { | 123 | } else { |
101 | log.debug("The group is not removed because it is being used."); | 124 | log.debug("The group is not removed because it is being used."); |
102 | tunnelStore.remove(tunnel.id()); | 125 | tunnelStore.remove(tunnel.id()); |
103 | } | 126 | } |
104 | } else { | 127 | } else { |
105 | - log.warn("No tunnel found for tunnel ID {}", tunnelInfo.id()); | 128 | + log.error("No tunnel found for tunnel ID {}", tunnelInfo.id()); |
129 | + return Result.TUNNEL_NOT_FOUND; | ||
106 | } | 130 | } |
131 | + | ||
132 | + return Result.SUCCESS; | ||
107 | } | 133 | } |
108 | 134 | ||
109 | /** | 135 | /** |
... | @@ -132,19 +158,21 @@ public class TunnelHandler { | ... | @@ -132,19 +158,21 @@ public class TunnelHandler { |
132 | private int createGroupsForTunnel(Tunnel tunnel) { | 158 | private int createGroupsForTunnel(Tunnel tunnel) { |
133 | 159 | ||
134 | List<Integer> portNumbers; | 160 | List<Integer> portNumbers; |
135 | - | 161 | + final int groupError = -1; |
136 | - int groupId; | ||
137 | 162 | ||
138 | DeviceId deviceId = config.getDeviceId(tunnel.labelIds().get(0)); | 163 | DeviceId deviceId = config.getDeviceId(tunnel.labelIds().get(0)); |
139 | if (deviceId == null) { | 164 | if (deviceId == null) { |
140 | log.warn("No device found for SID {}", tunnel.labelIds().get(0)); | 165 | log.warn("No device found for SID {}", tunnel.labelIds().get(0)); |
141 | - return -1; | 166 | + return groupError; |
167 | + } else if (groupHandlerMap.get(deviceId) == null) { | ||
168 | + log.warn("group handler not found for {}", deviceId); | ||
169 | + return groupError; | ||
142 | } | 170 | } |
143 | Set<DeviceId> deviceIds = new HashSet<>(); | 171 | Set<DeviceId> deviceIds = new HashSet<>(); |
144 | int sid = tunnel.labelIds().get(1); | 172 | int sid = tunnel.labelIds().get(1); |
145 | if (config.isAdjacencySid(deviceId, sid)) { | 173 | if (config.isAdjacencySid(deviceId, sid)) { |
146 | portNumbers = config.getPortsForAdjacencySid(deviceId, sid); | 174 | portNumbers = config.getPortsForAdjacencySid(deviceId, sid); |
147 | - for (Link link: srManager.linkService.getDeviceEgressLinks(deviceId)) { | 175 | + for (Link link: linkService.getDeviceEgressLinks(deviceId)) { |
148 | for (Integer port: portNumbers) { | 176 | for (Integer port: portNumbers) { |
149 | if (link.src().port().toLong() == port) { | 177 | if (link.src().port().toLong() == port) { |
150 | deviceIds.add(link.dst().deviceId()); | 178 | deviceIds.add(link.dst().deviceId()); |
... | @@ -159,14 +187,13 @@ public class TunnelHandler { | ... | @@ -159,14 +187,13 @@ public class TunnelHandler { |
159 | 187 | ||
160 | // If the tunnel reuses any existing groups, then tunnel handler | 188 | // If the tunnel reuses any existing groups, then tunnel handler |
161 | // should not remove the group. | 189 | // should not remove the group. |
162 | - if (srManager.hasNextObjectiveId(deviceId, ns)) { | 190 | + if (groupHandlerMap.get(deviceId).hasNextObjectiveId(ns)) { |
163 | tunnel.allowToRemoveGroup(false); | 191 | tunnel.allowToRemoveGroup(false); |
164 | } else { | 192 | } else { |
165 | tunnel.allowToRemoveGroup(true); | 193 | tunnel.allowToRemoveGroup(true); |
166 | } | 194 | } |
167 | - groupId = srManager.getNextObjectiveId(deviceId, ns); | ||
168 | 195 | ||
169 | - return groupId; | 196 | + return groupHandlerMap.get(deviceId).getNextObjectiveId(ns); |
170 | } | 197 | } |
171 | 198 | ||
172 | } | 199 | } | ... | ... |
... | @@ -19,6 +19,7 @@ import org.apache.karaf.shell.commands.Argument; | ... | @@ -19,6 +19,7 @@ import org.apache.karaf.shell.commands.Argument; |
19 | import org.apache.karaf.shell.commands.Command; | 19 | import org.apache.karaf.shell.commands.Command; |
20 | import org.onosproject.cli.AbstractShellCommand; | 20 | import org.onosproject.cli.AbstractShellCommand; |
21 | import org.onosproject.segmentrouting.Policy; | 21 | import org.onosproject.segmentrouting.Policy; |
22 | +import org.onosproject.segmentrouting.PolicyHandler; | ||
22 | import org.onosproject.segmentrouting.SegmentRoutingService; | 23 | import org.onosproject.segmentrouting.SegmentRoutingService; |
23 | import org.onosproject.segmentrouting.TunnelPolicy; | 24 | import org.onosproject.segmentrouting.TunnelPolicy; |
24 | 25 | ||
... | @@ -31,7 +32,7 @@ public class PolicyAddCommand extends AbstractShellCommand { | ... | @@ -31,7 +32,7 @@ public class PolicyAddCommand extends AbstractShellCommand { |
31 | 32 | ||
32 | // TODO: Need to support skipping some parameters | 33 | // TODO: Need to support skipping some parameters |
33 | 34 | ||
34 | - @Argument(index = 0, name = "policy ID", | 35 | + @Argument(index = 0, name = "ID", |
35 | description = "policy ID", | 36 | description = "policy ID", |
36 | required = true, multiValued = false) | 37 | required = true, multiValued = false) |
37 | String policyId; | 38 | String policyId; |
... | @@ -41,37 +42,37 @@ public class PolicyAddCommand extends AbstractShellCommand { | ... | @@ -41,37 +42,37 @@ public class PolicyAddCommand extends AbstractShellCommand { |
41 | required = true, multiValued = false) | 42 | required = true, multiValued = false) |
42 | int priority; | 43 | int priority; |
43 | 44 | ||
44 | - @Argument(index = 2, name = "src IP", | 45 | + @Argument(index = 2, name = "src_IP", |
45 | description = "src IP", | 46 | description = "src IP", |
46 | required = false, multiValued = false) | 47 | required = false, multiValued = false) |
47 | String srcIp; | 48 | String srcIp; |
48 | 49 | ||
49 | - @Argument(index = 3, name = "src port", | 50 | + @Argument(index = 3, name = "src_port", |
50 | description = "src port", | 51 | description = "src port", |
51 | required = false, multiValued = false) | 52 | required = false, multiValued = false) |
52 | short srcPort; | 53 | short srcPort; |
53 | 54 | ||
54 | - @Argument(index = 4, name = "dst IP", | 55 | + @Argument(index = 4, name = "dst_IP", |
55 | description = "dst IP", | 56 | description = "dst IP", |
56 | required = false, multiValued = false) | 57 | required = false, multiValued = false) |
57 | String dstIp; | 58 | String dstIp; |
58 | 59 | ||
59 | - @Argument(index = 5, name = "dst port", | 60 | + @Argument(index = 5, name = "dst_port", |
60 | description = "dst port", | 61 | description = "dst port", |
61 | required = false, multiValued = false) | 62 | required = false, multiValued = false) |
62 | short dstPort; | 63 | short dstPort; |
63 | 64 | ||
64 | @Argument(index = 6, name = "proto", | 65 | @Argument(index = 6, name = "proto", |
65 | - description = "proto", | 66 | + description = "IP protocol", |
66 | required = false, multiValued = false) | 67 | required = false, multiValued = false) |
67 | String proto; | 68 | String proto; |
68 | 69 | ||
69 | - @Argument(index = 7, name = "policy type", | 70 | + @Argument(index = 7, name = "policy_type", |
70 | description = "policy type", | 71 | description = "policy type", |
71 | required = true, multiValued = false) | 72 | required = true, multiValued = false) |
72 | String policyType; | 73 | String policyType; |
73 | 74 | ||
74 | - @Argument(index = 8, name = "tunnel ID", | 75 | + @Argument(index = 8, name = "tunnel_ID", |
75 | description = "tunnel ID", | 76 | description = "tunnel ID", |
76 | required = false, multiValued = false) | 77 | required = false, multiValued = false) |
77 | String tunnelId; | 78 | String tunnelId; |
... | @@ -103,11 +104,29 @@ public class PolicyAddCommand extends AbstractShellCommand { | ... | @@ -103,11 +104,29 @@ public class PolicyAddCommand extends AbstractShellCommand { |
103 | } | 104 | } |
104 | if (Policy.Type.valueOf(policyType) == Policy.Type.TUNNEL_FLOW) { | 105 | if (Policy.Type.valueOf(policyType) == Policy.Type.TUNNEL_FLOW) { |
105 | if (tunnelId == null) { | 106 | if (tunnelId == null) { |
106 | - // TODO: handle errors | 107 | + error("tunnel ID must be specified for TUNNEL_FLOW policy"); |
107 | return; | 108 | return; |
108 | } | 109 | } |
109 | tpb.setTunnelId(tunnelId); | 110 | tpb.setTunnelId(tunnelId); |
110 | } | 111 | } |
111 | - srService.createPolicy(tpb.build()); | 112 | + PolicyHandler.Result result = srService.createPolicy(tpb.build()); |
113 | + | ||
114 | + switch (result) { | ||
115 | + case POLICY_EXISTS: | ||
116 | + error("the same policy exists"); | ||
117 | + break; | ||
118 | + case ID_EXISTS: | ||
119 | + error("the same policy ID exists"); | ||
120 | + break; | ||
121 | + case TUNNEL_NOT_FOUND: | ||
122 | + error("the tunnel is not found"); | ||
123 | + break; | ||
124 | + case UNSUPPORTED_TYPE: | ||
125 | + error("the policy type specified is not supported"); | ||
126 | + break; | ||
127 | + default: | ||
128 | + break; | ||
129 | + } | ||
130 | + | ||
112 | } | 131 | } |
113 | } | 132 | } | ... | ... |
... | @@ -19,6 +19,7 @@ package org.onosproject.segmentrouting.cli; | ... | @@ -19,6 +19,7 @@ package org.onosproject.segmentrouting.cli; |
19 | import org.apache.karaf.shell.commands.Argument; | 19 | import org.apache.karaf.shell.commands.Argument; |
20 | import org.apache.karaf.shell.commands.Command; | 20 | import org.apache.karaf.shell.commands.Command; |
21 | import org.onosproject.cli.AbstractShellCommand; | 21 | import org.onosproject.cli.AbstractShellCommand; |
22 | +import org.onosproject.segmentrouting.PolicyHandler; | ||
22 | import org.onosproject.segmentrouting.SegmentRoutingService; | 23 | import org.onosproject.segmentrouting.SegmentRoutingService; |
23 | import org.onosproject.segmentrouting.TunnelPolicy; | 24 | import org.onosproject.segmentrouting.TunnelPolicy; |
24 | 25 | ||
... | @@ -41,6 +42,9 @@ public class PolicyRemoveCommand extends AbstractShellCommand { | ... | @@ -41,6 +42,9 @@ public class PolicyRemoveCommand extends AbstractShellCommand { |
41 | AbstractShellCommand.get(SegmentRoutingService.class); | 42 | AbstractShellCommand.get(SegmentRoutingService.class); |
42 | 43 | ||
43 | TunnelPolicy.Builder tpb = TunnelPolicy.builder().setPolicyId(policyId); | 44 | TunnelPolicy.Builder tpb = TunnelPolicy.builder().setPolicyId(policyId); |
44 | - srService.removePolicy(tpb.build()); | 45 | + PolicyHandler.Result result = srService.removePolicy(tpb.build()); |
46 | + if (result == PolicyHandler.Result.POLICY_NOT_FOUND) { | ||
47 | + print("ERROR: the policy is not found"); | ||
48 | + } | ||
45 | } | 49 | } |
46 | } | 50 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -22,6 +22,7 @@ import org.onosproject.cli.AbstractShellCommand; | ... | @@ -22,6 +22,7 @@ import org.onosproject.cli.AbstractShellCommand; |
22 | import org.onosproject.segmentrouting.DefaultTunnel; | 22 | import org.onosproject.segmentrouting.DefaultTunnel; |
23 | import org.onosproject.segmentrouting.SegmentRoutingService; | 23 | import org.onosproject.segmentrouting.SegmentRoutingService; |
24 | import org.onosproject.segmentrouting.Tunnel; | 24 | import org.onosproject.segmentrouting.Tunnel; |
25 | +import org.onosproject.segmentrouting.TunnelHandler; | ||
25 | 26 | ||
26 | import java.util.ArrayList; | 27 | import java.util.ArrayList; |
27 | import java.util.List; | 28 | import java.util.List; |
... | @@ -58,6 +59,22 @@ public class TunnelAddCommand extends AbstractShellCommand { | ... | @@ -58,6 +59,22 @@ public class TunnelAddCommand extends AbstractShellCommand { |
58 | } | 59 | } |
59 | Tunnel tunnel = new DefaultTunnel(tunnelId, labelIds); | 60 | Tunnel tunnel = new DefaultTunnel(tunnelId, labelIds); |
60 | 61 | ||
61 | - srService.createTunnel(tunnel); | 62 | + TunnelHandler.Result result = srService.createTunnel(tunnel); |
63 | + switch (result) { | ||
64 | + case ID_EXISTS: | ||
65 | + print("ERROR: the same tunnel ID exists"); | ||
66 | + break; | ||
67 | + case TUNNEL_EXISTS: | ||
68 | + print("ERROR: the same tunnel exists"); | ||
69 | + break; | ||
70 | + case INTERNAL_ERROR: | ||
71 | + print("ERROR: internal tunnel creation error"); | ||
72 | + break; | ||
73 | + case WRONG_PATH: | ||
74 | + print("ERROR: the tunnel path is wrong"); | ||
75 | + break; | ||
76 | + default: | ||
77 | + break; | ||
78 | + } | ||
62 | } | 79 | } |
63 | } | 80 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -23,6 +23,7 @@ import org.onosproject.cli.AbstractShellCommand; | ... | @@ -23,6 +23,7 @@ import org.onosproject.cli.AbstractShellCommand; |
23 | import org.onosproject.segmentrouting.DefaultTunnel; | 23 | import org.onosproject.segmentrouting.DefaultTunnel; |
24 | import org.onosproject.segmentrouting.SegmentRoutingService; | 24 | import org.onosproject.segmentrouting.SegmentRoutingService; |
25 | import org.onosproject.segmentrouting.Tunnel; | 25 | import org.onosproject.segmentrouting.Tunnel; |
26 | +import org.onosproject.segmentrouting.TunnelHandler; | ||
26 | 27 | ||
27 | /** | 28 | /** |
28 | * Command to remove a tunnel. | 29 | * Command to remove a tunnel. |
... | @@ -38,11 +39,20 @@ public class TunnelRemoveCommand extends AbstractShellCommand { | ... | @@ -38,11 +39,20 @@ public class TunnelRemoveCommand extends AbstractShellCommand { |
38 | 39 | ||
39 | @Override | 40 | @Override |
40 | protected void execute() { | 41 | protected void execute() { |
41 | - | ||
42 | SegmentRoutingService srService = | 42 | SegmentRoutingService srService = |
43 | AbstractShellCommand.get(SegmentRoutingService.class); | 43 | AbstractShellCommand.get(SegmentRoutingService.class); |
44 | 44 | ||
45 | Tunnel tunnel = new DefaultTunnel(tunnelId, Lists.newArrayList()); | 45 | Tunnel tunnel = new DefaultTunnel(tunnelId, Lists.newArrayList()); |
46 | - srService.removeTunnel(tunnel); | 46 | + TunnelHandler.Result result = srService.removeTunnel(tunnel); |
47 | + switch (result) { | ||
48 | + case TUNNEL_IN_USE: | ||
49 | + print("ERROR: the tunnel is still in use"); | ||
50 | + break; | ||
51 | + case TUNNEL_NOT_FOUND: | ||
52 | + print("ERROR: the tunnel is not found"); | ||
53 | + break; | ||
54 | + default: | ||
55 | + break; | ||
56 | + } | ||
47 | } | 57 | } |
48 | } | 58 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment