blob: 09611191c3ed91905c049e6360feb423cdfd9053 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.serializers;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070017
Thomas Vachuskad16ce182014-10-29 17:25:29 -070018import com.google.common.collect.ImmutableList;
19import com.google.common.collect.ImmutableMap;
20import com.google.common.collect.ImmutableSet;
21import com.google.common.testing.EqualsTester;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080022
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070023import org.junit.After;
24import org.junit.Before;
25import org.junit.BeforeClass;
26import org.junit.Test;
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -070027import org.onlab.packet.VlanId;
Sho SHIMIZU63feca72015-05-07 10:44:25 -070028import org.onlab.util.Bandwidth;
Marc De Leenheerbb382352015-04-23 18:20:34 -070029import org.onlab.util.Frequency;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.cluster.NodeId;
31import org.onosproject.cluster.RoleInfo;
Ray Milkeyd13a37b2015-06-12 11:55:17 -070032import org.onosproject.core.DefaultApplicationId;
Brian O'Connorabafb502014-12-02 22:26:20 -080033import org.onosproject.core.DefaultGroupId;
34import org.onosproject.mastership.MastershipTerm;
35import org.onosproject.net.Annotations;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070036import org.onosproject.net.ChannelSpacing;
Brian O'Connorabafb502014-12-02 22:26:20 -080037import org.onosproject.net.ConnectPoint;
38import org.onosproject.net.DefaultAnnotations;
39import org.onosproject.net.DefaultDevice;
40import org.onosproject.net.DefaultLink;
41import org.onosproject.net.DefaultPort;
42import org.onosproject.net.Device;
43import org.onosproject.net.DeviceId;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070044import org.onosproject.net.GridType;
Brian O'Connorabafb502014-12-02 22:26:20 -080045import org.onosproject.net.HostLocation;
46import org.onosproject.net.Link;
47import org.onosproject.net.Link.Type;
48import org.onosproject.net.LinkKey;
Marc De Leenheerbb382352015-04-23 18:20:34 -070049import org.onosproject.net.OchPort;
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070050import org.onosproject.net.OchSignal;
Marc De Leenheerbb382352015-04-23 18:20:34 -070051import org.onosproject.net.OduCltPort;
52import org.onosproject.net.OmsPort;
Brian O'Connorabafb502014-12-02 22:26:20 -080053import org.onosproject.net.PortNumber;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070054import org.onosproject.net.OduSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080055import org.onosproject.net.SparseAnnotations;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080056import org.onosproject.net.flow.DefaultFlowRule;
57import org.onosproject.net.flow.DefaultTrafficSelector;
58import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080059import org.onosproject.net.flow.FlowId;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080060import org.onosproject.net.flow.FlowRule;
61import org.onosproject.net.flow.FlowRuleBatchEntry;
Brian O'Connorabafb502014-12-02 22:26:20 -080062import org.onosproject.net.intent.IntentId;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070063import org.onosproject.net.newresource.ResourcePath;
Brian O'Connorabafb502014-12-02 22:26:20 -080064import org.onosproject.net.provider.ProviderId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070065import org.onosproject.net.resource.link.BandwidthResource;
66import org.onosproject.net.resource.link.BandwidthResourceAllocation;
67import org.onosproject.net.resource.link.DefaultLinkResourceAllocations;
68import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
69import org.onosproject.net.resource.link.LambdaResource;
70import org.onosproject.net.resource.link.LambdaResourceAllocation;
71import org.onosproject.net.resource.link.LinkResourceRequest;
Brian O'Connorabafb502014-12-02 22:26:20 -080072import org.onosproject.net.resource.ResourceAllocation;
73import org.onosproject.net.intent.constraint.AnnotationConstraint;
74import org.onosproject.net.intent.constraint.BandwidthConstraint;
75import org.onosproject.net.intent.constraint.LambdaConstraint;
76import org.onosproject.net.intent.constraint.LatencyConstraint;
77import org.onosproject.net.intent.constraint.LinkTypeConstraint;
78import org.onosproject.net.intent.constraint.ObstacleConstraint;
79import org.onosproject.net.intent.constraint.WaypointConstraint;
alshabib7911a052014-10-16 17:49:37 -070080import org.onlab.packet.ChassisId;
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070081import org.onlab.packet.IpAddress;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080082import org.onlab.packet.Ip4Address;
83import org.onlab.packet.Ip6Address;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070084import org.onlab.packet.IpPrefix;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080085import org.onlab.packet.Ip4Prefix;
86import org.onlab.packet.Ip6Prefix;
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -070087import org.onlab.packet.MacAddress;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070088import org.onlab.util.KryoNamespace;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070089
Thomas Vachuskad16ce182014-10-29 17:25:29 -070090import java.nio.ByteBuffer;
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080091import java.util.Arrays;
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -080092import java.util.Collections;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080093import java.util.HashMap;
94import java.util.Map;
95import java.util.Set;
Sho SHIMIZU977cb602014-11-13 08:40:50 -080096import java.time.Duration;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070097
98import static java.util.Arrays.asList;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080099import static org.junit.Assert.*;
Brian O'Connorabafb502014-12-02 22:26:20 -0800100import static org.onosproject.net.DeviceId.deviceId;
101import static org.onosproject.net.PortNumber.portNumber;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700102
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700103public class KryoSerializerTest {
104
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700105 private static final ProviderId PID = new ProviderId("of", "foo");
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700106 private static final ProviderId PIDA = new ProviderId("of", "foo", true);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700107 private static final DeviceId DID1 = deviceId("of:foo");
108 private static final DeviceId DID2 = deviceId("of:bar");
109 private static final PortNumber P1 = portNumber(1);
110 private static final PortNumber P2 = portNumber(2);
111 private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1);
112 private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2);
113 private static final String MFR = "whitebox";
114 private static final String HW = "1.1.x";
115 private static final String SW1 = "3.8.1";
116 private static final String SW2 = "3.9.5";
117 private static final String SN = "43311-12345";
alshabib7911a052014-10-16 17:49:37 -0700118 private static final ChassisId CID = new ChassisId();
119 private static final Device DEV1 = new DefaultDevice(PID, DID1, Device.Type.SWITCH, MFR, HW,
120 SW1, SN, CID);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700121 private static final SparseAnnotations A1 = DefaultAnnotations.builder()
122 .set("A1", "a1")
123 .set("B1", "b1")
124 .build();
125 private static final SparseAnnotations A1_2 = DefaultAnnotations.builder()
126 .remove("A1")
127 .set("B3", "b3")
128 .build();
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700129 private static final OchSignal OCH_SIGNAL1 = (OchSignal) org.onosproject.net.Lambda.ochSignal(
130 GridType.DWDM, ChannelSpacing.CHL_100GHZ, -8, 4);
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700131 private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700132
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700133 private KryoSerializer serializer;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700134
135 @BeforeClass
136 public static void setUpBeforeClass() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700137 }
138
139 @Before
140 public void setUp() throws Exception {
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700141 serializer = new KryoSerializer() {
142
143 @Override
144 protected void setupKryoPool() {
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700145 serializerPool = KryoNamespace.newBuilder()
146 .register(KryoNamespaces.API)
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800147 .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID)
148 .build();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700149 }
150 };
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700151 }
152
153 @After
154 public void tearDown() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700155 }
156
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800157 private <T> void testSerializedEquals(T original) {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700158 ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700159 serializer.encode(original, buffer);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700160 buffer.flip();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700161 T copy = serializer.decode(buffer);
162
163 T copy2 = serializer.decode(serializer.encode(original));
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700164
165 new EqualsTester()
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700166 .addEqualityGroup(original, copy, copy2)
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700167 .testEquals();
168 }
169
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800170 private <T> void testSerializable(T original) {
171 byte[] bs = serializer.encode(original);
172 T copy = serializer.decode(bs);
173 assertNotNull(copy);
174 }
175
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700176
177 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700178 public void testConnectPoint() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800179 testSerializedEquals(new ConnectPoint(DID1, P1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700180 }
181
182 @Test
183 public void testDefaultLink() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800184 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT));
185 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT, A1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700186 }
187
188 @Test
189 public void testDefaultPort() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800190 testSerializedEquals(new DefaultPort(DEV1, P1, true));
191 testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700192 }
193
194 @Test
Marc De Leenheerbb382352015-04-23 18:20:34 -0700195 public void testOmsPort() {
196 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
197 Frequency.ofGHz(100)));
198 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
199 Frequency.ofGHz(100), A1_2));
200 }
201
202 @Test
203 public void testOchPort() {
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700204 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1));
205 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1, A1_2));
Marc De Leenheerbb382352015-04-23 18:20:34 -0700206 }
207
208 @Test
209 public void testOduCltPort() {
210 testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE));
211 testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE, A1_2));
212 }
213
214 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700215 public void testDeviceId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800216 testSerializedEquals(DID1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700217 }
218
219 @Test
220 public void testImmutableMap() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800221 testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1));
222 testSerializedEquals(ImmutableMap.of(DID1, DEV1));
223 testSerializedEquals(ImmutableMap.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700224 }
225
226 @Test
227 public void testImmutableSet() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800228 testSerializedEquals(ImmutableSet.of(DID1, DID2));
229 testSerializedEquals(ImmutableSet.of(DID1));
230 testSerializedEquals(ImmutableSet.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700231 }
232
233 @Test
234 public void testImmutableList() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800235 testSerializedEquals(ImmutableList.of(DID1, DID2));
236 testSerializedEquals(ImmutableList.of(DID1));
237 testSerializedEquals(ImmutableList.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700238 }
239
240 @Test
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800241 public void testFlowRuleBatchEntry() {
242 final FlowRule rule1 =
Ray Milkeyd13a37b2015-06-12 11:55:17 -0700243 DefaultFlowRule.builder()
244 .forDevice(DID1)
245 .withSelector(DefaultTrafficSelector.emptySelector())
246 .withTreatment(DefaultTrafficTreatment.emptyTreatment())
247 .withPriority(0)
248 .fromApp(new DefaultApplicationId(1, "1"))
249 .makeTemporary(1)
250 .build();
251
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800252 final FlowRuleBatchEntry entry1 =
253 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
254 final FlowRuleBatchEntry entry2 =
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800255 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800256
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800257 testSerializedEquals(entry1);
258 testSerializedEquals(entry2);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800259 }
260
261 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700262 public void testIpPrefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800263 testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700264 }
265
266 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800267 public void testIp4Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800268 testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800269 }
270
271 @Test
272 public void testIp6Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800273 testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800274 }
275
276 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700277 public void testIpAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800278 testSerializedEquals(IpAddress.valueOf("192.168.0.1"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700279 }
280
281 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800282 public void testIp4Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800283 testSerializedEquals(Ip4Address.valueOf("192.168.0.1"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800284 }
285
286 @Test
287 public void testIp6Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800288 testSerializedEquals(Ip6Address.valueOf("1111:2222::"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800289 }
290
291 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700292 public void testMacAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800293 testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700294 }
295
296 @Test
297 public void testLinkKey() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800298 testSerializedEquals(LinkKey.linkKey(CP1, CP2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700299 }
300
301 @Test
302 public void testNodeId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800303 testSerializedEquals(new NodeId("SomeNodeIdentifier"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700304 }
305
306 @Test
307 public void testPortNumber() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800308 testSerializedEquals(P1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700309 }
310
311 @Test
312 public void testProviderId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800313 testSerializedEquals(PID);
314 testSerializedEquals(PIDA);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700315 }
316
317 @Test
318 public void testMastershipTerm() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800319 testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2));
320 testSerializedEquals(MastershipTerm.of(null, 0));
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700321 }
322
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700323 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700324 public void testHostLocation() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800325 testSerializedEquals(new HostLocation(CP1, 1234L));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700326 }
327
328 @Test
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700329 public void testFlowId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800330 testSerializedEquals(FlowId.valueOf(0x12345678L));
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700331 }
332
333 @Test
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700334 public void testRoleInfo() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800335 testSerializedEquals(new RoleInfo(new NodeId("master"),
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700336 asList(new NodeId("stby1"), new NodeId("stby2"))));
337 }
338
339 @Test
Sho SHIMIZU91210a72015-04-29 12:54:28 -0700340 public void testIndexedLambda() {
341 testSerializedEquals(org.onosproject.net.Lambda.indexedLambda(10L));
342 }
343
344 @Test
345 public void testOchSignal() {
346 testSerializedEquals(org.onosproject.net.Lambda.ochSignal(
347 GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1
348 ));
349 }
350
351 @Test
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800352 public void testDefaultLinkResourceRequest() {
353 testSerializable(DefaultLinkResourceRequest.builder(IntentId.valueOf(2501), ImmutableList.of())
Sho SHIMIZU014c33a2015-04-30 11:40:37 -0700354 .addLambdaRequest()
355 .addBandwidthRequest(32.195)
356 .build()
357 );
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800358 }
359
360 @Test
361 public void testDefaultLinkResourceAllocations() {
362 LinkResourceRequest request = DefaultLinkResourceRequest
363 .builder(IntentId.valueOf(2501), ImmutableList.of())
364 .addLambdaRequest()
365 .addBandwidthRequest(32.195)
366 .build();
367 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
368 allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT),
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -0700369 ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))),
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -0700370 new LambdaResourceAllocation(LambdaResource.valueOf(1))));
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800371 testSerializable(new DefaultLinkResourceAllocations(request, allocations));
372 }
373
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700374 @Test
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700375 public void testResourcePath() {
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -0800376 testSerializedEquals(ResourcePath.discrete(LinkKey.linkKey(CP1, CP2), VLAN1));
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700377 }
378
379 @Test
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700380 public void testResourceAllocation() {
381 testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation(
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -0800382 ResourcePath.discrete(LinkKey.linkKey(CP1, CP2), VLAN1),
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700383 IntentId.valueOf(30)));
384 }
Sho SHIMIZUdee78712015-04-30 09:33:52 -0700385
386 @Test
387 public void testFrequency() {
388 testSerializedEquals(Frequency.ofGHz(100));
389 }
390
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800391 @Test
Sho SHIMIZU81697792015-05-08 11:09:38 -0700392 public void testBandwidth() {
Sho SHIMIZU63feca72015-05-07 10:44:25 -0700393 testSerializedEquals(Bandwidth.mbps(1000.0));
Sho SHIMIZU81697792015-05-08 11:09:38 -0700394 }
395
396 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800397 public void testLambdaConstraint() {
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -0700398 testSerializable(new LambdaConstraint(LambdaResource.valueOf(1)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800399 }
400
401 @Test
402 public void testBandwidthConstraint() {
Sho SHIMIZUa88db492015-11-23 13:21:04 -0800403 testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800404 }
405
406 @Test
407 public void testLinkTypeConstraint() {
408 testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT));
409 }
410
411 @Test
412 public void testLatencyConstraint() {
413 testSerializable(new LatencyConstraint(Duration.ofSeconds(10)));
414 }
415
416 @Test
417 public void testWaypointConstraint() {
418 testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2")));
419 }
420
421 @Test
422 public void testObstacleConstraint() {
423 testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2")));
424 }
425
426 @Test
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800427 public void testArraysAsList() {
428 testSerializedEquals(Arrays.asList(1, 2, 3));
429 }
430
431 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800432 public void testAnnotationConstraint() {
433 testSerializable(new AnnotationConstraint("distance", 100.0));
434 }
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800435
436 @Test
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800437 public void testDefaultGroupId() {
438 testSerializedEquals(new DefaultGroupId(99));
439 }
440
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -0800441 @Test
442 public void testEmptySet() {
443 testSerializedEquals(Collections.emptySet());
444 }
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800445
446 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700447 public void testAnnotations() {
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700448 // Annotations does not have equals defined, manually test equality
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700449 final byte[] a1Bytes = serializer.encode(A1);
450 SparseAnnotations copiedA1 = serializer.decode(a1Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700451 assertAnnotationsEquals(copiedA1, A1);
452
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700453 final byte[] a12Bytes = serializer.encode(A1_2);
454 SparseAnnotations copiedA12 = serializer.decode(a12Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700455 assertAnnotationsEquals(copiedA12, A1_2);
456 }
457
458 // code clone
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700459 protected static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700460 SparseAnnotations expected = DefaultAnnotations.builder().build();
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700461 for (SparseAnnotations a : annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700462 expected = DefaultAnnotations.union(expected, a);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700463 }
464 assertEquals(expected.keys(), actual.keys());
465 for (String key : expected.keys()) {
466 assertEquals(expected.value(key), actual.value(key));
467 }
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700468 }
469
470}