blob: 766e0ced4f6f0041842a6f326444f37a482edb26 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -08002 * Copyright 2014-2016 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;
Toru Furusawa72ee30c2016-01-08 13:29:04 -080037import org.onosproject.net.CltSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080038import org.onosproject.net.ConnectPoint;
39import org.onosproject.net.DefaultAnnotations;
40import org.onosproject.net.DefaultDevice;
41import org.onosproject.net.DefaultLink;
42import org.onosproject.net.DefaultPort;
43import org.onosproject.net.Device;
44import org.onosproject.net.DeviceId;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070045import org.onosproject.net.GridType;
Brian O'Connorabafb502014-12-02 22:26:20 -080046import org.onosproject.net.HostLocation;
47import org.onosproject.net.Link;
Brian O'Connorabafb502014-12-02 22:26:20 -080048import 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;
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +020053import org.onosproject.net.OtuPort;
54import org.onosproject.net.OtuSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080055import org.onosproject.net.PortNumber;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070056import org.onosproject.net.OduSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080057import org.onosproject.net.SparseAnnotations;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080058import org.onosproject.net.flow.DefaultFlowRule;
59import org.onosproject.net.flow.DefaultTrafficSelector;
60import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080061import org.onosproject.net.flow.FlowId;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080062import org.onosproject.net.flow.FlowRule;
63import org.onosproject.net.flow.FlowRuleBatchEntry;
Brian O'Connorabafb502014-12-02 22:26:20 -080064import org.onosproject.net.intent.IntentId;
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080065import org.onosproject.net.resource.ResourceAllocation;
66import org.onosproject.net.resource.Resources;
Brian O'Connorabafb502014-12-02 22:26:20 -080067import org.onosproject.net.provider.ProviderId;
Brian O'Connorabafb502014-12-02 22:26:20 -080068import org.onosproject.net.intent.constraint.AnnotationConstraint;
69import org.onosproject.net.intent.constraint.BandwidthConstraint;
Brian O'Connorabafb502014-12-02 22:26:20 -080070import org.onosproject.net.intent.constraint.LatencyConstraint;
71import org.onosproject.net.intent.constraint.LinkTypeConstraint;
72import org.onosproject.net.intent.constraint.ObstacleConstraint;
73import org.onosproject.net.intent.constraint.WaypointConstraint;
alshabib7911a052014-10-16 17:49:37 -070074import org.onlab.packet.ChassisId;
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070075import org.onlab.packet.IpAddress;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080076import org.onlab.packet.Ip4Address;
77import org.onlab.packet.Ip6Address;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070078import org.onlab.packet.IpPrefix;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080079import org.onlab.packet.Ip4Prefix;
80import org.onlab.packet.Ip6Prefix;
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -070081import org.onlab.packet.MacAddress;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070082import org.onlab.util.KryoNamespace;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070083
Thomas Vachuskad16ce182014-10-29 17:25:29 -070084import java.nio.ByteBuffer;
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080085import java.util.Arrays;
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -080086import java.util.Collections;
Sho SHIMIZU977cb602014-11-13 08:40:50 -080087import java.time.Duration;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070088
89import static java.util.Arrays.asList;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080090import static org.junit.Assert.*;
Brian O'Connorabafb502014-12-02 22:26:20 -080091import static org.onosproject.net.DeviceId.deviceId;
92import static org.onosproject.net.PortNumber.portNumber;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070093
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -070094public class KryoSerializerTest {
95
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070096 private static final ProviderId PID = new ProviderId("of", "foo");
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070097 private static final ProviderId PIDA = new ProviderId("of", "foo", true);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070098 private static final DeviceId DID1 = deviceId("of:foo");
99 private static final DeviceId DID2 = deviceId("of:bar");
100 private static final PortNumber P1 = portNumber(1);
101 private static final PortNumber P2 = portNumber(2);
102 private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1);
103 private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2);
104 private static final String MFR = "whitebox";
105 private static final String HW = "1.1.x";
106 private static final String SW1 = "3.8.1";
107 private static final String SW2 = "3.9.5";
108 private static final String SN = "43311-12345";
alshabib7911a052014-10-16 17:49:37 -0700109 private static final ChassisId CID = new ChassisId();
110 private static final Device DEV1 = new DefaultDevice(PID, DID1, Device.Type.SWITCH, MFR, HW,
111 SW1, SN, CID);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700112 private static final SparseAnnotations A1 = DefaultAnnotations.builder()
113 .set("A1", "a1")
114 .set("B1", "b1")
115 .build();
116 private static final SparseAnnotations A1_2 = DefaultAnnotations.builder()
117 .remove("A1")
118 .set("B3", "b3")
119 .build();
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700120 private static final OchSignal OCH_SIGNAL1 = (OchSignal) org.onosproject.net.Lambda.ochSignal(
121 GridType.DWDM, ChannelSpacing.CHL_100GHZ, -8, 4);
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700122 private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700123
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700124 private KryoSerializer serializer;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700125
126 @BeforeClass
127 public static void setUpBeforeClass() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700128 }
129
130 @Before
131 public void setUp() throws Exception {
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700132 serializer = new KryoSerializer() {
133
134 @Override
135 protected void setupKryoPool() {
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700136 serializerPool = KryoNamespace.newBuilder()
137 .register(KryoNamespaces.API)
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800138 .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID)
139 .build();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700140 }
141 };
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700142 }
143
144 @After
145 public void tearDown() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700146 }
147
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800148 private <T> void testSerializedEquals(T original) {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700149 ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700150 serializer.encode(original, buffer);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700151 buffer.flip();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700152 T copy = serializer.decode(buffer);
153
154 T copy2 = serializer.decode(serializer.encode(original));
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700155
156 new EqualsTester()
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700157 .addEqualityGroup(original, copy, copy2)
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700158 .testEquals();
159 }
160
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800161 private <T> void testSerializable(T original) {
162 byte[] bs = serializer.encode(original);
163 T copy = serializer.decode(bs);
164 assertNotNull(copy);
165 }
166
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700167
168 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700169 public void testConnectPoint() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800170 testSerializedEquals(new ConnectPoint(DID1, P1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700171 }
172
173 @Test
174 public void testDefaultLink() {
Ray Milkey2693bda2016-01-22 16:08:14 -0800175 testSerializedEquals(DefaultLink.builder()
176 .providerId(PID)
177 .src(CP1)
178 .dst(CP2)
179 .type(Link.Type.DIRECT)
180 .build());
181 testSerializedEquals(DefaultLink.builder()
182 .providerId(PID)
183 .src(CP1)
184 .dst(CP2)
185 .type(Link.Type.DIRECT)
186 .annotations(A1)
187 .build());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700188 }
189
190 @Test
191 public void testDefaultPort() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800192 testSerializedEquals(new DefaultPort(DEV1, P1, true));
193 testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700194 }
195
196 @Test
Marc De Leenheerbb382352015-04-23 18:20:34 -0700197 public void testOmsPort() {
198 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
199 Frequency.ofGHz(100)));
200 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
201 Frequency.ofGHz(100), A1_2));
202 }
203
204 @Test
205 public void testOchPort() {
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700206 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1));
207 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1, A1_2));
Marc De Leenheerbb382352015-04-23 18:20:34 -0700208 }
209
210 @Test
211 public void testOduCltPort() {
Toru Furusawa72ee30c2016-01-08 13:29:04 -0800212 testSerializedEquals(new OduCltPort(DEV1, P1, true, CltSignalType.CLT_10GBE));
213 testSerializedEquals(new OduCltPort(DEV1, P1, true, CltSignalType.CLT_10GBE, A1_2));
Marc De Leenheerbb382352015-04-23 18:20:34 -0700214 }
215
216 @Test
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +0200217 public void testOtuPort() {
218 testSerializedEquals(new OtuPort(DEV1, P1, true, OtuSignalType.OTU2));
219 testSerializedEquals(new OtuPort(DEV1, P1, true, OtuSignalType.OTU2, A1_2));
220 }
221 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700222 public void testDeviceId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800223 testSerializedEquals(DID1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700224 }
225
226 @Test
227 public void testImmutableMap() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800228 testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1));
229 testSerializedEquals(ImmutableMap.of(DID1, DEV1));
230 testSerializedEquals(ImmutableMap.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700231 }
232
233 @Test
234 public void testImmutableSet() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800235 testSerializedEquals(ImmutableSet.of(DID1, DID2));
236 testSerializedEquals(ImmutableSet.of(DID1));
237 testSerializedEquals(ImmutableSet.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700238 }
239
240 @Test
241 public void testImmutableList() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800242 testSerializedEquals(ImmutableList.of(DID1, DID2));
243 testSerializedEquals(ImmutableList.of(DID1));
244 testSerializedEquals(ImmutableList.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700245 }
246
247 @Test
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800248 public void testFlowRuleBatchEntry() {
249 final FlowRule rule1 =
Ray Milkeyd13a37b2015-06-12 11:55:17 -0700250 DefaultFlowRule.builder()
251 .forDevice(DID1)
252 .withSelector(DefaultTrafficSelector.emptySelector())
253 .withTreatment(DefaultTrafficTreatment.emptyTreatment())
254 .withPriority(0)
255 .fromApp(new DefaultApplicationId(1, "1"))
256 .makeTemporary(1)
257 .build();
258
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800259 final FlowRuleBatchEntry entry1 =
260 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
261 final FlowRuleBatchEntry entry2 =
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800262 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800263
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800264 testSerializedEquals(entry1);
265 testSerializedEquals(entry2);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800266 }
267
268 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700269 public void testIpPrefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800270 testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700271 }
272
273 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800274 public void testIp4Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800275 testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800276 }
277
278 @Test
279 public void testIp6Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800280 testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800281 }
282
283 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700284 public void testIpAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800285 testSerializedEquals(IpAddress.valueOf("192.168.0.1"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700286 }
287
288 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800289 public void testIp4Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800290 testSerializedEquals(Ip4Address.valueOf("192.168.0.1"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800291 }
292
293 @Test
294 public void testIp6Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800295 testSerializedEquals(Ip6Address.valueOf("1111:2222::"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800296 }
297
298 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700299 public void testMacAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800300 testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700301 }
302
303 @Test
304 public void testLinkKey() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800305 testSerializedEquals(LinkKey.linkKey(CP1, CP2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700306 }
307
308 @Test
309 public void testNodeId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800310 testSerializedEquals(new NodeId("SomeNodeIdentifier"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700311 }
312
313 @Test
314 public void testPortNumber() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800315 testSerializedEquals(P1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700316 }
317
318 @Test
319 public void testProviderId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800320 testSerializedEquals(PID);
321 testSerializedEquals(PIDA);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700322 }
323
324 @Test
325 public void testMastershipTerm() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800326 testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2));
327 testSerializedEquals(MastershipTerm.of(null, 0));
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700328 }
329
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700330 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700331 public void testHostLocation() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800332 testSerializedEquals(new HostLocation(CP1, 1234L));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700333 }
334
335 @Test
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700336 public void testFlowId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800337 testSerializedEquals(FlowId.valueOf(0x12345678L));
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700338 }
339
340 @Test
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700341 public void testRoleInfo() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800342 testSerializedEquals(new RoleInfo(new NodeId("master"),
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700343 asList(new NodeId("stby1"), new NodeId("stby2"))));
344 }
345
346 @Test
Sho SHIMIZU91210a72015-04-29 12:54:28 -0700347 public void testIndexedLambda() {
348 testSerializedEquals(org.onosproject.net.Lambda.indexedLambda(10L));
349 }
350
351 @Test
352 public void testOchSignal() {
353 testSerializedEquals(org.onosproject.net.Lambda.ochSignal(
354 GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1
355 ));
356 }
357
358 @Test
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800359 public void testResource() {
Sho SHIMIZU460b9722016-01-28 10:48:26 -0800360 testSerializedEquals(Resources.discrete(DID1, P1, VLAN1).resource());
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700361 }
362
363 @Test
Sho SHIMIZU8d5ff162016-01-22 12:56:31 -0800364 public void testResourceId() {
Sho SHIMIZU460b9722016-01-28 10:48:26 -0800365 testSerializedEquals(Resources.discrete(DID1, P1).id());
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800366 }
367
368 @Test
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700369 public void testResourceAllocation() {
Sho SHIMIZUe18cb122016-02-22 21:04:56 -0800370 testSerializedEquals(new ResourceAllocation(
Sho SHIMIZU460b9722016-01-28 10:48:26 -0800371 Resources.discrete(DID1, P1, VLAN1).resource(),
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700372 IntentId.valueOf(30)));
373 }
Sho SHIMIZUdee78712015-04-30 09:33:52 -0700374
375 @Test
376 public void testFrequency() {
377 testSerializedEquals(Frequency.ofGHz(100));
378 }
379
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800380 @Test
Sho SHIMIZU81697792015-05-08 11:09:38 -0700381 public void testBandwidth() {
Sho SHIMIZU31f37ed2016-01-08 18:45:54 -0800382 testSerializedEquals(Bandwidth.mbps(1000));
Sho SHIMIZU63feca72015-05-07 10:44:25 -0700383 testSerializedEquals(Bandwidth.mbps(1000.0));
Sho SHIMIZU81697792015-05-08 11:09:38 -0700384 }
385
386 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800387 public void testBandwidthConstraint() {
Sho SHIMIZUa88db492015-11-23 13:21:04 -0800388 testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800389 }
390
391 @Test
392 public void testLinkTypeConstraint() {
393 testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT));
394 }
395
396 @Test
397 public void testLatencyConstraint() {
398 testSerializable(new LatencyConstraint(Duration.ofSeconds(10)));
399 }
400
401 @Test
402 public void testWaypointConstraint() {
403 testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2")));
404 }
405
406 @Test
407 public void testObstacleConstraint() {
408 testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2")));
409 }
410
411 @Test
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800412 public void testArraysAsList() {
413 testSerializedEquals(Arrays.asList(1, 2, 3));
414 }
415
416 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800417 public void testAnnotationConstraint() {
418 testSerializable(new AnnotationConstraint("distance", 100.0));
419 }
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800420
421 @Test
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800422 public void testDefaultGroupId() {
423 testSerializedEquals(new DefaultGroupId(99));
424 }
425
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -0800426 @Test
427 public void testEmptySet() {
428 testSerializedEquals(Collections.emptySet());
429 }
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800430
431 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700432 public void testAnnotations() {
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700433 // Annotations does not have equals defined, manually test equality
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700434 final byte[] a1Bytes = serializer.encode(A1);
435 SparseAnnotations copiedA1 = serializer.decode(a1Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700436 assertAnnotationsEquals(copiedA1, A1);
437
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700438 final byte[] a12Bytes = serializer.encode(A1_2);
439 SparseAnnotations copiedA12 = serializer.decode(a12Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700440 assertAnnotationsEquals(copiedA12, A1_2);
441 }
442
443 // code clone
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700444 protected static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700445 SparseAnnotations expected = DefaultAnnotations.builder().build();
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700446 for (SparseAnnotations a : annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700447 expected = DefaultAnnotations.union(expected, a);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700448 }
449 assertEquals(expected.keys(), actual.keys());
450 for (String key : expected.keys()) {
451 assertEquals(expected.value(key), actual.value(key));
452 }
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700453 }
454
455}