Committed by
Gerrit Code Review
[WIP][CORD-200] Improves Segment Routing using Network Configuration Subsystem
DONE - Remove original configuration subsystem - Implement new SegmentRoutingConfig - Update SegmentRoutingManager and DeviceConfiguration TODO - Extract adjacencySid array from JsonNode - Extract subnets and prefixes from port subject Change-Id: Ic7fec102f4427a30eec99ebf6c7c5584652a6280
Showing
11 changed files
with
175 additions
and
1046 deletions
1 | /* | 1 | /* |
2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2014-2015 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. |
... | @@ -18,15 +18,13 @@ package org.onosproject.segmentrouting; | ... | @@ -18,15 +18,13 @@ package org.onosproject.segmentrouting; |
18 | import com.google.common.collect.Lists; | 18 | import com.google.common.collect.Lists; |
19 | import org.onlab.packet.Ip4Address; | 19 | import org.onlab.packet.Ip4Address; |
20 | import org.onlab.packet.Ip4Prefix; | 20 | import org.onlab.packet.Ip4Prefix; |
21 | -import org.onlab.packet.IpPrefix; | ||
22 | import org.onlab.packet.MacAddress; | 21 | import org.onlab.packet.MacAddress; |
22 | +import org.onosproject.net.config.NetworkConfigRegistry; | ||
23 | +import org.onosproject.segmentrouting.config.SegmentRoutingConfig; | ||
24 | +import org.onosproject.segmentrouting.config.SegmentRoutingConfig.AdjacencySid; | ||
23 | import org.onosproject.segmentrouting.grouphandler.DeviceProperties; | 25 | import org.onosproject.segmentrouting.grouphandler.DeviceProperties; |
24 | import org.onosproject.net.DeviceId; | 26 | import org.onosproject.net.DeviceId; |
25 | import org.onosproject.net.PortNumber; | 27 | import org.onosproject.net.PortNumber; |
26 | -import org.onosproject.segmentrouting.config.NetworkConfig.SwitchConfig; | ||
27 | -import org.onosproject.segmentrouting.config.NetworkConfigManager; | ||
28 | -import org.onosproject.segmentrouting.config.SegmentRouterConfig; | ||
29 | -import org.onosproject.segmentrouting.config.SegmentRouterConfig.Subnet; | ||
30 | import org.slf4j.Logger; | 28 | import org.slf4j.Logger; |
31 | import org.slf4j.LoggerFactory; | 29 | import org.slf4j.LoggerFactory; |
32 | 30 | ||
... | @@ -36,6 +34,7 @@ import java.util.ArrayList; | ... | @@ -36,6 +34,7 @@ import java.util.ArrayList; |
36 | import java.util.HashMap; | 34 | import java.util.HashMap; |
37 | import java.util.List; | 35 | import java.util.List; |
38 | import java.util.Map; | 36 | import java.util.Map; |
37 | +import java.util.Set; | ||
39 | 38 | ||
40 | /** | 39 | /** |
41 | * Segment Routing configuration component that reads the | 40 | * Segment Routing configuration component that reads the |
... | @@ -50,7 +49,7 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -50,7 +49,7 @@ public class DeviceConfiguration implements DeviceProperties { |
50 | .getLogger(DeviceConfiguration.class); | 49 | .getLogger(DeviceConfiguration.class); |
51 | private final List<Integer> allSegmentIds = new ArrayList<>(); | 50 | private final List<Integer> allSegmentIds = new ArrayList<>(); |
52 | private final HashMap<DeviceId, SegmentRouterInfo> deviceConfigMap = new HashMap<>(); | 51 | private final HashMap<DeviceId, SegmentRouterInfo> deviceConfigMap = new HashMap<>(); |
53 | - private final NetworkConfigManager configService; | 52 | + private final NetworkConfigRegistry configService; |
54 | 53 | ||
55 | private class SegmentRouterInfo { | 54 | private class SegmentRouterInfo { |
56 | int nodeSid; | 55 | int nodeSid; |
... | @@ -60,48 +59,39 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -60,48 +59,39 @@ public class DeviceConfiguration implements DeviceProperties { |
60 | boolean isEdge; | 59 | boolean isEdge; |
61 | HashMap<PortNumber, Ip4Address> gatewayIps; | 60 | HashMap<PortNumber, Ip4Address> gatewayIps; |
62 | HashMap<PortNumber, Ip4Prefix> subnets; | 61 | HashMap<PortNumber, Ip4Prefix> subnets; |
63 | - List<SegmentRouterConfig.AdjacencySid> adjacencySids; | 62 | + List<AdjacencySid> adjacencySids; |
64 | } | 63 | } |
65 | 64 | ||
66 | /** | 65 | /** |
67 | * Constructor. Reads all the configuration for all devices of type | 66 | * Constructor. Reads all the configuration for all devices of type |
68 | * Segment Router and organizes into various maps for easier access. | 67 | * Segment Router and organizes into various maps for easier access. |
69 | * | 68 | * |
70 | - * @param configService handle to network configuration manager | 69 | + * @param cfgService handle to network configuration manager |
71 | * component from where the relevant configuration is retrieved. | 70 | * component from where the relevant configuration is retrieved. |
72 | */ | 71 | */ |
73 | - public DeviceConfiguration(NetworkConfigManager configService) { | 72 | + public DeviceConfiguration(NetworkConfigRegistry cfgService) { |
74 | - this.configService = checkNotNull(configService); | 73 | + this.configService = checkNotNull(cfgService); |
75 | - List<SwitchConfig> allSwitchCfg = | 74 | + |
76 | - this.configService.getConfiguredAllowedSwitches(); | 75 | + Set<DeviceId> subjectSet = |
77 | - for (SwitchConfig cfg : allSwitchCfg) { | 76 | + cfgService.getSubjects(DeviceId.class, SegmentRoutingConfig.class); |
78 | - if (!(cfg instanceof SegmentRouterConfig)) { | 77 | + |
79 | - continue; | 78 | + subjectSet.forEach(subject -> { |
80 | - } | 79 | + SegmentRoutingConfig config = |
80 | + cfgService.getConfig(subject, SegmentRoutingConfig.class); | ||
81 | SegmentRouterInfo info = new SegmentRouterInfo(); | 81 | SegmentRouterInfo info = new SegmentRouterInfo(); |
82 | - info.nodeSid = ((SegmentRouterConfig) cfg).getNodeSid(); | 82 | + info.nodeSid = config.getSid(); |
83 | - info.deviceId = cfg.getDpid(); | 83 | + info.deviceId = subject; |
84 | - info.mac = MacAddress.valueOf((( | 84 | + info.ip = config.getIp(); |
85 | - SegmentRouterConfig) cfg).getRouterMac()); | 85 | + info.mac = config.getMac(); |
86 | - String routerIp = ((SegmentRouterConfig) cfg).getRouterIp(); | 86 | + info.isEdge = config.isEdgeRouter(); |
87 | - Ip4Prefix prefix = checkNotNull(IpPrefix.valueOf(routerIp).getIp4Prefix()); | 87 | + // TODO fecth subnet and gateway information via port subject |
88 | - info.ip = prefix.address(); | ||
89 | - info.isEdge = ((SegmentRouterConfig) cfg).isEdgeRouter(); | ||
90 | - info.subnets = new HashMap<>(); | ||
91 | info.gatewayIps = new HashMap<>(); | 88 | info.gatewayIps = new HashMap<>(); |
92 | - for (Subnet s: ((SegmentRouterConfig) cfg).getSubnets()) { | 89 | + info.subnets = new HashMap<>(); |
93 | - info.subnets.put(PortNumber.portNumber(s.getPortNo()), | 90 | + info.adjacencySids = config.getAdjacencySids(); |
94 | - Ip4Prefix.valueOf(s.getSubnetIp())); | 91 | + |
95 | - String gatewayIp = s.getSubnetIp(). | ||
96 | - substring(0, s.getSubnetIp().indexOf('/')); | ||
97 | - info.gatewayIps.put(PortNumber.portNumber(s.getPortNo()), | ||
98 | - Ip4Address.valueOf(gatewayIp)); | ||
99 | - } | ||
100 | - info.adjacencySids = ((SegmentRouterConfig) cfg).getAdjacencySids(); | ||
101 | this.deviceConfigMap.put(info.deviceId, info); | 92 | this.deviceConfigMap.put(info.deviceId, info); |
102 | this.allSegmentIds.add(info.nodeSid); | 93 | this.allSegmentIds.add(info.nodeSid); |
103 | - | 94 | + }); |
104 | - } | ||
105 | } | 95 | } |
106 | 96 | ||
107 | /** | 97 | /** |
... | @@ -379,8 +369,8 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -379,8 +369,8 @@ public class DeviceConfiguration implements DeviceProperties { |
379 | */ | 369 | */ |
380 | public List<Integer> getPortsForAdjacencySid(DeviceId deviceId, int sid) { | 370 | public List<Integer> getPortsForAdjacencySid(DeviceId deviceId, int sid) { |
381 | if (deviceConfigMap.get(deviceId) != null) { | 371 | if (deviceConfigMap.get(deviceId) != null) { |
382 | - for (SegmentRouterConfig.AdjacencySid asid : deviceConfigMap.get(deviceId).adjacencySids) { | 372 | + for (AdjacencySid asid : deviceConfigMap.get(deviceId).adjacencySids) { |
383 | - if (asid.getAdjSid() == sid) { | 373 | + if (asid.getSid() == sid) { |
384 | return asid.getPorts(); | 374 | return asid.getPorts(); |
385 | } | 375 | } |
386 | } | 376 | } |
... | @@ -402,9 +392,9 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -402,9 +392,9 @@ public class DeviceConfiguration implements DeviceProperties { |
402 | if (deviceConfigMap.get(deviceId).adjacencySids.isEmpty()) { | 392 | if (deviceConfigMap.get(deviceId).adjacencySids.isEmpty()) { |
403 | return false; | 393 | return false; |
404 | } else { | 394 | } else { |
405 | - for (SegmentRouterConfig.AdjacencySid asid: | 395 | + for (AdjacencySid asid: |
406 | deviceConfigMap.get(deviceId).adjacencySids) { | 396 | deviceConfigMap.get(deviceId).adjacencySids) { |
407 | - if (asid.getAdjSid() == sid) { | 397 | + if (asid.getSid() == sid) { |
408 | return true; | 398 | return true; |
409 | } | 399 | } |
410 | } | 400 | } |
... | @@ -414,4 +404,4 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -414,4 +404,4 @@ public class DeviceConfiguration implements DeviceProperties { |
414 | 404 | ||
415 | return false; | 405 | return false; |
416 | } | 406 | } |
417 | -} | 407 | +} |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -27,6 +27,12 @@ import org.onlab.util.KryoNamespace; | ... | @@ -27,6 +27,12 @@ import org.onlab.util.KryoNamespace; |
27 | import org.onosproject.core.ApplicationId; | 27 | import org.onosproject.core.ApplicationId; |
28 | import org.onosproject.core.CoreService; | 28 | import org.onosproject.core.CoreService; |
29 | import org.onosproject.event.Event; | 29 | import org.onosproject.event.Event; |
30 | +import org.onosproject.net.config.ConfigFactory; | ||
31 | +import org.onosproject.net.config.NetworkConfigEvent; | ||
32 | +import org.onosproject.net.config.NetworkConfigRegistry; | ||
33 | +import org.onosproject.net.config.NetworkConfigListener; | ||
34 | +import org.onosproject.net.config.basics.SubjectFactories; | ||
35 | +import org.onosproject.segmentrouting.config.SegmentRoutingConfig; | ||
30 | import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; | 36 | import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; |
31 | import org.onosproject.segmentrouting.grouphandler.NeighborSet; | 37 | import org.onosproject.segmentrouting.grouphandler.NeighborSet; |
32 | import org.onosproject.segmentrouting.grouphandler.NeighborSetNextObjectiveStoreKey; | 38 | import org.onosproject.segmentrouting.grouphandler.NeighborSetNextObjectiveStoreKey; |
... | @@ -50,7 +56,6 @@ import org.onosproject.net.packet.PacketContext; | ... | @@ -50,7 +56,6 @@ import org.onosproject.net.packet.PacketContext; |
50 | import org.onosproject.net.packet.PacketProcessor; | 56 | import org.onosproject.net.packet.PacketProcessor; |
51 | import org.onosproject.net.packet.PacketService; | 57 | import org.onosproject.net.packet.PacketService; |
52 | import org.onosproject.net.topology.TopologyService; | 58 | import org.onosproject.net.topology.TopologyService; |
53 | -import org.onosproject.segmentrouting.config.NetworkConfigManager; | ||
54 | import org.onosproject.store.service.EventuallyConsistentMap; | 59 | import org.onosproject.store.service.EventuallyConsistentMap; |
55 | import org.onosproject.store.service.EventuallyConsistentMapBuilder; | 60 | import org.onosproject.store.service.EventuallyConsistentMapBuilder; |
56 | import org.onosproject.store.service.StorageService; | 61 | import org.onosproject.store.service.StorageService; |
... | @@ -133,7 +138,19 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -133,7 +138,19 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
133 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 138 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
134 | protected StorageService storageService; | 139 | protected StorageService storageService; |
135 | 140 | ||
136 | - private NetworkConfigManager networkConfigService = new NetworkConfigManager();; | 141 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
142 | + protected NetworkConfigRegistry cfgService; | ||
143 | + | ||
144 | + private final InternalConfigListener cfgListener = new InternalConfigListener(); | ||
145 | + private final ConfigFactory cfgFactory = | ||
146 | + new ConfigFactory(SubjectFactories.DEVICE_SUBJECT_FACTORY, | ||
147 | + SegmentRoutingConfig.class, | ||
148 | + "segmentrouting") { | ||
149 | + @Override | ||
150 | + public SegmentRoutingConfig createConfig() { | ||
151 | + return new SegmentRoutingConfig(); | ||
152 | + } | ||
153 | + }; | ||
137 | 154 | ||
138 | private Object threadSchedulerLock = new Object(); | 155 | private Object threadSchedulerLock = new Object(); |
139 | private static int numOfEventsQueued = 0; | 156 | private static int numOfEventsQueued = 0; |
... | @@ -192,8 +209,10 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -192,8 +209,10 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
192 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) | 209 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
193 | .build(); | 210 | .build(); |
194 | 211 | ||
195 | - networkConfigService.init(); | 212 | + cfgService.addListener(cfgListener); |
196 | - deviceConfiguration = new DeviceConfiguration(networkConfigService); | 213 | + cfgService.registerConfigFactory(cfgFactory); |
214 | + deviceConfiguration = new DeviceConfiguration(cfgService); | ||
215 | + | ||
197 | arpHandler = new ArpHandler(this); | 216 | arpHandler = new ArpHandler(this); |
198 | icmpHandler = new IcmpHandler(this); | 217 | icmpHandler = new IcmpHandler(this); |
199 | ipHandler = new IpHandler(this); | 218 | ipHandler = new IpHandler(this); |
... | @@ -230,6 +249,9 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -230,6 +249,9 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
230 | 249 | ||
231 | @Deactivate | 250 | @Deactivate |
232 | protected void deactivate() { | 251 | protected void deactivate() { |
252 | + cfgService.removeListener(cfgListener); | ||
253 | + cfgService.unregisterConfigFactory(cfgFactory); | ||
254 | + | ||
233 | packetService.removeProcessor(processor); | 255 | packetService.removeProcessor(processor); |
234 | processor = null; | 256 | processor = null; |
235 | log.info("Stopped"); | 257 | log.info("Stopped"); |
... | @@ -512,6 +534,15 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -512,6 +534,15 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
512 | } | 534 | } |
513 | } | 535 | } |
514 | 536 | ||
515 | - | 537 | + private class InternalConfigListener implements NetworkConfigListener { |
516 | - | 538 | + @Override |
539 | + public void event(NetworkConfigEvent event) { | ||
540 | + if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || | ||
541 | + event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) && | ||
542 | + event.configClass().equals(SegmentRoutingConfig.class)) { | ||
543 | + // TODO Support dynamic configuration in the future | ||
544 | + return; | ||
545 | + } | ||
546 | + } | ||
547 | + } | ||
517 | } | 548 | } | ... | ... |
apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfig.java
deleted
100644 → 0
1 | -/* | ||
2 | - * Copyright 2015 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 | -package org.onosproject.segmentrouting.config; | ||
17 | - | ||
18 | -import java.util.ArrayList; | ||
19 | -import java.util.List; | ||
20 | -import java.util.Map; | ||
21 | - | ||
22 | -import org.onosproject.net.DeviceId; | ||
23 | -import org.slf4j.Logger; | ||
24 | -import org.slf4j.LoggerFactory; | ||
25 | - | ||
26 | -import com.fasterxml.jackson.annotation.JsonProperty; | ||
27 | -import com.fasterxml.jackson.databind.JsonNode; | ||
28 | - | ||
29 | -/** | ||
30 | - * Public class corresponding to JSON described data model. Defines the network | ||
31 | - * configuration at startup. | ||
32 | - */ | ||
33 | -public class NetworkConfig { | ||
34 | - protected static final Logger log = LoggerFactory.getLogger(NetworkConfig.class); | ||
35 | - | ||
36 | - @SuppressWarnings("unused") | ||
37 | - private String comment; | ||
38 | - | ||
39 | - private Boolean restrictSwitches; | ||
40 | - private Boolean restrictLinks; | ||
41 | - private List<SwitchConfig> switches; | ||
42 | - private List<LinkConfig> links; | ||
43 | - | ||
44 | - /** | ||
45 | - * Default constructor. | ||
46 | - */ | ||
47 | - public NetworkConfig() { | ||
48 | - switches = new ArrayList<>(); | ||
49 | - links = new ArrayList<>(); | ||
50 | - } | ||
51 | - | ||
52 | - @JsonProperty("comment") | ||
53 | - public void setComment(String c) { | ||
54 | - log.trace("NetworkConfig: comment={}", c); | ||
55 | - comment = c; | ||
56 | - } | ||
57 | - | ||
58 | - @JsonProperty("restrictSwitches") | ||
59 | - public void setRestrictSwitches(boolean rs) { | ||
60 | - log.trace("NetworkConfig: restrictSwitches={}", rs); | ||
61 | - restrictSwitches = rs; | ||
62 | - } | ||
63 | - | ||
64 | - /** | ||
65 | - * Returns default restrict configuration for switches. | ||
66 | - * | ||
67 | - * @return boolean | ||
68 | - */ | ||
69 | - public Boolean getRestrictSwitches() { | ||
70 | - return restrictSwitches; | ||
71 | - } | ||
72 | - | ||
73 | - @JsonProperty("restrictLinks") | ||
74 | - public void setRestrictLinks(boolean rl) { | ||
75 | - log.trace("NetworkConfig: restrictLinks={}", rl); | ||
76 | - restrictLinks = rl; | ||
77 | - } | ||
78 | - | ||
79 | - /** | ||
80 | - * Returns default restrict configuration for links. | ||
81 | - * | ||
82 | - * @return boolean | ||
83 | - */ | ||
84 | - public Boolean getRestrictLinks() { | ||
85 | - return restrictLinks; | ||
86 | - } | ||
87 | - | ||
88 | - /** | ||
89 | - * Returns configuration for switches. | ||
90 | - * | ||
91 | - * @return list of switch configuration | ||
92 | - */ | ||
93 | - public List<SwitchConfig> getSwitchConfig() { | ||
94 | - return switches; | ||
95 | - } | ||
96 | - | ||
97 | - @JsonProperty("switchConfig") | ||
98 | - public void setSwitchConfig(List<SwitchConfig> switches2) { | ||
99 | - log.trace("NetworkConfig: switchConfig={}", switches2); | ||
100 | - this.switches = switches2; | ||
101 | - } | ||
102 | - | ||
103 | - /** | ||
104 | - * Java class corresponding to JSON described switch | ||
105 | - * configuration data model. | ||
106 | - */ | ||
107 | - public static class SwitchConfig { | ||
108 | - protected String nodeDpid; | ||
109 | - protected String name; | ||
110 | - protected String type; | ||
111 | - protected boolean allowed; | ||
112 | - protected double latitude; | ||
113 | - protected double longitude; | ||
114 | - protected Map<String, JsonNode> params; | ||
115 | - protected Map<String, String> publishAttributes; | ||
116 | - protected DeviceId dpid; | ||
117 | - | ||
118 | - /** | ||
119 | - * Returns the configured "name" of a switch. | ||
120 | - * | ||
121 | - * @return string | ||
122 | - */ | ||
123 | - public String getName() { | ||
124 | - return name; | ||
125 | - } | ||
126 | - | ||
127 | - @JsonProperty("name") | ||
128 | - public void setName(String name) { | ||
129 | - log.trace("SwitchConfig: name={}", name); | ||
130 | - this.name = name; | ||
131 | - } | ||
132 | - | ||
133 | - /** | ||
134 | - * Returns the data plane identifier of a switch. | ||
135 | - * | ||
136 | - * @return ONOS device identifier | ||
137 | - */ | ||
138 | - public DeviceId getDpid() { | ||
139 | - return dpid; | ||
140 | - } | ||
141 | - | ||
142 | - public void setDpid(DeviceId dpid) { | ||
143 | - this.dpid = dpid; | ||
144 | - this.nodeDpid = dpid.toString(); | ||
145 | - } | ||
146 | - | ||
147 | - /** | ||
148 | - * Returns the data plane identifier of a switch. | ||
149 | - * | ||
150 | - * @return string | ||
151 | - */ | ||
152 | - public String getNodeDpid() { | ||
153 | - return nodeDpid; | ||
154 | - } | ||
155 | - | ||
156 | - // mapper sets both DeviceId and string fields for dpid | ||
157 | - @JsonProperty("nodeDpid") | ||
158 | - public void setNodeDpid(String nodeDpid) { | ||
159 | - log.trace("SwitchConfig: nodeDpid={}", nodeDpid); | ||
160 | - this.nodeDpid = nodeDpid; | ||
161 | - this.dpid = DeviceId.deviceId(nodeDpid); | ||
162 | - } | ||
163 | - | ||
164 | - /** | ||
165 | - * Returns the type of a switch. | ||
166 | - * | ||
167 | - * @return string | ||
168 | - */ | ||
169 | - public String getType() { | ||
170 | - return type; | ||
171 | - } | ||
172 | - | ||
173 | - @JsonProperty("type") | ||
174 | - public void setType(String type) { | ||
175 | - log.trace("SwitchConfig: type={}", type); | ||
176 | - this.type = type; | ||
177 | - } | ||
178 | - | ||
179 | - /** | ||
180 | - * Returns the latitude of a switch. | ||
181 | - * | ||
182 | - * @return double | ||
183 | - */ | ||
184 | - public double getLatitude() { | ||
185 | - return latitude; | ||
186 | - } | ||
187 | - | ||
188 | - @JsonProperty("latitude") | ||
189 | - public void setLatitude(double latitude) { | ||
190 | - log.trace("SwitchConfig: latitude={}", latitude); | ||
191 | - this.latitude = latitude; | ||
192 | - } | ||
193 | - | ||
194 | - /** | ||
195 | - * Returns the longitude of a switch. | ||
196 | - * | ||
197 | - * @return double | ||
198 | - */ | ||
199 | - public double getLongitude() { | ||
200 | - return longitude; | ||
201 | - } | ||
202 | - | ||
203 | - @JsonProperty("longitude") | ||
204 | - public void setLongitude(double longitude) { | ||
205 | - log.trace("SwitchConfig: longitude={}", longitude); | ||
206 | - this.longitude = longitude; | ||
207 | - } | ||
208 | - | ||
209 | - /** | ||
210 | - * Returns the allowed flag for a switch. | ||
211 | - * | ||
212 | - * @return boolean | ||
213 | - */ | ||
214 | - public boolean isAllowed() { | ||
215 | - return allowed; | ||
216 | - } | ||
217 | - | ||
218 | - @JsonProperty("allowed") | ||
219 | - public void setAllowed(boolean allowed) { | ||
220 | - this.allowed = allowed; | ||
221 | - } | ||
222 | - | ||
223 | - /** | ||
224 | - * Returns the additional configured parameters of a switch. | ||
225 | - * | ||
226 | - * @return key value map | ||
227 | - */ | ||
228 | - public Map<String, JsonNode> getParams() { | ||
229 | - return params; | ||
230 | - } | ||
231 | - | ||
232 | - @JsonProperty("params") | ||
233 | - public void setParams(Map<String, JsonNode> params) { | ||
234 | - this.params = params; | ||
235 | - } | ||
236 | - | ||
237 | - /** | ||
238 | - * Reserved for future use. | ||
239 | - * | ||
240 | - * @return key value map | ||
241 | - */ | ||
242 | - public Map<String, String> getPublishAttributes() { | ||
243 | - return publishAttributes; | ||
244 | - } | ||
245 | - | ||
246 | - @JsonProperty("publishAttributes") | ||
247 | - public void setPublishAttributes(Map<String, String> publishAttributes) { | ||
248 | - this.publishAttributes = publishAttributes; | ||
249 | - } | ||
250 | - | ||
251 | - } | ||
252 | - | ||
253 | - @JsonProperty("linkConfig") | ||
254 | - public void setLinkConfig(List<LinkConfig> links2) { | ||
255 | - this.links = links2; | ||
256 | - } | ||
257 | - | ||
258 | - /** | ||
259 | - * Reserved for future use. | ||
260 | - * | ||
261 | - * @return list of configured link configuration | ||
262 | - */ | ||
263 | - public List<LinkConfig> getLinkConfig() { | ||
264 | - return links; | ||
265 | - } | ||
266 | - | ||
267 | - /** | ||
268 | - * Reserved for future use. | ||
269 | - */ | ||
270 | - public static class LinkConfig { | ||
271 | - protected String type; | ||
272 | - protected Boolean allowed; | ||
273 | - protected DeviceId dpid1; | ||
274 | - protected DeviceId dpid2; | ||
275 | - protected String nodeDpid1; | ||
276 | - protected String nodeDpid2; | ||
277 | - protected Map<String, JsonNode> params; | ||
278 | - protected Map<String, String> publishAttributes; | ||
279 | - | ||
280 | - public String getType() { | ||
281 | - return type; | ||
282 | - } | ||
283 | - | ||
284 | - public void setType(String type) { | ||
285 | - this.type = type; | ||
286 | - } | ||
287 | - | ||
288 | - public Boolean isAllowed() { | ||
289 | - return allowed; | ||
290 | - } | ||
291 | - | ||
292 | - public void setAllowed(Boolean allowed) { | ||
293 | - this.allowed = allowed; | ||
294 | - } | ||
295 | - | ||
296 | - public String getNodeDpid1() { | ||
297 | - return nodeDpid1; | ||
298 | - } | ||
299 | - | ||
300 | - // mapper sets both long and string fields for dpid | ||
301 | - public void setNodeDpid1(String nodeDpid1) { | ||
302 | - this.nodeDpid1 = nodeDpid1; | ||
303 | - this.dpid1 = DeviceId.deviceId(nodeDpid1); | ||
304 | - } | ||
305 | - | ||
306 | - public String getNodeDpid2() { | ||
307 | - return nodeDpid2; | ||
308 | - } | ||
309 | - | ||
310 | - // mapper sets both long and string fields for dpid | ||
311 | - public void setNodeDpid2(String nodeDpid2) { | ||
312 | - this.nodeDpid2 = nodeDpid2; | ||
313 | - this.dpid2 = DeviceId.deviceId(nodeDpid2); | ||
314 | - } | ||
315 | - | ||
316 | - public DeviceId getDpid1() { | ||
317 | - return dpid1; | ||
318 | - } | ||
319 | - | ||
320 | - public void setDpid1(DeviceId dpid1) { | ||
321 | - this.dpid1 = dpid1; | ||
322 | - this.nodeDpid1 = dpid1.toString(); | ||
323 | - } | ||
324 | - | ||
325 | - public DeviceId getDpid2() { | ||
326 | - return dpid2; | ||
327 | - } | ||
328 | - | ||
329 | - public void setDpid2(DeviceId dpid2) { | ||
330 | - this.dpid2 = dpid2; | ||
331 | - this.nodeDpid2 = dpid2.toString(); | ||
332 | - } | ||
333 | - | ||
334 | - public Map<String, JsonNode> getParams() { | ||
335 | - return params; | ||
336 | - } | ||
337 | - | ||
338 | - public void setParams(Map<String, JsonNode> params) { | ||
339 | - this.params = params; | ||
340 | - } | ||
341 | - | ||
342 | - public Map<String, String> getPublishAttributes() { | ||
343 | - return publishAttributes; | ||
344 | - } | ||
345 | - | ||
346 | - public void setPublishAttributes(Map<String, String> publishAttributes) { | ||
347 | - this.publishAttributes = publishAttributes; | ||
348 | - } | ||
349 | - } | ||
350 | -} | ||
351 | - |
1 | -/* | ||
2 | - * Copyright 2015 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 | -package org.onosproject.segmentrouting.config; | ||
17 | - | ||
18 | -import org.onosproject.net.DeviceId; | ||
19 | -import org.slf4j.Logger; | ||
20 | -import org.slf4j.LoggerFactory; | ||
21 | - | ||
22 | -/** | ||
23 | - * NetworkConfigExceptions specifies a set of unchecked runtime exceptions that | ||
24 | - * can be thrown by the {@link NetworkConfigManager}. It indicates errors that | ||
25 | - * must be fixed in the config file before controller execution can proceed. | ||
26 | - */ | ||
27 | -public class NetworkConfigException extends RuntimeException { | ||
28 | - | ||
29 | - private static final long serialVersionUID = 4959684709803000652L; | ||
30 | - protected static final Logger log = LoggerFactory | ||
31 | - .getLogger(NetworkConfigException.class); | ||
32 | - | ||
33 | - /** | ||
34 | - * Exception for duplicate device identifier configuration. | ||
35 | - */ | ||
36 | - public static class DuplicateDpid extends RuntimeException { | ||
37 | - private static final long serialVersionUID = 5491113234592145335L; | ||
38 | - | ||
39 | - public DuplicateDpid(DeviceId dpid) { | ||
40 | - super(); | ||
41 | - log.error("Duplicate dpid found in switch-config Dpid:{}", | ||
42 | - dpid); | ||
43 | - } | ||
44 | - } | ||
45 | - | ||
46 | - /** | ||
47 | - * Exception for duplicate device name configuration. | ||
48 | - */ | ||
49 | - public static class DuplicateName extends RuntimeException { | ||
50 | - private static final long serialVersionUID = -4090171438031376129L; | ||
51 | - | ||
52 | - public DuplicateName(String name) { | ||
53 | - super(); | ||
54 | - log.error("Duplicate name found in switch-config name:{}", name); | ||
55 | - } | ||
56 | - } | ||
57 | - | ||
58 | - /** | ||
59 | - * Exception for unspecified device identifier for a switch. | ||
60 | - */ | ||
61 | - public static class DpidNotSpecified extends RuntimeException { | ||
62 | - private static final long serialVersionUID = -8494418855597117254L; | ||
63 | - | ||
64 | - public DpidNotSpecified(String name) { | ||
65 | - super(); | ||
66 | - log.error("Dpid not specified for switch-config name:{}", name); | ||
67 | - } | ||
68 | - } | ||
69 | - | ||
70 | - /** | ||
71 | - * Exception for unspecified device name for a switch. | ||
72 | - */ | ||
73 | - public static class NameNotSpecified extends RuntimeException { | ||
74 | - private static final long serialVersionUID = -3518881744110422891L; | ||
75 | - | ||
76 | - public NameNotSpecified(DeviceId dpid) { | ||
77 | - super(); | ||
78 | - log.error("Name not specified for switch-config dpid:{}", | ||
79 | - dpid); | ||
80 | - } | ||
81 | - } | ||
82 | - | ||
83 | - /** | ||
84 | - * Exception for unspecified device type for a switch. | ||
85 | - */ | ||
86 | - public static class SwitchTypeNotSpecified extends RuntimeException { | ||
87 | - private static final long serialVersionUID = 2527453336226053753L; | ||
88 | - | ||
89 | - public SwitchTypeNotSpecified(DeviceId dpid) { | ||
90 | - super(); | ||
91 | - log.error("Switch type not specified for switch-config dpid:{}", | ||
92 | - dpid); | ||
93 | - } | ||
94 | - } | ||
95 | - | ||
96 | - /** | ||
97 | - * Exception for unknown device type configured for a switch. | ||
98 | - */ | ||
99 | - public static class UnknownSwitchType extends RuntimeException { | ||
100 | - private static final long serialVersionUID = 7758418165512249170L; | ||
101 | - | ||
102 | - public UnknownSwitchType(String type, String name) { | ||
103 | - super(); | ||
104 | - log.error("Unknown switch type {} for switch name:{}", type, name); | ||
105 | - } | ||
106 | - } | ||
107 | - | ||
108 | - /** | ||
109 | - * Exception for missing required parameter configuration for a switch. | ||
110 | - */ | ||
111 | - public static class ParamsNotSpecified extends RuntimeException { | ||
112 | - private static final long serialVersionUID = 6247582323691265513L; | ||
113 | - | ||
114 | - public ParamsNotSpecified(String name) { | ||
115 | - super(); | ||
116 | - log.error("Params required - not specified for switch:{}", name); | ||
117 | - } | ||
118 | - } | ||
119 | - | ||
120 | - /** | ||
121 | - * Reserved for future use. | ||
122 | - */ | ||
123 | - public static class LinkTypeNotSpecified extends RuntimeException { | ||
124 | - private static final long serialVersionUID = -2089470389588542215L; | ||
125 | - | ||
126 | - public LinkTypeNotSpecified(String dpid1, String dpid2) { | ||
127 | - super(); | ||
128 | - log.error("Link type not specified for link-config between " | ||
129 | - + "dpid1:{} and dpid2:{}", dpid1, dpid2); | ||
130 | - } | ||
131 | - } | ||
132 | - | ||
133 | - /** | ||
134 | - * Reserved for future use. | ||
135 | - */ | ||
136 | - public static class LinkDpidNotSpecified extends RuntimeException { | ||
137 | - private static final long serialVersionUID = -5701825916378616004L; | ||
138 | - | ||
139 | - public LinkDpidNotSpecified(String dpid1, String dpid2) { | ||
140 | - super(); | ||
141 | - if (dpid1 == null) { | ||
142 | - log.error("nodeDpid1 not specified for link-config "); | ||
143 | - } | ||
144 | - if (dpid2 == null) { | ||
145 | - log.error("nodeDpid2 not specified for link-config "); | ||
146 | - } | ||
147 | - } | ||
148 | - } | ||
149 | - | ||
150 | - /** | ||
151 | - * Reserved for future use. | ||
152 | - */ | ||
153 | - public static class LinkForUnknownSwitchConfig extends RuntimeException { | ||
154 | - private static final long serialVersionUID = -2910458439881964094L; | ||
155 | - | ||
156 | - public LinkForUnknownSwitchConfig(String dpid) { | ||
157 | - super(); | ||
158 | - log.error("Link configuration was specified for a switch-dpid {} " | ||
159 | - + "that has not been configured", dpid); | ||
160 | - } | ||
161 | - } | ||
162 | - | ||
163 | - /** | ||
164 | - * Reserved for future use. | ||
165 | - */ | ||
166 | - public static class UnknownLinkType extends RuntimeException { | ||
167 | - private static final long serialVersionUID = -5505376193106542305L; | ||
168 | - | ||
169 | - public UnknownLinkType(String linktype, String dpid1, String dpid2) { | ||
170 | - super(); | ||
171 | - log.error("unknown link type {} for links between dpid1:{} " | ||
172 | - + "and dpid2:{}", linktype, dpid1, dpid2); | ||
173 | - } | ||
174 | - } | ||
175 | - | ||
176 | - /** | ||
177 | - * Exception for generic configuration errors. | ||
178 | - */ | ||
179 | - public static class ErrorConfig extends RuntimeException { | ||
180 | - private static final long serialVersionUID = -2827406314700193147L; | ||
181 | - | ||
182 | - public ErrorConfig(String errorMsg) { | ||
183 | - super(); | ||
184 | - log.error(errorMsg); | ||
185 | - } | ||
186 | - | ||
187 | - } | ||
188 | - | ||
189 | - /** | ||
190 | - * Reserved for future use. | ||
191 | - */ | ||
192 | - public static class SwitchDpidNotConverted extends RuntimeException { | ||
193 | - private static final long serialVersionUID = 5640347104590170426L; | ||
194 | - | ||
195 | - public SwitchDpidNotConverted(String name) { | ||
196 | - super(); | ||
197 | - log.error("Switch dpid specified as a HexString {} does not match " | ||
198 | - + "with long value", name); | ||
199 | - } | ||
200 | - } | ||
201 | - | ||
202 | - /** | ||
203 | - * Reserved for future use. | ||
204 | - */ | ||
205 | - public static class LinkDpidNotConverted extends RuntimeException { | ||
206 | - private static final long serialVersionUID = 2397245646094080774L; | ||
207 | - | ||
208 | - public LinkDpidNotConverted(String dpid1, String dpid2) { | ||
209 | - log.error("Dpids expressed as HexStrings for links between dpid1:{} " | ||
210 | - + "and dpid2:{} do not match with long values", dpid1, dpid2); | ||
211 | - } | ||
212 | - } | ||
213 | - | ||
214 | -} | ||
215 | - |
This diff is collapsed. Click to expand it.
1 | -/* | ||
2 | - * Copyright 2015 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 | -package org.onosproject.segmentrouting.config; | ||
17 | - | ||
18 | -import java.util.List; | ||
19 | - | ||
20 | -import org.onosproject.net.DeviceId; | ||
21 | -import org.onosproject.net.Link; | ||
22 | -import org.onosproject.segmentrouting.config.NetworkConfig.LinkConfig; | ||
23 | -import org.onosproject.segmentrouting.config.NetworkConfig.SwitchConfig; | ||
24 | - | ||
25 | -/** | ||
26 | - * Exposes methods to retrieve network configuration. | ||
27 | - * | ||
28 | - * TODO: currently only startup-configuration is exposed and such configuration | ||
29 | - * cannot be changed at runtime. Need to add runtime support for changes to | ||
30 | - * configuration (via REST/CLI) in future releases. | ||
31 | - * | ||
32 | - * TODO: return immutable objects or defensive copies of network config so that | ||
33 | - * users of this API do not inadvertently or maliciously change network config. | ||
34 | - * | ||
35 | - * @deprecated in Drake; see org.onosproject.net.config | ||
36 | - */ | ||
37 | -@Deprecated | ||
38 | -public interface NetworkConfigService { | ||
39 | - | ||
40 | - /** | ||
41 | - * Suggests the action to be taken by the caller given the configuration | ||
42 | - * associated with the queried network-object (eg. switch, link etc.). | ||
43 | - */ | ||
44 | - enum NetworkConfigState { | ||
45 | - /** | ||
46 | - * Associated network object has been configured to not be allowed in | ||
47 | - * the network. | ||
48 | - */ | ||
49 | - DENY, | ||
50 | - | ||
51 | - /** | ||
52 | - * Associated network object has been configured to be allowed in the | ||
53 | - * network. | ||
54 | - */ | ||
55 | - ACCEPT, | ||
56 | - | ||
57 | - /** | ||
58 | - * Associated network object has been configured to be allowed in the | ||
59 | - * network. In addition, there are configured parameters that should be | ||
60 | - * added to the object. | ||
61 | - */ | ||
62 | - ACCEPT_ADD, | ||
63 | - } | ||
64 | - | ||
65 | - /** | ||
66 | - * Returns the configuration outcome (accept, deny etc.), and any configured | ||
67 | - * parameters to the caller, in response to a query for the configuration | ||
68 | - * associated with a switch. | ||
69 | - */ | ||
70 | - class SwitchConfigStatus { | ||
71 | - private NetworkConfigState configState; | ||
72 | - private SwitchConfig switchConfig; | ||
73 | - private String msg; | ||
74 | - | ||
75 | - SwitchConfigStatus(NetworkConfigState configState, | ||
76 | - SwitchConfig switchConfig, String msg) { | ||
77 | - this.configState = configState; | ||
78 | - this.switchConfig = switchConfig; | ||
79 | - this.msg = msg; | ||
80 | - } | ||
81 | - | ||
82 | - SwitchConfigStatus(NetworkConfigState configState, | ||
83 | - SwitchConfig switchConfig) { | ||
84 | - this.configState = configState; | ||
85 | - this.switchConfig = switchConfig; | ||
86 | - this.msg = ""; | ||
87 | - } | ||
88 | - | ||
89 | - /** | ||
90 | - * Returns the configuration state for the switch. | ||
91 | - * | ||
92 | - * @return non-null NetworkConfigState | ||
93 | - */ | ||
94 | - public NetworkConfigState getConfigState() { | ||
95 | - return configState; | ||
96 | - } | ||
97 | - | ||
98 | - /** | ||
99 | - * Returns the switch configuration, which may be null if no | ||
100 | - * configuration exists, or if the configuration state disallows the | ||
101 | - * switch. | ||
102 | - * | ||
103 | - * @return SwitchConfig, the switch configuration, or null | ||
104 | - */ | ||
105 | - public SwitchConfig getSwitchConfig() { | ||
106 | - return switchConfig; | ||
107 | - } | ||
108 | - | ||
109 | - /** | ||
110 | - * User readable string typically used to specify the reason why a | ||
111 | - * switch is being disallowed. | ||
112 | - * | ||
113 | - * @return A non-null but possibly empty String | ||
114 | - */ | ||
115 | - public String getMsg() { | ||
116 | - return msg; | ||
117 | - } | ||
118 | - | ||
119 | - } | ||
120 | - | ||
121 | - /** | ||
122 | - * Reserved for future use. | ||
123 | - * | ||
124 | - * Returns the configuration outcome (accept, deny etc.), and any configured | ||
125 | - * parameters to the caller, in response to a query for the configuration | ||
126 | - * associated with a link. | ||
127 | - */ | ||
128 | - class LinkConfigStatus { | ||
129 | - private NetworkConfigState configState; | ||
130 | - private LinkConfig linkConfig; | ||
131 | - private String msg; | ||
132 | - | ||
133 | - LinkConfigStatus(NetworkConfigState configState, | ||
134 | - LinkConfig linkConfig, String msg) { | ||
135 | - this.configState = configState; | ||
136 | - this.linkConfig = linkConfig; | ||
137 | - this.msg = msg; | ||
138 | - } | ||
139 | - | ||
140 | - LinkConfigStatus(NetworkConfigState configState, | ||
141 | - LinkConfig linkConfig) { | ||
142 | - this.configState = configState; | ||
143 | - this.linkConfig = linkConfig; | ||
144 | - this.msg = ""; | ||
145 | - } | ||
146 | - | ||
147 | - /** | ||
148 | - * Returns the configuration state for the link. | ||
149 | - * | ||
150 | - * @return non-null NetworkConfigState | ||
151 | - */ | ||
152 | - public NetworkConfigState getConfigState() { | ||
153 | - return configState; | ||
154 | - } | ||
155 | - | ||
156 | - /** | ||
157 | - * Returns the link configuration, which may be null if no configuration | ||
158 | - * exists, or if the configuration state disallows the link. | ||
159 | - * | ||
160 | - * @return SwitchConfig, the switch configuration, or null | ||
161 | - */ | ||
162 | - public LinkConfig getLinkConfig() { | ||
163 | - return linkConfig; | ||
164 | - } | ||
165 | - | ||
166 | - /** | ||
167 | - * User readable string typically used to specify the reason why a link | ||
168 | - * is being disallowed. | ||
169 | - * | ||
170 | - * @return msg A non-null but possibly empty String | ||
171 | - */ | ||
172 | - public String getMsg() { | ||
173 | - return msg; | ||
174 | - } | ||
175 | - | ||
176 | - } | ||
177 | - | ||
178 | - /** | ||
179 | - * Checks the switch configuration (if any) associated with the 'dpid'. | ||
180 | - * Determines if the switch should be allowed or denied according to | ||
181 | - * configuration rules. | ||
182 | - * | ||
183 | - * The method always returns a non-null SwitchConfigStatus. The enclosed | ||
184 | - * ConfigState contains the result of the check. The enclosed SwitchConfig | ||
185 | - * may or may not be null, depending on the outcome of the check. | ||
186 | - * | ||
187 | - * @param dpid device id of the switch to be queried | ||
188 | - * @return SwitchConfigStatus with outcome of check and associated config. | ||
189 | - */ | ||
190 | - SwitchConfigStatus checkSwitchConfig(DeviceId dpid); | ||
191 | - | ||
192 | - /** | ||
193 | - * Reserved for future use. | ||
194 | - * | ||
195 | - * Checks the link configuration (if any) associated with the 'link'. | ||
196 | - * Determines if the link should be allowed or denied according to | ||
197 | - * configuration rules. Note that the 'link' is a unidirectional link which | ||
198 | - * checked against configuration that is typically defined for a | ||
199 | - * bidirectional link. The caller may make a second call if it wishes to | ||
200 | - * check the 'reverse' direction. | ||
201 | - * | ||
202 | - * Also note that the configuration may not specify ports for a given | ||
203 | - * bidirectional link. In such cases, the configuration applies to all links | ||
204 | - * between the two switches. This method will check the given 'link' against | ||
205 | - * such configuration. | ||
206 | - | ||
207 | - * The method always returns a non-null LinkConfigStatus. The enclosed | ||
208 | - * ConfigState contains the result of the check. The enclosed LinkConfig may | ||
209 | - * or may not be null, depending on the outcome of the check. | ||
210 | - * | ||
211 | - * @param linkTuple unidirectional link to be queried | ||
212 | - * @return LinkConfigStatus with outcome of check and associated config. | ||
213 | - */ | ||
214 | - LinkConfigStatus checkLinkConfig(Link linkTuple); | ||
215 | - | ||
216 | - /** | ||
217 | - * Retrieves a list of switches that have been configured, and have been | ||
218 | - * determined to be 'allowed' in the network, according to configuration | ||
219 | - * rules. | ||
220 | - * | ||
221 | - * Note that it is possible that there are other switches that are allowed | ||
222 | - * in the network that have NOT been configured. Such switches will not be a | ||
223 | - * part of the returned list. | ||
224 | - * | ||
225 | - * Also note that it is possible that some switches will not be discovered | ||
226 | - * and the only way the controller can know about these switches is via | ||
227 | - * configuration. Such switches will be included in this list. It is up to | ||
228 | - * the caller to determine which SwitchConfig applies to non-discovered | ||
229 | - * switches. | ||
230 | - * | ||
231 | - * @return a non-null List of SwitchConfig which may be empty | ||
232 | - */ | ||
233 | - List<SwitchConfig> getConfiguredAllowedSwitches(); | ||
234 | - | ||
235 | - /** | ||
236 | - * Reserved for future use. | ||
237 | - * | ||
238 | - * Retrieves a list of links that have been configured, and have been | ||
239 | - * determined to be 'allowed' in the network, according to configuration | ||
240 | - * rules. | ||
241 | - * | ||
242 | - * Note that it is possible that there are other links that are allowed in | ||
243 | - * the network that have NOT been configured. Such links will not be a part | ||
244 | - * of the returned list. | ||
245 | - * | ||
246 | - * Also note that it is possible that some links will not be discovered and | ||
247 | - * the only way the controller can know about these links is via | ||
248 | - * configuration. Such links will be included in this list. It is up to the | ||
249 | - * caller to determine which LinkConfig applies to non-discovered links. | ||
250 | - * | ||
251 | - * In addition, note that the LinkConfig applies to the configured | ||
252 | - * bi-directional link, which may or may not have declared ports. The | ||
253 | - * associated unidirectional LinkTuple can be retrieved from the | ||
254 | - * getLinkTupleList() method in the LinkConfig object. | ||
255 | - * | ||
256 | - * @return a non-null List of LinkConfig which may be empty | ||
257 | - */ | ||
258 | - List<LinkConfig> getConfiguredAllowedLinks(); | ||
259 | - | ||
260 | - /** | ||
261 | - * Retrieves the Dpid associated with a 'name' for a configured switch | ||
262 | - * object. This method does not check of the switches are 'allowed' by | ||
263 | - * config. | ||
264 | - * | ||
265 | - * @param name device name | ||
266 | - * @return the Dpid corresponding to a given 'name', or null if no | ||
267 | - * configured switch was found for the given 'name'. | ||
268 | - */ | ||
269 | - DeviceId getDpidForName(String name); | ||
270 | - | ||
271 | -} |
apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/PktLinkConfig.java
deleted
100644 → 0
1 | -/* | ||
2 | - * Copyright 2015 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 | -package org.onosproject.segmentrouting.config; | ||
17 | - | ||
18 | -import java.util.List; | ||
19 | -import java.util.Map.Entry; | ||
20 | -import java.util.Set; | ||
21 | -import java.util.concurrent.ConcurrentHashMap; | ||
22 | - | ||
23 | -import org.onosproject.net.Link; | ||
24 | -import org.onosproject.segmentrouting.config.NetworkConfig.LinkConfig; | ||
25 | -import org.slf4j.Logger; | ||
26 | -import org.slf4j.LoggerFactory; | ||
27 | - | ||
28 | -import com.fasterxml.jackson.databind.JsonNode; | ||
29 | - | ||
30 | -/** | ||
31 | - * Reserved for future use. | ||
32 | - * Configuration for a link between two packet-switches. | ||
33 | - */ | ||
34 | -public class PktLinkConfig extends LinkConfig { | ||
35 | - protected static final Logger log = LoggerFactory | ||
36 | - .getLogger(PktLinkConfig.class); | ||
37 | - private int port1; | ||
38 | - private int port2; | ||
39 | - private String nodeName1; | ||
40 | - private String nodeName2; | ||
41 | - private List<Link> linkTupleList; | ||
42 | - | ||
43 | - public PktLinkConfig(LinkConfig lkc) { | ||
44 | - nodeDpid1 = lkc.getNodeDpid1(); | ||
45 | - nodeDpid2 = lkc.getNodeDpid2(); | ||
46 | - dpid1 = lkc.getDpid1(); | ||
47 | - dpid2 = lkc.getDpid2(); | ||
48 | - type = lkc.getType(); | ||
49 | - allowed = lkc.isAllowed(); | ||
50 | - params = lkc.getParams(); | ||
51 | - publishAttributes = new ConcurrentHashMap<>(); | ||
52 | - parseParams(); | ||
53 | - validateParams(); | ||
54 | - setPublishAttributes(); | ||
55 | - } | ||
56 | - | ||
57 | - // ******************** | ||
58 | - // Packet Link Configuration | ||
59 | - // ******************** | ||
60 | - | ||
61 | - public int getPort1() { | ||
62 | - return port1; | ||
63 | - } | ||
64 | - | ||
65 | - public void setPort1(int port1) { | ||
66 | - this.port1 = port1; | ||
67 | - } | ||
68 | - | ||
69 | - public int getPort2() { | ||
70 | - return port2; | ||
71 | - } | ||
72 | - | ||
73 | - public void setPort2(int port2) { | ||
74 | - this.port2 = port2; | ||
75 | - } | ||
76 | - | ||
77 | - public String getNodeName1() { | ||
78 | - return nodeName1; | ||
79 | - } | ||
80 | - | ||
81 | - public void setNodeName1(String nodeName1) { | ||
82 | - this.nodeName1 = nodeName1; | ||
83 | - } | ||
84 | - | ||
85 | - public String getNodeName2() { | ||
86 | - return nodeName2; | ||
87 | - } | ||
88 | - | ||
89 | - public void setNodeName2(String nodeName2) { | ||
90 | - this.nodeName2 = nodeName2; | ||
91 | - } | ||
92 | - | ||
93 | - /** | ||
94 | - * Returns the two unidirectional links corresponding to the packet-link | ||
95 | - * configuration. It is possible that the ports in the LinkTuple have | ||
96 | - * portnumber '0', implying that the configuration applies to all links | ||
97 | - * between the two switches. | ||
98 | - * | ||
99 | - * @return a list of LinkTuple with exactly 2 unidirectional links | ||
100 | - */ | ||
101 | - public List<Link> getLinkTupleList() { | ||
102 | - return linkTupleList; | ||
103 | - } | ||
104 | - | ||
105 | - private void setPublishAttributes() { | ||
106 | - | ||
107 | - } | ||
108 | - | ||
109 | - private void parseParams() { | ||
110 | - if (params == null) { | ||
111 | - throw new PktLinkParamsNotSpecified(nodeDpid1, nodeDpid2); | ||
112 | - } | ||
113 | - Set<Entry<String, JsonNode>> m = params.entrySet(); | ||
114 | - for (Entry<String, JsonNode> e : m) { | ||
115 | - String key = e.getKey(); | ||
116 | - JsonNode j = e.getValue(); | ||
117 | - if (key.equals("nodeName1")) { | ||
118 | - setNodeName1(j.asText()); | ||
119 | - } else if (key.equals("nodeName2")) { | ||
120 | - setNodeName2(j.asText()); | ||
121 | - } else if (key.equals("port1")) { | ||
122 | - setPort1(j.asInt()); | ||
123 | - } else if (key.equals("port2")) { | ||
124 | - setPort2(j.asInt()); | ||
125 | - } else { | ||
126 | - throw new UnknownPktLinkConfig(key, nodeDpid1, nodeDpid2); | ||
127 | - } | ||
128 | - } | ||
129 | - } | ||
130 | - | ||
131 | - private void validateParams() { | ||
132 | - // TODO - wrong-names, duplicate links, | ||
133 | - // duplicate use of port, is switch-allowed for which link is allowed? | ||
134 | - // valid port numbers | ||
135 | - } | ||
136 | - | ||
137 | - public static class PktLinkParamsNotSpecified extends RuntimeException { | ||
138 | - private static final long serialVersionUID = 6247582323691265513L; | ||
139 | - | ||
140 | - public PktLinkParamsNotSpecified(String dpidA, String dpidB) { | ||
141 | - super(); | ||
142 | - log.error("Params required for packet link - not specified " | ||
143 | - + "for link between switch1:{} and switch2:{}", | ||
144 | - dpidA, dpidB); | ||
145 | - } | ||
146 | - } | ||
147 | - | ||
148 | - public static class UnknownPktLinkConfig extends RuntimeException { | ||
149 | - private static final long serialVersionUID = -5750132094884129179L; | ||
150 | - | ||
151 | - public UnknownPktLinkConfig(String key, String dpidA, String dpidB) { | ||
152 | - super(); | ||
153 | - log.error("Unknown packet-link config {} for link between" | ||
154 | - + " dpid1: {} and dpid2: {}", key, | ||
155 | - dpidA, dpidB); | ||
156 | - } | ||
157 | - } | ||
158 | - | ||
159 | -} |
This diff is collapsed. Click to expand it.
apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/SegmentRoutingConfig.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2014-2015 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.config; | ||
18 | + | ||
19 | +import org.onlab.packet.Ip4Address; | ||
20 | +import org.onlab.packet.MacAddress; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | +import org.onosproject.net.config.Config; | ||
23 | +import org.onosproject.net.config.basics.BasicElementConfig; | ||
24 | + | ||
25 | +import java.util.ArrayList; | ||
26 | +import java.util.List; | ||
27 | +import java.util.Optional; | ||
28 | + | ||
29 | +/** | ||
30 | + * Configuration object for Segment Routing Application. | ||
31 | + */ | ||
32 | +public class SegmentRoutingConfig extends Config<DeviceId> { | ||
33 | + private static final String NAME = "name"; | ||
34 | + private static final String IP = "routerIp"; | ||
35 | + private static final String MAC = "routerMac"; | ||
36 | + private static final String SID = "nodeSid"; | ||
37 | + private static final String EDGE = "isEdgeRouter"; | ||
38 | + | ||
39 | + public Optional<String> getName() { | ||
40 | + String name = get(NAME, null); | ||
41 | + return name != null ? Optional.of(name) : Optional.empty(); | ||
42 | + } | ||
43 | + | ||
44 | + public BasicElementConfig setName(String name) { | ||
45 | + return (BasicElementConfig) setOrClear(NAME, name); | ||
46 | + } | ||
47 | + | ||
48 | + public Ip4Address getIp() { | ||
49 | + String ip = get(IP, null); | ||
50 | + return ip != null ? Ip4Address.valueOf(ip) : null; | ||
51 | + } | ||
52 | + | ||
53 | + public BasicElementConfig setIp(String ip) { | ||
54 | + return (BasicElementConfig) setOrClear(IP, ip); | ||
55 | + } | ||
56 | + | ||
57 | + public MacAddress getMac() { | ||
58 | + String mac = get(MAC, null); | ||
59 | + return mac != null ? MacAddress.valueOf(mac) : null; | ||
60 | + } | ||
61 | + | ||
62 | + public BasicElementConfig setMac(String mac) { | ||
63 | + return (BasicElementConfig) setOrClear(MAC, mac); | ||
64 | + } | ||
65 | + | ||
66 | + public int getSid() { | ||
67 | + return get(SID, -1); | ||
68 | + } | ||
69 | + | ||
70 | + public BasicElementConfig setSid(int sid) { | ||
71 | + return (BasicElementConfig) setOrClear(SID, sid); | ||
72 | + } | ||
73 | + | ||
74 | + public boolean isEdgeRouter() { | ||
75 | + return get(EDGE, false); | ||
76 | + } | ||
77 | + | ||
78 | + public BasicElementConfig setEdgeRouter(boolean isEdgeRouter) { | ||
79 | + return (BasicElementConfig) setOrClear(EDGE, isEdgeRouter); | ||
80 | + } | ||
81 | + | ||
82 | + // TODO extract array from JsonNode | ||
83 | + public List<AdjacencySid> getAdjacencySids() { | ||
84 | + return new ArrayList<AdjacencySid>(); | ||
85 | + } | ||
86 | + | ||
87 | + public class AdjacencySid { | ||
88 | + int sid; | ||
89 | + List<Integer> ports; | ||
90 | + | ||
91 | + public AdjacencySid(int sid, List<Integer> ports) { | ||
92 | + this.sid = sid; | ||
93 | + this.ports = ports; | ||
94 | + } | ||
95 | + | ||
96 | + public int getSid() { | ||
97 | + return sid; | ||
98 | + } | ||
99 | + | ||
100 | + public List<Integer> getPorts() { | ||
101 | + return ports; | ||
102 | + } | ||
103 | + } | ||
104 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | /* | 1 | /* |
2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2014-2015 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. | ... | ... |
1 | /* | 1 | /* |
2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2014-2015 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. | ... | ... |
-
Please register or login to post a comment