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
1829 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 | - |
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.io.File; | ||
19 | -import java.io.IOException; | ||
20 | -import java.util.ArrayList; | ||
21 | -import java.util.HashMap; | ||
22 | -import java.util.HashSet; | ||
23 | -import java.util.List; | ||
24 | -import java.util.Map; | ||
25 | -import java.util.Set; | ||
26 | -import java.util.concurrent.ConcurrentHashMap; | ||
27 | -import java.util.concurrent.ConcurrentMap; | ||
28 | - | ||
29 | -import org.onosproject.net.DeviceId; | ||
30 | -import org.onosproject.net.Link; | ||
31 | -import org.onosproject.segmentrouting.config.NetworkConfig.LinkConfig; | ||
32 | -import org.onosproject.segmentrouting.config.NetworkConfig.SwitchConfig; | ||
33 | -import org.slf4j.Logger; | ||
34 | -import org.slf4j.LoggerFactory; | ||
35 | - | ||
36 | -import com.fasterxml.jackson.core.JsonParseException; | ||
37 | -import com.fasterxml.jackson.databind.JsonMappingException; | ||
38 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
39 | - | ||
40 | -/** | ||
41 | - * NetworkConfigManager manages all network configuration for switches, links | ||
42 | - * and any other state that needs to be configured for correct network | ||
43 | - * operation. | ||
44 | - * | ||
45 | - */ | ||
46 | -public class NetworkConfigManager implements NetworkConfigService { | ||
47 | - protected static final Logger log = LoggerFactory | ||
48 | - .getLogger(NetworkConfigManager.class); | ||
49 | - private static final String CONFIG_DIR = "../config"; | ||
50 | - private static final String DEFAULT_CONFIG_FILE = "segmentrouting.conf"; | ||
51 | - private final String configFileName = DEFAULT_CONFIG_FILE; | ||
52 | - /** | ||
53 | - * JSON Config file needs to use one of the following types for defining the | ||
54 | - * kind of switch or link it wishes to configure. | ||
55 | - */ | ||
56 | - public static final String SEGMENT_ROUTER = "Router_SR"; | ||
57 | - | ||
58 | - public static final String PKT_LINK = "pktLink"; | ||
59 | - | ||
60 | - NetworkConfig networkConfig; | ||
61 | - private ConcurrentMap<DeviceId, SwitchConfig> configuredSwitches; | ||
62 | - private ConcurrentMap<Link, LinkConfig> configuredLinks; | ||
63 | - private Map<String, DeviceId> nameToDpid; | ||
64 | - | ||
65 | - @Override | ||
66 | - public SwitchConfigStatus checkSwitchConfig(DeviceId dpid) { | ||
67 | - SwitchConfig swc = configuredSwitches.get(dpid); | ||
68 | - if (networkConfig.getRestrictSwitches()) { | ||
69 | - // default deny behavior | ||
70 | - if (swc == null) { | ||
71 | - // switch is not configured - we deny this switch | ||
72 | - return new SwitchConfigStatus(NetworkConfigState.DENY, null, | ||
73 | - "Switch not configured, in network denying switches by default."); | ||
74 | - } | ||
75 | - if (swc.isAllowed()) { | ||
76 | - // switch is allowed in config, return configured attributes | ||
77 | - return new SwitchConfigStatus(NetworkConfigState.ACCEPT_ADD, swc); | ||
78 | - } else { | ||
79 | - // switch has been configured off (administratively down) | ||
80 | - return new SwitchConfigStatus(NetworkConfigState.DENY, null, | ||
81 | - "Switch configured down (allowed=false)."); | ||
82 | - } | ||
83 | - } else { | ||
84 | - // default allow behavior | ||
85 | - if (swc == null) { | ||
86 | - // no config to add | ||
87 | - return new SwitchConfigStatus(NetworkConfigState.ACCEPT, null); | ||
88 | - } | ||
89 | - if (swc.isAllowed()) { | ||
90 | - // switch is allowed in config, return configured attributes | ||
91 | - return new SwitchConfigStatus(NetworkConfigState.ACCEPT_ADD, swc); | ||
92 | - } else { | ||
93 | - // switch has been configured off (administratively down) | ||
94 | - return new SwitchConfigStatus(NetworkConfigState.DENY, null, | ||
95 | - "Switch configured down (allowed=false)."); | ||
96 | - } | ||
97 | - } | ||
98 | - | ||
99 | - } | ||
100 | - | ||
101 | - @Override | ||
102 | - public LinkConfigStatus checkLinkConfig(Link linkTuple) { | ||
103 | - LinkConfig lkc = getConfiguredLink(linkTuple); | ||
104 | - // links are always disallowed if any one of the nodes that make up the | ||
105 | - // link are disallowed | ||
106 | - DeviceId linkNode1 = linkTuple.src().deviceId(); | ||
107 | - SwitchConfigStatus scs1 = checkSwitchConfig(linkNode1); | ||
108 | - if (scs1.getConfigState() == NetworkConfigState.DENY) { | ||
109 | - return new LinkConfigStatus(NetworkConfigState.DENY, null, | ||
110 | - "Link-node: " + linkNode1 + " denied by config: " + scs1.getMsg()); | ||
111 | - } | ||
112 | - DeviceId linkNode2 = linkTuple.dst().deviceId(); | ||
113 | - SwitchConfigStatus scs2 = checkSwitchConfig(linkNode2); | ||
114 | - if (scs2.getConfigState() == NetworkConfigState.DENY) { | ||
115 | - return new LinkConfigStatus(NetworkConfigState.DENY, null, | ||
116 | - "Link-node: " + linkNode2 + " denied by config: " + scs2.getMsg()); | ||
117 | - } | ||
118 | - if (networkConfig.getRestrictLinks()) { | ||
119 | - // default deny behavior | ||
120 | - if (lkc == null) { | ||
121 | - // link is not configured - we deny this link | ||
122 | - return new LinkConfigStatus(NetworkConfigState.DENY, null, | ||
123 | - "Link not configured, in network denying links by default."); | ||
124 | - } | ||
125 | - if (lkc.isAllowed()) { | ||
126 | - // link is allowed in config, return configured attributes | ||
127 | - return new LinkConfigStatus(NetworkConfigState.ACCEPT_ADD, lkc); | ||
128 | - } else { | ||
129 | - // link has been configured off (administratively down) | ||
130 | - return new LinkConfigStatus(NetworkConfigState.DENY, null, | ||
131 | - "Link configured down (allowed=false)."); | ||
132 | - } | ||
133 | - } else { | ||
134 | - // default allow behavior | ||
135 | - if (lkc == null) { | ||
136 | - // no config to add | ||
137 | - return new LinkConfigStatus(NetworkConfigState.ACCEPT, null); | ||
138 | - } | ||
139 | - if (lkc.isAllowed()) { | ||
140 | - // link is allowed in config, return configured attributes | ||
141 | - return new LinkConfigStatus(NetworkConfigState.ACCEPT_ADD, lkc); | ||
142 | - } else { | ||
143 | - // link has been configured off (administratively down) | ||
144 | - return new LinkConfigStatus(NetworkConfigState.DENY, null, | ||
145 | - "Link configured down (allowed=false)."); | ||
146 | - } | ||
147 | - } | ||
148 | - | ||
149 | - } | ||
150 | - | ||
151 | - @Override | ||
152 | - public List<SwitchConfig> getConfiguredAllowedSwitches() { | ||
153 | - List<SwitchConfig> allowed = new ArrayList<>(); | ||
154 | - for (SwitchConfig swc : configuredSwitches.values()) { | ||
155 | - if (swc.isAllowed()) { | ||
156 | - allowed.add(swc); | ||
157 | - } | ||
158 | - } | ||
159 | - return allowed; | ||
160 | - } | ||
161 | - | ||
162 | - @Override | ||
163 | - public List<LinkConfig> getConfiguredAllowedLinks() { | ||
164 | - List<LinkConfig> allowed = new ArrayList<>(); | ||
165 | - for (LinkConfig lkc : configuredLinks.values()) { | ||
166 | - if (lkc.isAllowed()) { | ||
167 | - allowed.add(lkc); | ||
168 | - } | ||
169 | - } | ||
170 | - return allowed; | ||
171 | - } | ||
172 | - | ||
173 | - @Override | ||
174 | - public DeviceId getDpidForName(String name) { | ||
175 | - if (nameToDpid.get(name) != null) { | ||
176 | - return nameToDpid.get(name); | ||
177 | - } | ||
178 | - return null; | ||
179 | - } | ||
180 | - | ||
181 | - // ************** | ||
182 | - // Private methods | ||
183 | - // ************** | ||
184 | - | ||
185 | - private void loadNetworkConfig() { | ||
186 | - File configFile = new File(CONFIG_DIR, configFileName); | ||
187 | - ObjectMapper mapper = new ObjectMapper(); | ||
188 | - networkConfig = new NetworkConfig(); | ||
189 | - | ||
190 | - try { | ||
191 | - networkConfig = mapper.readValue(configFile, | ||
192 | - NetworkConfig.class); | ||
193 | - } catch (JsonParseException e) { | ||
194 | - String err = String.format("JsonParseException while loading network " | ||
195 | - + "config from file: %s: %s", configFileName, | ||
196 | - e.getMessage()); | ||
197 | - throw new NetworkConfigException.ErrorConfig(err); | ||
198 | - } catch (JsonMappingException e) { | ||
199 | - String err = String.format( | ||
200 | - "JsonMappingException while loading network config " | ||
201 | - + "from file: %s: %s", | ||
202 | - configFileName, | ||
203 | - e.getMessage()); | ||
204 | - throw new NetworkConfigException.ErrorConfig(err); | ||
205 | - } catch (IOException e) { | ||
206 | - String err = String.format("IOException while loading network config " | ||
207 | - + "from file: %s %s", configFileName, e.getMessage()); | ||
208 | - throw new NetworkConfigException.ErrorConfig(err); | ||
209 | - } | ||
210 | - | ||
211 | - log.info("Network config specifies: {} switches and {} links", | ||
212 | - (networkConfig.getRestrictSwitches()) | ||
213 | - ? networkConfig.getSwitchConfig().size() : "default allow", | ||
214 | - (networkConfig.getRestrictLinks()) | ||
215 | - ? networkConfig.getLinkConfig().size() : "default allow"); | ||
216 | - } | ||
217 | - | ||
218 | - private void parseNetworkConfig() { | ||
219 | - List<SwitchConfig> swConfList = networkConfig.getSwitchConfig(); | ||
220 | - List<LinkConfig> lkConfList = networkConfig.getLinkConfig(); | ||
221 | - validateSwitchConfig(swConfList); | ||
222 | - createTypeSpecificSwitchConfig(swConfList); | ||
223 | - validateLinkConfig(lkConfList); | ||
224 | - createTypeSpecificLinkConfig(lkConfList); | ||
225 | - // TODO validate reachability matrix 'names' for configured dpids | ||
226 | - } | ||
227 | - | ||
228 | - private void createTypeSpecificSwitchConfig(List<SwitchConfig> swConfList) { | ||
229 | - for (SwitchConfig swc : swConfList) { | ||
230 | - nameToDpid.put(swc.getName(), swc.getDpid()); | ||
231 | - String swtype = swc.getType(); | ||
232 | - switch (swtype) { | ||
233 | - case SEGMENT_ROUTER: | ||
234 | - SwitchConfig sr = new SegmentRouterConfig(swc); | ||
235 | - configuredSwitches.put(sr.getDpid(), sr); | ||
236 | - break; | ||
237 | - default: | ||
238 | - throw new NetworkConfigException.UnknownSwitchType(swtype, | ||
239 | - swc.getName()); | ||
240 | - } | ||
241 | - } | ||
242 | - } | ||
243 | - | ||
244 | - private void createTypeSpecificLinkConfig(List<LinkConfig> lkConfList) { | ||
245 | - for (LinkConfig lkc : lkConfList) { | ||
246 | - String lktype = lkc.getType(); | ||
247 | - switch (lktype) { | ||
248 | - case PKT_LINK: | ||
249 | - PktLinkConfig pk = new PktLinkConfig(lkc); | ||
250 | - for (Link lt : pk.getLinkTupleList()) { | ||
251 | - configuredLinks.put(lt, pk); | ||
252 | - } | ||
253 | - break; | ||
254 | - default: | ||
255 | - throw new NetworkConfigException.UnknownLinkType(lktype, | ||
256 | - lkc.getNodeDpid1(), lkc.getNodeDpid2()); | ||
257 | - } | ||
258 | - } | ||
259 | - } | ||
260 | - | ||
261 | - private void validateSwitchConfig(List<SwitchConfig> swConfList) { | ||
262 | - Set<DeviceId> swDpids = new HashSet<>(); | ||
263 | - Set<String> swNames = new HashSet<>(); | ||
264 | - for (SwitchConfig swc : swConfList) { | ||
265 | - if (swc.getNodeDpid() == null || swc.getDpid() == null) { | ||
266 | - throw new NetworkConfigException.DpidNotSpecified(swc.getName()); | ||
267 | - } | ||
268 | - // ensure both String and DeviceId values of dpid are set | ||
269 | - if (!swc.getDpid().equals(DeviceId.deviceId(swc.getNodeDpid()))) { | ||
270 | - throw new NetworkConfigException.SwitchDpidNotConverted( | ||
271 | - swc.getName()); | ||
272 | - } | ||
273 | - if (swc.getName() == null) { | ||
274 | - throw new NetworkConfigException.NameNotSpecified(swc.getDpid()); | ||
275 | - } | ||
276 | - if (swc.getType() == null) { | ||
277 | - throw new NetworkConfigException.SwitchTypeNotSpecified( | ||
278 | - swc.getDpid()); | ||
279 | - } | ||
280 | - if (!swDpids.add(swc.getDpid())) { | ||
281 | - throw new NetworkConfigException.DuplicateDpid(swc.getDpid()); | ||
282 | - } | ||
283 | - if (!swNames.add(swc.getName())) { | ||
284 | - throw new NetworkConfigException.DuplicateName(swc.getName()); | ||
285 | - } | ||
286 | - // TODO Add more validations | ||
287 | - } | ||
288 | - } | ||
289 | - | ||
290 | - private void validateLinkConfig(List<LinkConfig> lkConfList) { | ||
291 | - for (LinkConfig lkc : lkConfList) { | ||
292 | - if (lkc.getNodeDpid1() == null || lkc.getNodeDpid2() == null) { | ||
293 | - throw new NetworkConfigException.LinkDpidNotSpecified( | ||
294 | - lkc.getNodeDpid1(), lkc.getNodeDpid2()); | ||
295 | - } | ||
296 | - // ensure both String and Long values are set | ||
297 | - if (!lkc.getDpid1().equals(DeviceId.deviceId(lkc.getNodeDpid1())) || | ||
298 | - !lkc.getDpid2().equals(DeviceId.deviceId(lkc.getNodeDpid2()))) { | ||
299 | - throw new NetworkConfigException.LinkDpidNotConverted( | ||
300 | - lkc.getNodeDpid1(), lkc.getNodeDpid2()); | ||
301 | - } | ||
302 | - if (lkc.getType() == null) { | ||
303 | - throw new NetworkConfigException.LinkTypeNotSpecified( | ||
304 | - lkc.getNodeDpid1(), lkc.getNodeDpid2()); | ||
305 | - } | ||
306 | - if (configuredSwitches.get(lkc.getDpid1()) == null) { | ||
307 | - throw new NetworkConfigException.LinkForUnknownSwitchConfig( | ||
308 | - lkc.getNodeDpid1()); | ||
309 | - } | ||
310 | - if (configuredSwitches.get(lkc.getDpid2()) == null) { | ||
311 | - throw new NetworkConfigException.LinkForUnknownSwitchConfig( | ||
312 | - lkc.getNodeDpid2()); | ||
313 | - } | ||
314 | - // TODO add more validations | ||
315 | - } | ||
316 | - | ||
317 | - } | ||
318 | - | ||
319 | - private LinkConfig getConfiguredLink(Link linkTuple) { | ||
320 | - LinkConfig lkc = null; | ||
321 | - // first try the unidirectional link with the ports assigned | ||
322 | - lkc = configuredLinks.get(linkTuple); | ||
323 | - return lkc; | ||
324 | - } | ||
325 | - | ||
326 | - | ||
327 | - /** | ||
328 | - * Initializes the network configuration manager module by | ||
329 | - * loading and parsing the network configuration file. | ||
330 | - */ | ||
331 | - public void init() { | ||
332 | - loadNetworkConfig(); | ||
333 | - configuredSwitches = new ConcurrentHashMap<>(); | ||
334 | - configuredLinks = new ConcurrentHashMap<>(); | ||
335 | - nameToDpid = new HashMap<>(); | ||
336 | - parseNetworkConfig(); | ||
337 | - } | ||
338 | -} |
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 | -} |
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.io.IOException; | ||
19 | -import java.util.ArrayList; | ||
20 | -import java.util.Iterator; | ||
21 | -import java.util.List; | ||
22 | -import java.util.Map.Entry; | ||
23 | -import java.util.Set; | ||
24 | -import java.util.concurrent.ConcurrentHashMap; | ||
25 | - | ||
26 | -import org.onosproject.net.DeviceId; | ||
27 | -import org.onosproject.segmentrouting.config.NetworkConfig.SwitchConfig; | ||
28 | -import org.slf4j.Logger; | ||
29 | -import org.slf4j.LoggerFactory; | ||
30 | - | ||
31 | -import com.fasterxml.jackson.core.JsonProcessingException; | ||
32 | -import com.fasterxml.jackson.databind.JsonNode; | ||
33 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
34 | - | ||
35 | -/** | ||
36 | - * Manages additional configuration for switches configured as Segment Routers. | ||
37 | - */ | ||
38 | -public class SegmentRouterConfig extends SwitchConfig { | ||
39 | - protected static final Logger log = LoggerFactory | ||
40 | - .getLogger(SegmentRouterConfig.class); | ||
41 | - private String routerIp; | ||
42 | - private String routerMac; | ||
43 | - private int nodeSid; | ||
44 | - private boolean isEdgeRouter; | ||
45 | - private List<AdjacencySid> adjacencySids; | ||
46 | - private List<Subnet> subnets; | ||
47 | - | ||
48 | - public static final String ROUTER_IP = "routerIp"; | ||
49 | - public static final String ROUTER_MAC = "routerMac"; | ||
50 | - public static final String NODE_SID = "nodeSid"; | ||
51 | - public static final String ADJACENCY_SIDS = "adjacencySids"; | ||
52 | - public static final String SUBNETS = "subnets"; | ||
53 | - public static final String ISEDGE = "isEdgeRouter"; | ||
54 | - private static final int SRGB_MAX = 1000; | ||
55 | - | ||
56 | - /** | ||
57 | - * Parses and validates the additional configuration parameters applicable | ||
58 | - * to segment routers. | ||
59 | - * | ||
60 | - * @param swc switch configuration | ||
61 | - */ | ||
62 | - public SegmentRouterConfig(SwitchConfig swc) { | ||
63 | - this.setName(swc.getName()); | ||
64 | - this.setDpid(swc.getDpid()); | ||
65 | - this.setType(swc.getType()); | ||
66 | - this.setLatitude(swc.getLatitude()); | ||
67 | - this.setLongitude(swc.getLongitude()); | ||
68 | - this.setParams(swc.getParams()); | ||
69 | - this.setAllowed(swc.isAllowed()); | ||
70 | - publishAttributes = new ConcurrentHashMap<>(); | ||
71 | - adjacencySids = new ArrayList<>(); | ||
72 | - subnets = new ArrayList<>(); | ||
73 | - parseParams(); | ||
74 | - validateParams(); | ||
75 | - setPublishAttributes(); | ||
76 | - } | ||
77 | - | ||
78 | - /** | ||
79 | - * Returns the configured segment router IP address. | ||
80 | - * | ||
81 | - * @return ip address in string format | ||
82 | - */ | ||
83 | - public String getRouterIp() { | ||
84 | - return routerIp; | ||
85 | - } | ||
86 | - | ||
87 | - public void setRouterIp(String routerIp) { | ||
88 | - this.routerIp = routerIp; | ||
89 | - } | ||
90 | - | ||
91 | - /** | ||
92 | - * Returns the configured segment router mac address. | ||
93 | - * | ||
94 | - * @return mac address in string format | ||
95 | - */ | ||
96 | - public String getRouterMac() { | ||
97 | - return routerMac; | ||
98 | - } | ||
99 | - | ||
100 | - public void setRouterMac(String routerMac) { | ||
101 | - this.routerMac = routerMac; | ||
102 | - } | ||
103 | - | ||
104 | - /** | ||
105 | - * Returns the configured sID for a segment router. | ||
106 | - * | ||
107 | - * @return segment identifier | ||
108 | - */ | ||
109 | - public int getNodeSid() { | ||
110 | - return nodeSid; | ||
111 | - } | ||
112 | - | ||
113 | - public void setNodeSid(int nodeSid) { | ||
114 | - this.nodeSid = nodeSid; | ||
115 | - } | ||
116 | - | ||
117 | - /** | ||
118 | - * Returns the flag that indicates the configured segment router | ||
119 | - * is edge or backbone router. | ||
120 | - * | ||
121 | - * @return boolean | ||
122 | - */ | ||
123 | - public boolean isEdgeRouter() { | ||
124 | - return isEdgeRouter; | ||
125 | - } | ||
126 | - | ||
127 | - public void setIsEdgeRouter(boolean isEdge) { | ||
128 | - this.isEdgeRouter = isEdge; | ||
129 | - } | ||
130 | - | ||
131 | - /** | ||
132 | - * Class representing segment router adjacency identifier. | ||
133 | - */ | ||
134 | - public static class AdjacencySid { | ||
135 | - private int adjSid; | ||
136 | - private List<Integer> ports; | ||
137 | - | ||
138 | - public AdjacencySid(int adjSid, List<Integer> ports) { | ||
139 | - this.ports = ports; | ||
140 | - this.adjSid = adjSid; | ||
141 | - } | ||
142 | - | ||
143 | - /** | ||
144 | - * Returns the list of ports part of a segment | ||
145 | - * router adjacency identifier. | ||
146 | - * | ||
147 | - * @return list of integers | ||
148 | - */ | ||
149 | - public List<Integer> getPorts() { | ||
150 | - return ports; | ||
151 | - } | ||
152 | - | ||
153 | - public void setPorts(List<Integer> ports) { | ||
154 | - this.ports = ports; | ||
155 | - } | ||
156 | - | ||
157 | - /** | ||
158 | - * Returns the configured adjacency id of a segment router. | ||
159 | - * | ||
160 | - * @return integer | ||
161 | - */ | ||
162 | - public int getAdjSid() { | ||
163 | - return adjSid; | ||
164 | - } | ||
165 | - | ||
166 | - public void setAdjSid(int adjSid) { | ||
167 | - this.adjSid = adjSid; | ||
168 | - } | ||
169 | - } | ||
170 | - | ||
171 | - /** | ||
172 | - * Returns the configured adjacent segment IDs for a segment router. | ||
173 | - * | ||
174 | - * @return list of adjacency identifier | ||
175 | - */ | ||
176 | - public List<AdjacencySid> getAdjacencySids() { | ||
177 | - return adjacencySids; | ||
178 | - } | ||
179 | - | ||
180 | - public void setAdjacencySids(List<AdjacencySid> adjacencySids) { | ||
181 | - this.adjacencySids = adjacencySids; | ||
182 | - } | ||
183 | - | ||
184 | - /** | ||
185 | - * Class representing a subnet attached to a segment router. | ||
186 | - */ | ||
187 | - public static class Subnet { | ||
188 | - private int portNo; | ||
189 | - private String subnetIp; | ||
190 | - | ||
191 | - public Subnet(int portNo, String subnetIp) { | ||
192 | - this.portNo = portNo; | ||
193 | - this.subnetIp = subnetIp; | ||
194 | - } | ||
195 | - | ||
196 | - /** | ||
197 | - * Returns the port number of segment router on | ||
198 | - * which subnet is attached. | ||
199 | - * | ||
200 | - * @return integer | ||
201 | - */ | ||
202 | - public int getPortNo() { | ||
203 | - return portNo; | ||
204 | - } | ||
205 | - | ||
206 | - public void setPortNo(int portNo) { | ||
207 | - this.portNo = portNo; | ||
208 | - } | ||
209 | - | ||
210 | - /** | ||
211 | - * Returns the configured subnet address. | ||
212 | - * | ||
213 | - * @return subnet ip address in string format | ||
214 | - */ | ||
215 | - public String getSubnetIp() { | ||
216 | - return subnetIp; | ||
217 | - } | ||
218 | - | ||
219 | - public void setSubnetIp(String subnetIp) { | ||
220 | - this.subnetIp = subnetIp; | ||
221 | - } | ||
222 | - } | ||
223 | - | ||
224 | - /** | ||
225 | - * Returns the configured subnets for a segment router. | ||
226 | - * | ||
227 | - * @return list of subnets | ||
228 | - */ | ||
229 | - public List<Subnet> getSubnets() { | ||
230 | - return subnets; | ||
231 | - } | ||
232 | - | ||
233 | - public void setSubnets(List<Subnet> subnets) { | ||
234 | - this.subnets = subnets; | ||
235 | - } | ||
236 | - | ||
237 | - // ******************** | ||
238 | - // Helper methods | ||
239 | - // ******************** | ||
240 | - | ||
241 | - private void parseParams() { | ||
242 | - if (params == null) { | ||
243 | - throw new NetworkConfigException.ParamsNotSpecified(name); | ||
244 | - } | ||
245 | - | ||
246 | - Set<Entry<String, JsonNode>> m = params.entrySet(); | ||
247 | - for (Entry<String, JsonNode> e : m) { | ||
248 | - String key = e.getKey(); | ||
249 | - JsonNode j = e.getValue(); | ||
250 | - if (key.equals("routerIp")) { | ||
251 | - setRouterIp(j.asText()); | ||
252 | - } else if (key.equals("routerMac")) { | ||
253 | - setRouterMac(j.asText()); | ||
254 | - } else if (key.equals("nodeSid")) { | ||
255 | - setNodeSid(j.asInt()); | ||
256 | - } else if (key.equals("isEdgeRouter")) { | ||
257 | - setIsEdgeRouter(j.asBoolean()); | ||
258 | - } else if (key.equals("adjacencySids") || key.equals("subnets")) { | ||
259 | - getInnerParams(j, key); | ||
260 | - } else { | ||
261 | - throw new UnknownSegmentRouterConfig(key, dpid); | ||
262 | - } | ||
263 | - } | ||
264 | - } | ||
265 | - | ||
266 | - private void getInnerParams(JsonNode j, String innerParam) { | ||
267 | - Iterator<JsonNode> innerList = j.elements(); | ||
268 | - while (innerList.hasNext()) { | ||
269 | - Iterator<Entry<String, JsonNode>> f = innerList.next().fields(); | ||
270 | - int portNo = -1; | ||
271 | - int adjSid = -1; | ||
272 | - String subnetIp = null; | ||
273 | - List<Integer> ports = null; | ||
274 | - while (f.hasNext()) { | ||
275 | - Entry<String, JsonNode> fe = f.next(); | ||
276 | - if (fe.getKey().equals("portNo")) { | ||
277 | - portNo = fe.getValue().asInt(); | ||
278 | - } else if (fe.getKey().equals("adjSid")) { | ||
279 | - adjSid = fe.getValue().asInt(); | ||
280 | - } else if (fe.getKey().equals("subnetIp")) { | ||
281 | - subnetIp = fe.getValue().asText(); | ||
282 | - } else if (fe.getKey().equals("ports")) { | ||
283 | - if (fe.getValue().isArray()) { | ||
284 | - Iterator<JsonNode> i = fe.getValue().elements(); | ||
285 | - ports = new ArrayList<>(); | ||
286 | - while (i.hasNext()) { | ||
287 | - ports.add(i.next().asInt()); | ||
288 | - } | ||
289 | - } | ||
290 | - } else { | ||
291 | - throw new UnknownSegmentRouterConfig(fe.getKey(), dpid); | ||
292 | - } | ||
293 | - } | ||
294 | - if (innerParam.equals("adjacencySids")) { | ||
295 | - AdjacencySid ads = new AdjacencySid(adjSid, ports); | ||
296 | - adjacencySids.add(ads); | ||
297 | - } else { | ||
298 | - Subnet sip = new Subnet(portNo, subnetIp); | ||
299 | - subnets.add(sip); | ||
300 | - } | ||
301 | - } | ||
302 | - } | ||
303 | - | ||
304 | - private void validateParams() { | ||
305 | - if (routerIp == null) { | ||
306 | - throw new IpNotSpecified(dpid); | ||
307 | - } | ||
308 | - if (routerMac == null) { | ||
309 | - throw new MacNotSpecified(dpid); | ||
310 | - } | ||
311 | - if (isEdgeRouter && subnets.isEmpty()) { | ||
312 | - throw new SubnetNotSpecifiedInEdgeRouter(dpid); | ||
313 | - } | ||
314 | - if (!isEdgeRouter && !subnets.isEmpty()) { | ||
315 | - throw new SubnetSpecifiedInBackboneRouter(dpid); | ||
316 | - } | ||
317 | - if (nodeSid > SRGB_MAX) { | ||
318 | - throw new NodeLabelNotInSRGB(nodeSid, dpid); | ||
319 | - } | ||
320 | - for (AdjacencySid as : adjacencySids) { | ||
321 | - int label = as.getAdjSid(); | ||
322 | - List<Integer> plist = as.getPorts(); | ||
323 | - if (label <= SRGB_MAX) { | ||
324 | - throw new AdjacencyLabelInSRGB(label, dpid); | ||
325 | - } | ||
326 | - if (plist.size() <= 1) { | ||
327 | - throw new AdjacencyLabelNotEnoughPorts(label, dpid); | ||
328 | - } | ||
329 | - } | ||
330 | - | ||
331 | - | ||
332 | - // TODO more validations | ||
333 | - } | ||
334 | - | ||
335 | - /** | ||
336 | - * Setting publishAttributes implies that this is the configuration that | ||
337 | - * will be added to Topology.Switch object before it is published on the | ||
338 | - * channel to other controller instances. | ||
339 | - */ | ||
340 | - private void setPublishAttributes() { | ||
341 | - publishAttributes.put(ROUTER_IP, routerIp); | ||
342 | - publishAttributes.put(ROUTER_MAC, routerMac); | ||
343 | - publishAttributes.put(NODE_SID, String.valueOf(nodeSid)); | ||
344 | - publishAttributes.put(ISEDGE, String.valueOf(isEdgeRouter)); | ||
345 | - ObjectMapper mapper = new ObjectMapper(); | ||
346 | - try { | ||
347 | - publishAttributes.put(ADJACENCY_SIDS, | ||
348 | - mapper.writeValueAsString(adjacencySids)); | ||
349 | - publishAttributes.put(SUBNETS, | ||
350 | - mapper.writeValueAsString(subnets)); | ||
351 | - } catch (JsonProcessingException e) { | ||
352 | - log.error("Error while writing SR config: {}", e.getCause()); | ||
353 | - } catch (IOException e) { | ||
354 | - log.error("Error while writing SR config: {}", e.getCause()); | ||
355 | - } | ||
356 | - } | ||
357 | - | ||
358 | - // ******************** | ||
359 | - // Exceptions | ||
360 | - // ******************** | ||
361 | - | ||
362 | - public static class IpNotSpecified extends RuntimeException { | ||
363 | - private static final long serialVersionUID = -3001502553646331686L; | ||
364 | - | ||
365 | - public IpNotSpecified(DeviceId dpid) { | ||
366 | - super(); | ||
367 | - log.error("Router IP address not specified for SR config dpid:{}", | ||
368 | - dpid); | ||
369 | - } | ||
370 | - } | ||
371 | - | ||
372 | - public static class MacNotSpecified extends RuntimeException { | ||
373 | - private static final long serialVersionUID = -5850132094884129179L; | ||
374 | - | ||
375 | - public MacNotSpecified(DeviceId dpid) { | ||
376 | - super(); | ||
377 | - log.error("Router Mac address not specified for SR config dpid:{}", | ||
378 | - dpid); | ||
379 | - } | ||
380 | - } | ||
381 | - | ||
382 | - public static class UnknownSegmentRouterConfig extends RuntimeException { | ||
383 | - private static final long serialVersionUID = -5750132094884129179L; | ||
384 | - | ||
385 | - public UnknownSegmentRouterConfig(String key, DeviceId dpid) { | ||
386 | - super(); | ||
387 | - log.error("Unknown Segment Router config {} in dpid: {}", key, | ||
388 | - dpid); | ||
389 | - } | ||
390 | - } | ||
391 | - | ||
392 | - public static class SubnetNotSpecifiedInEdgeRouter extends RuntimeException { | ||
393 | - private static final long serialVersionUID = -5855458472668581268L; | ||
394 | - | ||
395 | - public SubnetNotSpecifiedInEdgeRouter(DeviceId dpid) { | ||
396 | - super(); | ||
397 | - log.error("Subnet was not specified for edge router in dpid: {}", | ||
398 | - dpid); | ||
399 | - } | ||
400 | - } | ||
401 | - | ||
402 | - public static class SubnetSpecifiedInBackboneRouter extends RuntimeException { | ||
403 | - private static final long serialVersionUID = 1L; | ||
404 | - | ||
405 | - public SubnetSpecifiedInBackboneRouter(DeviceId dpid) { | ||
406 | - super(); | ||
407 | - log.error("Subnet was specified in backbone router in dpid: {}", | ||
408 | - dpid); | ||
409 | - } | ||
410 | - } | ||
411 | - | ||
412 | - public static class NodeLabelNotInSRGB extends RuntimeException { | ||
413 | - private static final long serialVersionUID = -8482670903748519526L; | ||
414 | - | ||
415 | - public NodeLabelNotInSRGB(int label, DeviceId dpid) { | ||
416 | - super(); | ||
417 | - log.error("Node sif {} specified in not in global label-base " | ||
418 | - + "in dpid: {}", label, | ||
419 | - dpid); | ||
420 | - } | ||
421 | - } | ||
422 | - | ||
423 | - public static class AdjacencyLabelInSRGB extends RuntimeException { | ||
424 | - private static final long serialVersionUID = -8482670903748519526L; | ||
425 | - | ||
426 | - public AdjacencyLabelInSRGB(int label, DeviceId dpid) { | ||
427 | - super(); | ||
428 | - log.error("Adjaceny label {} specified from global label-base " | ||
429 | - + "in dpid: {}", label, | ||
430 | - dpid); | ||
431 | - } | ||
432 | - } | ||
433 | - | ||
434 | - public static class AdjacencyLabelNotEnoughPorts extends RuntimeException { | ||
435 | - private static final long serialVersionUID = -8482670903748519526L; | ||
436 | - | ||
437 | - public AdjacencyLabelNotEnoughPorts(int label, DeviceId dpid) { | ||
438 | - super(); | ||
439 | - log.error("Adjaceny label {} must be specified for at least 2 ports. " | ||
440 | - + "Adjacency labels for single ports are auto-generated " | ||
441 | - + "in dpid: {}", label, | ||
442 | - dpid); | ||
443 | - } | ||
444 | - } | ||
445 | -} |
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