Committed by
Ray Milkey
CORD-352 Refactoring SegmentRoutingConfig
- Add Javadoc and fix function name convention - Add setAdjancencySids method - Change return value of getAdjacencySids from List to ImmutableSet - Validate config value - Add unit test for SegmentRoutingConfig Change-Id: Ic43ac31a49da8a9d62131d7803930280cf9994d2
Showing
6 changed files
with
335 additions
and
97 deletions
... | @@ -89,6 +89,11 @@ | ... | @@ -89,6 +89,11 @@ |
89 | <groupId>org.osgi</groupId> | 89 | <groupId>org.osgi</groupId> |
90 | <artifactId>org.osgi.core</artifactId> | 90 | <artifactId>org.osgi.core</artifactId> |
91 | </dependency> | 91 | </dependency> |
92 | + <dependency> | ||
93 | + <groupId>org.onosproject</groupId> | ||
94 | + <artifactId>onlab-junit</artifactId> | ||
95 | + <scope>test</scope> | ||
96 | + </dependency> | ||
92 | </dependencies> | 97 | </dependencies> |
93 | 98 | ||
94 | <build> | 99 | <build> | ... | ... |
... | @@ -158,7 +158,7 @@ public class TunnelHandler { | ... | @@ -158,7 +158,7 @@ public class TunnelHandler { |
158 | 158 | ||
159 | private int createGroupsForTunnel(Tunnel tunnel) { | 159 | private int createGroupsForTunnel(Tunnel tunnel) { |
160 | 160 | ||
161 | - List<Integer> portNumbers; | 161 | + Set<Integer> portNumbers; |
162 | final int groupError = -1; | 162 | final int groupError = -1; |
163 | 163 | ||
164 | DeviceId deviceId = config.getDeviceId(tunnel.labelIds().get(0)); | 164 | DeviceId deviceId = config.getDeviceId(tunnel.labelIds().get(0)); | ... | ... |
... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
16 | package org.onosproject.segmentrouting.config; | 16 | package org.onosproject.segmentrouting.config; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableSet; | 18 | import com.google.common.collect.ImmutableSet; |
19 | -import com.google.common.collect.Lists; | ||
20 | import org.onlab.packet.Ip4Address; | 19 | import org.onlab.packet.Ip4Address; |
21 | import org.onlab.packet.Ip4Prefix; | 20 | import org.onlab.packet.Ip4Prefix; |
22 | import org.onlab.packet.MacAddress; | 21 | import org.onlab.packet.MacAddress; |
... | @@ -26,7 +25,6 @@ import org.onosproject.incubator.net.intf.Interface; | ... | @@ -26,7 +25,6 @@ import org.onosproject.incubator.net.intf.Interface; |
26 | import org.onosproject.net.ConnectPoint; | 25 | import org.onosproject.net.ConnectPoint; |
27 | import org.onosproject.net.config.NetworkConfigRegistry; | 26 | import org.onosproject.net.config.NetworkConfigRegistry; |
28 | import org.onosproject.net.host.InterfaceIpAddress; | 27 | import org.onosproject.net.host.InterfaceIpAddress; |
29 | -import org.onosproject.segmentrouting.config.SegmentRoutingConfig.AdjacencySid; | ||
30 | import org.onosproject.net.DeviceId; | 28 | import org.onosproject.net.DeviceId; |
31 | import org.onosproject.net.PortNumber; | 29 | import org.onosproject.net.PortNumber; |
32 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
... | @@ -34,6 +32,7 @@ import org.slf4j.LoggerFactory; | ... | @@ -34,6 +32,7 @@ import org.slf4j.LoggerFactory; |
34 | 32 | ||
35 | import java.util.ArrayList; | 33 | import java.util.ArrayList; |
36 | import java.util.HashMap; | 34 | import java.util.HashMap; |
35 | +import java.util.HashSet; | ||
37 | import java.util.List; | 36 | import java.util.List; |
38 | import java.util.Map; | 37 | import java.util.Map; |
39 | import java.util.Set; | 38 | import java.util.Set; |
... | @@ -60,7 +59,7 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -60,7 +59,7 @@ 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<AdjacencySid> adjacencySids; | 62 | + Map<Integer, Set<Integer>> adjacencySids; |
64 | 63 | ||
65 | public SegmentRouterInfo() { | 64 | public SegmentRouterInfo() { |
66 | this.gatewayIps = new HashMap<>(); | 65 | this.gatewayIps = new HashMap<>(); |
... | @@ -83,11 +82,11 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -83,11 +82,11 @@ public class DeviceConfiguration implements DeviceProperties { |
83 | cfgService.getConfig(subject, SegmentRoutingConfig.class); | 82 | cfgService.getConfig(subject, SegmentRoutingConfig.class); |
84 | SegmentRouterInfo info = new SegmentRouterInfo(); | 83 | SegmentRouterInfo info = new SegmentRouterInfo(); |
85 | info.deviceId = subject; | 84 | info.deviceId = subject; |
86 | - info.nodeSid = config.getSid(); | 85 | + info.nodeSid = config.nodeSid(); |
87 | - info.ip = config.getIp(); | 86 | + info.ip = config.routerIp(); |
88 | - info.mac = config.getMac(); | 87 | + info.mac = config.routerMac(); |
89 | info.isEdge = config.isEdgeRouter(); | 88 | info.isEdge = config.isEdgeRouter(); |
90 | - info.adjacencySids = config.getAdjacencySids(); | 89 | + info.adjacencySids = config.adjacencySids(); |
91 | 90 | ||
92 | this.deviceConfigMap.put(info.deviceId, info); | 91 | this.deviceConfigMap.put(info.deviceId, info); |
93 | this.allSegmentIds.add(info.nodeSid); | 92 | this.allSegmentIds.add(info.nodeSid); |
... | @@ -410,19 +409,13 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -410,19 +409,13 @@ public class DeviceConfiguration implements DeviceProperties { |
410 | * | 409 | * |
411 | * @param deviceId device identification of the router | 410 | * @param deviceId device identification of the router |
412 | * @param sid adjacency Sid | 411 | * @param sid adjacency Sid |
413 | - * @return list of port numbers | 412 | + * @return set of port numbers |
414 | */ | 413 | */ |
415 | - public List<Integer> getPortsForAdjacencySid(DeviceId deviceId, int sid) { | 414 | + public Set<Integer> getPortsForAdjacencySid(DeviceId deviceId, int sid) { |
416 | SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); | 415 | SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); |
417 | - if (srinfo != null) { | 416 | + return srinfo != null ? |
418 | - for (AdjacencySid asid : srinfo.adjacencySids) { | 417 | + ImmutableSet.copyOf(srinfo.adjacencySids.get(sid)) : |
419 | - if (asid.getAsid() == sid) { | 418 | + ImmutableSet.copyOf(new HashSet<>()); |
420 | - return asid.getPorts(); | ||
421 | - } | ||
422 | - } | ||
423 | - } | ||
424 | - | ||
425 | - return Lists.newArrayList(); | ||
426 | } | 419 | } |
427 | 420 | ||
428 | /** | 421 | /** |
... | @@ -435,20 +428,6 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -435,20 +428,6 @@ public class DeviceConfiguration implements DeviceProperties { |
435 | */ | 428 | */ |
436 | public boolean isAdjacencySid(DeviceId deviceId, int sid) { | 429 | public boolean isAdjacencySid(DeviceId deviceId, int sid) { |
437 | SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); | 430 | SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); |
438 | - if (srinfo != null) { | 431 | + return srinfo != null && srinfo.adjacencySids.containsKey(sid); |
439 | - if (srinfo.adjacencySids.isEmpty()) { | ||
440 | - return false; | ||
441 | - } else { | ||
442 | - for (AdjacencySid asid: | ||
443 | - srinfo.adjacencySids) { | ||
444 | - if (asid.getAsid() == sid) { | ||
445 | - return true; | ||
446 | - } | ||
447 | - } | ||
448 | - return false; | ||
449 | - } | ||
450 | - } | ||
451 | - | ||
452 | - return false; | ||
453 | } | 432 | } |
454 | } | 433 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,113 +16,210 @@ | ... | @@ -16,113 +16,210 @@ |
16 | 16 | ||
17 | package org.onosproject.segmentrouting.config; | 17 | package org.onosproject.segmentrouting.config; |
18 | 18 | ||
19 | +import com.fasterxml.jackson.databind.JsonNode; | ||
19 | import com.fasterxml.jackson.databind.node.ArrayNode; | 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
21 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
22 | +import com.google.common.collect.ImmutableMap; | ||
20 | import org.onlab.packet.Ip4Address; | 23 | import org.onlab.packet.Ip4Address; |
21 | import org.onlab.packet.MacAddress; | 24 | import org.onlab.packet.MacAddress; |
22 | import org.onosproject.net.DeviceId; | 25 | import org.onosproject.net.DeviceId; |
23 | import org.onosproject.net.config.Config; | 26 | import org.onosproject.net.config.Config; |
24 | -import org.onosproject.net.config.basics.BasicElementConfig; | ||
25 | 27 | ||
26 | -import java.util.ArrayList; | 28 | +import java.util.HashMap; |
27 | -import java.util.List; | 29 | +import java.util.HashSet; |
30 | +import java.util.Map; | ||
28 | import java.util.Optional; | 31 | import java.util.Optional; |
32 | +import java.util.Set; | ||
29 | 33 | ||
30 | /** | 34 | /** |
31 | * Configuration object for Segment Routing Application. | 35 | * Configuration object for Segment Routing Application. |
32 | */ | 36 | */ |
33 | public class SegmentRoutingConfig extends Config<DeviceId> { | 37 | public class SegmentRoutingConfig extends Config<DeviceId> { |
34 | - private static final String NAME = "name"; | 38 | + public static final String NAME = "name"; |
35 | - private static final String IP = "routerIp"; | 39 | + public static final String IP = "routerIp"; |
36 | - private static final String MAC = "routerMac"; | 40 | + public static final String MAC = "routerMac"; |
37 | - private static final String SID = "nodeSid"; | 41 | + public static final String SID = "nodeSid"; |
38 | - private static final String EDGE = "isEdgeRouter"; | 42 | + public static final String EDGE = "isEdgeRouter"; |
39 | - private static final String ADJSID = "adjacencySids"; | 43 | + public static final String ADJSIDS = "adjacencySids"; |
40 | - | 44 | + public static final String ADJSID = "adjSid"; |
41 | - public Optional<String> getName() { | 45 | + public static final String PORTS = "ports"; |
46 | + | ||
47 | + @Override | ||
48 | + public boolean isValid() { | ||
49 | + return hasOnlyFields(NAME, IP, MAC, SID, EDGE, ADJSIDS, ADJSID, PORTS) && | ||
50 | + this.name() != null && | ||
51 | + this.routerIp() != null && | ||
52 | + this.routerMac() != null && | ||
53 | + this.nodeSid() != -1 && | ||
54 | + this.isEdgeRouter() != null && | ||
55 | + this.adjacencySids() != null; | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * Gets the name of the router. | ||
60 | + * | ||
61 | + * @return Optional name of the router. May be empty if not configured. | ||
62 | + */ | ||
63 | + public Optional<String> name() { | ||
42 | String name = get(NAME, null); | 64 | String name = get(NAME, null); |
43 | return name != null ? Optional.of(name) : Optional.empty(); | 65 | return name != null ? Optional.of(name) : Optional.empty(); |
44 | } | 66 | } |
45 | 67 | ||
46 | - public BasicElementConfig setName(String name) { | 68 | + /** |
47 | - return (BasicElementConfig) setOrClear(NAME, name); | 69 | + * Sets the name of the router. |
70 | + * | ||
71 | + * @param name name of the router. | ||
72 | + * @return the config of the router. | ||
73 | + */ | ||
74 | + public SegmentRoutingConfig setName(String name) { | ||
75 | + return (SegmentRoutingConfig) setOrClear(NAME, name); | ||
48 | } | 76 | } |
49 | 77 | ||
50 | - public Ip4Address getIp() { | 78 | + /** |
79 | + * Gets the IP address of the router. | ||
80 | + * | ||
81 | + * @return IP address of the router. Or null if not configured. | ||
82 | + */ | ||
83 | + public Ip4Address routerIp() { | ||
51 | String ip = get(IP, null); | 84 | String ip = get(IP, null); |
52 | return ip != null ? Ip4Address.valueOf(ip) : null; | 85 | return ip != null ? Ip4Address.valueOf(ip) : null; |
53 | } | 86 | } |
54 | 87 | ||
55 | - public BasicElementConfig setIp(String ip) { | 88 | + /** |
56 | - return (BasicElementConfig) setOrClear(IP, ip); | 89 | + * Sets the IP address of the router. |
90 | + * | ||
91 | + * @param ip IP address of the router. | ||
92 | + * @return the config of the router. | ||
93 | + */ | ||
94 | + public SegmentRoutingConfig setRouterIp(String ip) { | ||
95 | + return (SegmentRoutingConfig) setOrClear(IP, ip); | ||
57 | } | 96 | } |
58 | 97 | ||
59 | - public MacAddress getMac() { | 98 | + /** |
99 | + * Gets the MAC address of the router. | ||
100 | + * | ||
101 | + * @return MAC address of the router. Or null if not configured. | ||
102 | + */ | ||
103 | + public MacAddress routerMac() { | ||
60 | String mac = get(MAC, null); | 104 | String mac = get(MAC, null); |
61 | return mac != null ? MacAddress.valueOf(mac) : null; | 105 | return mac != null ? MacAddress.valueOf(mac) : null; |
62 | } | 106 | } |
63 | 107 | ||
64 | - public BasicElementConfig setMac(String mac) { | 108 | + /** |
65 | - return (BasicElementConfig) setOrClear(MAC, mac); | 109 | + * Sets the MAC address of the router. |
110 | + * | ||
111 | + * @param mac MAC address of the router. | ||
112 | + * @return the config of the router. | ||
113 | + */ | ||
114 | + public SegmentRoutingConfig setRouterMac(String mac) { | ||
115 | + return (SegmentRoutingConfig) setOrClear(MAC, mac); | ||
66 | } | 116 | } |
67 | 117 | ||
68 | - public int getSid() { | 118 | + /** |
119 | + * Gets the node SID of the router. | ||
120 | + * | ||
121 | + * @return node SID of the router. Or -1 if not configured. | ||
122 | + */ | ||
123 | + public int nodeSid() { | ||
69 | return get(SID, -1); | 124 | return get(SID, -1); |
70 | } | 125 | } |
71 | 126 | ||
72 | - public BasicElementConfig setSid(int sid) { | 127 | + /** |
73 | - return (BasicElementConfig) setOrClear(SID, sid); | 128 | + * Sets the node SID of the router. |
129 | + * | ||
130 | + * @param sid node SID of the router. | ||
131 | + * @return the config of the router. | ||
132 | + */ | ||
133 | + public SegmentRoutingConfig setNodeSid(int sid) { | ||
134 | + return (SegmentRoutingConfig) setOrClear(SID, sid); | ||
74 | } | 135 | } |
75 | 136 | ||
76 | - public boolean isEdgeRouter() { | 137 | + /** |
77 | - return get(EDGE, false); | 138 | + * Checks if the router is an edge router. |
139 | + * | ||
140 | + * @return true if the router is an edge router. | ||
141 | + * false if the router is not an edge router. | ||
142 | + * null if the value is not configured. | ||
143 | + */ | ||
144 | + public Boolean isEdgeRouter() { | ||
145 | + String isEdgeRouter = get(EDGE, null); | ||
146 | + return isEdgeRouter != null ? | ||
147 | + Boolean.valueOf(isEdgeRouter) : | ||
148 | + null; | ||
78 | } | 149 | } |
79 | 150 | ||
80 | - public BasicElementConfig setEdgeRouter(boolean isEdgeRouter) { | 151 | + /** |
81 | - return (BasicElementConfig) setOrClear(EDGE, isEdgeRouter); | 152 | + * Specifies if the router is an edge router. |
153 | + * | ||
154 | + * @param isEdgeRouter true if the router is an edge router. | ||
155 | + * @return the config of the router. | ||
156 | + */ | ||
157 | + public SegmentRoutingConfig setIsEdgeRouter(boolean isEdgeRouter) { | ||
158 | + return (SegmentRoutingConfig) setOrClear(EDGE, isEdgeRouter); | ||
82 | } | 159 | } |
83 | 160 | ||
84 | - public List<AdjacencySid> getAdjacencySids() { | 161 | + /** |
85 | - ArrayList<AdjacencySid> adjacencySids = new ArrayList<>(); | 162 | + * Gets the adjacency SIDs of the router. |
86 | - | 163 | + * |
87 | - if (!object.has(ADJSID)) { | 164 | + * @return adjacency SIDs of the router. Or null if not configured. |
88 | - return adjacencySids; | 165 | + */ |
166 | + public Map<Integer, Set<Integer>> adjacencySids() { | ||
167 | + if (!object.has(ADJSIDS)) { | ||
168 | + return null; | ||
89 | } | 169 | } |
90 | 170 | ||
91 | - ArrayNode adjacencySidNodes = (ArrayNode) object.path(ADJSID); | 171 | + Map<Integer, Set<Integer>> adjacencySids = new HashMap<>(); |
92 | - adjacencySidNodes.forEach(adjacencySidNode -> { | 172 | + ArrayNode adjacencySidsNode = (ArrayNode) object.path(ADJSIDS); |
93 | - int asid = adjacencySidNode.path(AdjacencySid.ASID).asInt(); | 173 | + for (JsonNode adjacencySidNode : adjacencySidsNode) { |
94 | - | 174 | + int asid = adjacencySidNode.path(ADJSID).asInt(-1); |
95 | - ArrayList<Integer> ports = new ArrayList<Integer>(); | 175 | + if (asid == -1) { |
96 | - ArrayNode portsNodes = (ArrayNode) adjacencySidNode.path(AdjacencySid.PORTS); | 176 | + return null; |
97 | - portsNodes.forEach(portNode -> { | 177 | + } |
98 | - ports.add(portNode.asInt()); | 178 | + |
99 | - }); | 179 | + HashSet<Integer> ports = new HashSet<>(); |
100 | - | 180 | + ArrayNode portsNode = (ArrayNode) adjacencySidNode.path(PORTS); |
101 | - AdjacencySid adjacencySid = new AdjacencySid(asid, ports); | 181 | + for (JsonNode portNode : portsNode) { |
102 | - adjacencySids.add(adjacencySid); | 182 | + int port = portNode.asInt(-1); |
103 | - }); | 183 | + if (port == -1) { |
184 | + return null; | ||
185 | + } | ||
186 | + ports.add(port); | ||
187 | + } | ||
188 | + adjacencySids.put(asid, ports); | ||
189 | + } | ||
104 | 190 | ||
105 | - return adjacencySids; | 191 | + return ImmutableMap.copyOf(adjacencySids); |
106 | } | 192 | } |
107 | 193 | ||
108 | - public class AdjacencySid { | 194 | + /** |
109 | - private static final String ASID = "adjSid"; | 195 | + * Sets the adjacency SIDs of the router. |
110 | - private static final String PORTS = "ports"; | 196 | + * |
111 | - | 197 | + * @param adjacencySids adjacency SIDs of the router. |
112 | - int asid; | 198 | + * @return the config of the router. |
113 | - List<Integer> ports; | 199 | + */ |
114 | - | 200 | + public SegmentRoutingConfig setAdjacencySids(Map<Integer, Set<Integer>> adjacencySids) { |
115 | - public AdjacencySid(int asid, List<Integer> ports) { | 201 | + if (adjacencySids == null) { |
116 | - this.asid = asid; | 202 | + object.remove(ADJSIDS); |
117 | - this.ports = ports; | 203 | + } else { |
118 | - } | 204 | + ArrayNode adjacencySidsNode = mapper.createArrayNode(); |
205 | + | ||
206 | + adjacencySids.forEach((sid, ports) -> { | ||
207 | + ObjectNode adjacencySidNode = mapper.createObjectNode(); | ||
208 | + | ||
209 | + adjacencySidNode.put(ADJSID, sid); | ||
210 | + | ||
211 | + ArrayNode portsNode = mapper.createArrayNode(); | ||
212 | + ports.forEach(port -> { | ||
213 | + portsNode.add(port.toString()); | ||
214 | + }); | ||
215 | + adjacencySidNode.set(PORTS, portsNode); | ||
216 | + | ||
217 | + adjacencySidsNode.add(adjacencySidNode); | ||
218 | + }); | ||
119 | 219 | ||
120 | - public int getAsid() { | 220 | + object.set(ADJSIDS, adjacencySidsNode); |
121 | - return asid; | ||
122 | } | 221 | } |
123 | 222 | ||
124 | - public List<Integer> getPorts() { | 223 | + return this; |
125 | - return ports; | ||
126 | - } | ||
127 | } | 224 | } |
128 | } | 225 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
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 com.fasterxml.jackson.databind.JsonNode; | ||
20 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onlab.packet.IpAddress; | ||
24 | +import org.onlab.packet.MacAddress; | ||
25 | +import org.onosproject.net.DeviceId; | ||
26 | +import org.onosproject.net.config.Config; | ||
27 | +import org.onosproject.net.config.ConfigApplyDelegate; | ||
28 | + | ||
29 | +import java.util.HashMap; | ||
30 | +import java.util.HashSet; | ||
31 | +import java.util.Map; | ||
32 | +import java.util.Set; | ||
33 | + | ||
34 | +import static org.junit.Assert.assertThat; | ||
35 | +import static org.hamcrest.Matchers.is; | ||
36 | +import static org.junit.Assert.assertTrue; | ||
37 | + | ||
38 | +/** | ||
39 | + * Tests for class {@link SegmentRoutingConfig}. | ||
40 | + */ | ||
41 | +public class SegmentRoutingConfigTest { | ||
42 | + private SegmentRoutingConfig config; | ||
43 | + private Map<Integer, Set<Integer>> adjacencySids1; | ||
44 | + private Map<Integer, Set<Integer>> adjacencySids2; | ||
45 | + | ||
46 | + @Before | ||
47 | + public void setUp() throws Exception { | ||
48 | + String jsonString = "{" + | ||
49 | + "\"name\" : \"Leaf-R1\"," + | ||
50 | + "\"nodeSid\" : 101," + | ||
51 | + "\"routerIp\" : \"10.0.1.254\"," + | ||
52 | + "\"routerMac\" : \"00:00:00:00:01:80\"," + | ||
53 | + "\"isEdgeRouter\" : true," + | ||
54 | + "\"adjacencySids\" : [" + | ||
55 | + " { \"adjSid\" : 100, \"ports\" : [2, 3] }," + | ||
56 | + " { \"adjSid\" : 200, \"ports\" : [4, 5] }" + | ||
57 | + "]}"; | ||
58 | + | ||
59 | + adjacencySids1 = new HashMap<>(); | ||
60 | + Set<Integer> ports1 = new HashSet<>(); | ||
61 | + ports1.add(2); | ||
62 | + ports1.add(3); | ||
63 | + adjacencySids1.put(100, ports1); | ||
64 | + Set<Integer> ports2 = new HashSet<>(); | ||
65 | + ports2.add(4); | ||
66 | + ports2.add(5); | ||
67 | + adjacencySids1.put(200, ports2); | ||
68 | + | ||
69 | + adjacencySids2 = new HashMap<>(); | ||
70 | + Set<Integer> ports3 = new HashSet<>(); | ||
71 | + ports3.add(6); | ||
72 | + adjacencySids2.put(300, ports3); | ||
73 | + | ||
74 | + DeviceId subject = DeviceId.deviceId("of:0000000000000001"); | ||
75 | + String key = "org.onosproject.segmentrouting"; | ||
76 | + ObjectMapper mapper = new ObjectMapper(); | ||
77 | + JsonNode jsonNode = mapper.readTree(jsonString); | ||
78 | + ConfigApplyDelegate delegate = new MockDelegate(); | ||
79 | + | ||
80 | + config = new SegmentRoutingConfig(); | ||
81 | + config.init(subject, key, jsonNode, mapper, delegate); | ||
82 | + } | ||
83 | + | ||
84 | + @Test | ||
85 | + public void testName() throws Exception { | ||
86 | + assertTrue(config.name().isPresent()); | ||
87 | + assertThat(config.name().get(), is("Leaf-R1")); | ||
88 | + } | ||
89 | + | ||
90 | + @Test | ||
91 | + public void testSetName() throws Exception { | ||
92 | + config.setName("Spine-R1"); | ||
93 | + assertTrue(config.name().isPresent()); | ||
94 | + assertThat(config.name().get(), is("Spine-R1")); | ||
95 | + } | ||
96 | + | ||
97 | + @Test | ||
98 | + public void testRouterIp() throws Exception { | ||
99 | + assertThat(config.routerIp(), is(IpAddress.valueOf("10.0.1.254"))); | ||
100 | + } | ||
101 | + | ||
102 | + @Test | ||
103 | + public void testSetRouterIp() throws Exception { | ||
104 | + config.setRouterIp("10.0.2.254"); | ||
105 | + assertThat(config.routerIp(), is(IpAddress.valueOf("10.0.2.254"))); | ||
106 | + } | ||
107 | + | ||
108 | + @Test | ||
109 | + public void testRouterMac() throws Exception { | ||
110 | + assertThat(config.routerMac(), is(MacAddress.valueOf("00:00:00:00:01:80"))); | ||
111 | + } | ||
112 | + | ||
113 | + @Test | ||
114 | + public void testSetRouterMac() throws Exception { | ||
115 | + config.setRouterMac("00:00:00:00:02:80"); | ||
116 | + assertThat(config.routerMac(), is(MacAddress.valueOf("00:00:00:00:02:80"))); | ||
117 | + } | ||
118 | + | ||
119 | + @Test | ||
120 | + public void testNodeSid() throws Exception { | ||
121 | + assertThat(config.nodeSid(), is(101)); | ||
122 | + } | ||
123 | + | ||
124 | + @Test | ||
125 | + public void testSetNodeSid() throws Exception { | ||
126 | + config.setNodeSid(200); | ||
127 | + assertThat(config.nodeSid(), is(200)); | ||
128 | + } | ||
129 | + | ||
130 | + @Test | ||
131 | + public void testIsEdgeRouter() throws Exception { | ||
132 | + assertThat(config.isEdgeRouter(), is(true)); | ||
133 | + } | ||
134 | + | ||
135 | + @Test | ||
136 | + public void testSetIsEdgeRouter() throws Exception { | ||
137 | + config.setIsEdgeRouter(false); | ||
138 | + assertThat(config.isEdgeRouter(), is(false)); | ||
139 | + } | ||
140 | + | ||
141 | + @Test | ||
142 | + public void testAdjacencySids() throws Exception { | ||
143 | + assertThat(config.adjacencySids(), is(adjacencySids1)); | ||
144 | + } | ||
145 | + | ||
146 | + @Test | ||
147 | + public void testSetAdjacencySids() throws Exception { | ||
148 | + config.setAdjacencySids(adjacencySids2); | ||
149 | + assertThat(config.adjacencySids(), is(adjacencySids2)); | ||
150 | + } | ||
151 | + | ||
152 | + private class MockDelegate implements ConfigApplyDelegate { | ||
153 | + @Override | ||
154 | + public void onApply(Config config) { | ||
155 | + } | ||
156 | + } | ||
157 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -28,8 +28,8 @@ | ... | @@ -28,8 +28,8 @@ |
28 | "routerMac" : "00:00:00:00:01:80", | 28 | "routerMac" : "00:00:00:00:01:80", |
29 | "isEdgeRouter" : true, | 29 | "isEdgeRouter" : true, |
30 | "adjacencySids" : [ | 30 | "adjacencySids" : [ |
31 | - { "sid" : 100, "ports" : [2, 3] }, | 31 | + { "adjSids" : 100, "ports" : [2, 3] }, |
32 | - { "sid" : 200, "ports" : [4, 5] } | 32 | + { "adjSids" : 200, "ports" : [4, 5] } |
33 | ] | 33 | ] |
34 | } | 34 | } |
35 | }, | 35 | }, | ... | ... |
-
Please register or login to post a comment