blob: 49b75f0611f8d122aba2007de5638e7abe40edf8 [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 SHIMIZU08ec48f2015-07-27 11:27:26 -070063import org.onosproject.net.newresource.DefaultResource;
64import org.onosproject.net.newresource.DefaultResourceAllocation;
Brian O'Connorabafb502014-12-02 22:26:20 -080065import org.onosproject.net.provider.ProviderId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070066import org.onosproject.net.resource.link.BandwidthResource;
67import org.onosproject.net.resource.link.BandwidthResourceAllocation;
68import org.onosproject.net.resource.link.DefaultLinkResourceAllocations;
69import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
70import org.onosproject.net.resource.link.LambdaResource;
71import org.onosproject.net.resource.link.LambdaResourceAllocation;
72import org.onosproject.net.resource.link.LinkResourceRequest;
Brian O'Connorabafb502014-12-02 22:26:20 -080073import org.onosproject.net.resource.ResourceAllocation;
74import org.onosproject.net.intent.constraint.AnnotationConstraint;
75import org.onosproject.net.intent.constraint.BandwidthConstraint;
76import org.onosproject.net.intent.constraint.LambdaConstraint;
77import org.onosproject.net.intent.constraint.LatencyConstraint;
78import org.onosproject.net.intent.constraint.LinkTypeConstraint;
79import org.onosproject.net.intent.constraint.ObstacleConstraint;
80import org.onosproject.net.intent.constraint.WaypointConstraint;
alshabib7911a052014-10-16 17:49:37 -070081import org.onlab.packet.ChassisId;
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070082import org.onlab.packet.IpAddress;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080083import org.onlab.packet.Ip4Address;
84import org.onlab.packet.Ip6Address;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070085import org.onlab.packet.IpPrefix;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080086import org.onlab.packet.Ip4Prefix;
87import org.onlab.packet.Ip6Prefix;
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -070088import org.onlab.packet.MacAddress;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070089import org.onlab.util.KryoNamespace;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070090
Thomas Vachuskad16ce182014-10-29 17:25:29 -070091import java.nio.ByteBuffer;
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080092import java.util.Arrays;
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -080093import java.util.Collections;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080094import java.util.HashMap;
95import java.util.Map;
96import java.util.Set;
Sho SHIMIZU977cb602014-11-13 08:40:50 -080097import java.time.Duration;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070098
99import static java.util.Arrays.asList;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800100import static org.junit.Assert.*;
Brian O'Connorabafb502014-12-02 22:26:20 -0800101import static org.onosproject.net.DeviceId.deviceId;
102import static org.onosproject.net.PortNumber.portNumber;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700103
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700104public class KryoSerializerTest {
105
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700106 private static final ProviderId PID = new ProviderId("of", "foo");
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700107 private static final ProviderId PIDA = new ProviderId("of", "foo", true);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700108 private static final DeviceId DID1 = deviceId("of:foo");
109 private static final DeviceId DID2 = deviceId("of:bar");
110 private static final PortNumber P1 = portNumber(1);
111 private static final PortNumber P2 = portNumber(2);
112 private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1);
113 private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2);
114 private static final String MFR = "whitebox";
115 private static final String HW = "1.1.x";
116 private static final String SW1 = "3.8.1";
117 private static final String SW2 = "3.9.5";
118 private static final String SN = "43311-12345";
alshabib7911a052014-10-16 17:49:37 -0700119 private static final ChassisId CID = new ChassisId();
120 private static final Device DEV1 = new DefaultDevice(PID, DID1, Device.Type.SWITCH, MFR, HW,
121 SW1, SN, CID);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700122 private static final SparseAnnotations A1 = DefaultAnnotations.builder()
123 .set("A1", "a1")
124 .set("B1", "b1")
125 .build();
126 private static final SparseAnnotations A1_2 = DefaultAnnotations.builder()
127 .remove("A1")
128 .set("B3", "b3")
129 .build();
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700130 private static final OchSignal OCH_SIGNAL1 = (OchSignal) org.onosproject.net.Lambda.ochSignal(
131 GridType.DWDM, ChannelSpacing.CHL_100GHZ, -8, 4);
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700132 private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700133
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700134 private KryoSerializer serializer;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700135
136 @BeforeClass
137 public static void setUpBeforeClass() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700138 }
139
140 @Before
141 public void setUp() throws Exception {
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700142 serializer = new KryoSerializer() {
143
144 @Override
145 protected void setupKryoPool() {
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700146 serializerPool = KryoNamespace.newBuilder()
147 .register(KryoNamespaces.API)
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800148 .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID)
149 .build();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700150 }
151 };
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700152 }
153
154 @After
155 public void tearDown() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700156 }
157
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800158 private <T> void testSerializedEquals(T original) {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700159 ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700160 serializer.encode(original, buffer);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700161 buffer.flip();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700162 T copy = serializer.decode(buffer);
163
164 T copy2 = serializer.decode(serializer.encode(original));
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700165
166 new EqualsTester()
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700167 .addEqualityGroup(original, copy, copy2)
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700168 .testEquals();
169 }
170
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800171 private <T> void testSerializable(T original) {
172 byte[] bs = serializer.encode(original);
173 T copy = serializer.decode(bs);
174 assertNotNull(copy);
175 }
176
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700177
178 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700179 public void testConnectPoint() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800180 testSerializedEquals(new ConnectPoint(DID1, P1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700181 }
182
183 @Test
184 public void testDefaultLink() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800185 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT));
186 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT, A1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700187 }
188
189 @Test
190 public void testDefaultPort() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800191 testSerializedEquals(new DefaultPort(DEV1, P1, true));
192 testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700193 }
194
195 @Test
Marc De Leenheerbb382352015-04-23 18:20:34 -0700196 public void testOmsPort() {
197 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
198 Frequency.ofGHz(100)));
199 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
200 Frequency.ofGHz(100), A1_2));
201 }
202
203 @Test
204 public void testOchPort() {
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700205 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1));
206 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1, A1_2));
Marc De Leenheerbb382352015-04-23 18:20:34 -0700207 }
208
209 @Test
210 public void testOduCltPort() {
211 testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE));
212 testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE, A1_2));
213 }
214
215 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700216 public void testDeviceId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800217 testSerializedEquals(DID1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700218 }
219
220 @Test
221 public void testImmutableMap() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800222 testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1));
223 testSerializedEquals(ImmutableMap.of(DID1, DEV1));
224 testSerializedEquals(ImmutableMap.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700225 }
226
227 @Test
228 public void testImmutableSet() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800229 testSerializedEquals(ImmutableSet.of(DID1, DID2));
230 testSerializedEquals(ImmutableSet.of(DID1));
231 testSerializedEquals(ImmutableSet.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700232 }
233
234 @Test
235 public void testImmutableList() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800236 testSerializedEquals(ImmutableList.of(DID1, DID2));
237 testSerializedEquals(ImmutableList.of(DID1));
238 testSerializedEquals(ImmutableList.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700239 }
240
241 @Test
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800242 public void testFlowRuleBatchEntry() {
243 final FlowRule rule1 =
Ray Milkeyd13a37b2015-06-12 11:55:17 -0700244 DefaultFlowRule.builder()
245 .forDevice(DID1)
246 .withSelector(DefaultTrafficSelector.emptySelector())
247 .withTreatment(DefaultTrafficTreatment.emptyTreatment())
248 .withPriority(0)
249 .fromApp(new DefaultApplicationId(1, "1"))
250 .makeTemporary(1)
251 .build();
252
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800253 final FlowRuleBatchEntry entry1 =
254 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
255 final FlowRuleBatchEntry entry2 =
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800256 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800257
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800258 testSerializedEquals(entry1);
259 testSerializedEquals(entry2);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800260 }
261
262 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700263 public void testIpPrefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800264 testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700265 }
266
267 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800268 public void testIp4Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800269 testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800270 }
271
272 @Test
273 public void testIp6Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800274 testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800275 }
276
277 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700278 public void testIpAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800279 testSerializedEquals(IpAddress.valueOf("192.168.0.1"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700280 }
281
282 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800283 public void testIp4Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800284 testSerializedEquals(Ip4Address.valueOf("192.168.0.1"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800285 }
286
287 @Test
288 public void testIp6Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800289 testSerializedEquals(Ip6Address.valueOf("1111:2222::"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800290 }
291
292 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700293 public void testMacAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800294 testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700295 }
296
297 @Test
298 public void testLinkKey() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800299 testSerializedEquals(LinkKey.linkKey(CP1, CP2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700300 }
301
302 @Test
303 public void testNodeId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800304 testSerializedEquals(new NodeId("SomeNodeIdentifier"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700305 }
306
307 @Test
308 public void testPortNumber() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800309 testSerializedEquals(P1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700310 }
311
312 @Test
313 public void testProviderId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800314 testSerializedEquals(PID);
315 testSerializedEquals(PIDA);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700316 }
317
318 @Test
319 public void testMastershipTerm() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800320 testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2));
321 testSerializedEquals(MastershipTerm.of(null, 0));
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700322 }
323
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700324 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700325 public void testHostLocation() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800326 testSerializedEquals(new HostLocation(CP1, 1234L));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700327 }
328
329 @Test
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700330 public void testFlowId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800331 testSerializedEquals(FlowId.valueOf(0x12345678L));
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700332 }
333
334 @Test
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700335 public void testRoleInfo() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800336 testSerializedEquals(new RoleInfo(new NodeId("master"),
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700337 asList(new NodeId("stby1"), new NodeId("stby2"))));
338 }
339
340 @Test
Sho SHIMIZU91210a72015-04-29 12:54:28 -0700341 public void testIndexedLambda() {
342 testSerializedEquals(org.onosproject.net.Lambda.indexedLambda(10L));
343 }
344
345 @Test
346 public void testOchSignal() {
347 testSerializedEquals(org.onosproject.net.Lambda.ochSignal(
348 GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1
349 ));
350 }
351
352 @Test
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800353 public void testDefaultLinkResourceRequest() {
354 testSerializable(DefaultLinkResourceRequest.builder(IntentId.valueOf(2501), ImmutableList.of())
Sho SHIMIZU014c33a2015-04-30 11:40:37 -0700355 .addLambdaRequest()
356 .addBandwidthRequest(32.195)
357 .build()
358 );
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800359 }
360
361 @Test
362 public void testDefaultLinkResourceAllocations() {
363 LinkResourceRequest request = DefaultLinkResourceRequest
364 .builder(IntentId.valueOf(2501), ImmutableList.of())
365 .addLambdaRequest()
366 .addBandwidthRequest(32.195)
367 .build();
368 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
369 allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT),
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -0700370 ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))),
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -0700371 new LambdaResourceAllocation(LambdaResource.valueOf(1))));
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800372 testSerializable(new DefaultLinkResourceAllocations(request, allocations));
373 }
374
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700375 @Test
376 public void testDefaultResouce() {
377 testSerializedEquals(new DefaultResource<>(LinkKey.linkKey(CP1, CP2), VLAN1));
378 }
379
380 @Test
381 public void testDefaultResourceAllocation() {
382 testSerializedEquals(new DefaultResourceAllocation<>(
383 LinkKey.linkKey(CP1, CP2),
384 VLAN1,
385 IntentId.valueOf(30)));
386 }
Sho SHIMIZUdee78712015-04-30 09:33:52 -0700387
388 @Test
389 public void testFrequency() {
390 testSerializedEquals(Frequency.ofGHz(100));
391 }
392
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800393 @Test
Sho SHIMIZU81697792015-05-08 11:09:38 -0700394 public void testBandwidth() {
Sho SHIMIZU63feca72015-05-07 10:44:25 -0700395 testSerializedEquals(Bandwidth.mbps(1000.0));
Sho SHIMIZU81697792015-05-08 11:09:38 -0700396 }
397
398 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800399 public void testLambdaConstraint() {
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -0700400 testSerializable(new LambdaConstraint(LambdaResource.valueOf(1)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800401 }
402
403 @Test
404 public void testBandwidthConstraint() {
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -0700405 testSerializable(new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(1000.0))));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800406 }
407
408 @Test
409 public void testLinkTypeConstraint() {
410 testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT));
411 }
412
413 @Test
414 public void testLatencyConstraint() {
415 testSerializable(new LatencyConstraint(Duration.ofSeconds(10)));
416 }
417
418 @Test
419 public void testWaypointConstraint() {
420 testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2")));
421 }
422
423 @Test
424 public void testObstacleConstraint() {
425 testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2")));
426 }
427
428 @Test
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800429 public void testArraysAsList() {
430 testSerializedEquals(Arrays.asList(1, 2, 3));
431 }
432
433 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800434 public void testAnnotationConstraint() {
435 testSerializable(new AnnotationConstraint("distance", 100.0));
436 }
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800437
438 @Test
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800439 public void testDefaultGroupId() {
440 testSerializedEquals(new DefaultGroupId(99));
441 }
442
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -0800443 @Test
444 public void testEmptySet() {
445 testSerializedEquals(Collections.emptySet());
446 }
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800447
448 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700449 public void testAnnotations() {
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700450 // Annotations does not have equals defined, manually test equality
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700451 final byte[] a1Bytes = serializer.encode(A1);
452 SparseAnnotations copiedA1 = serializer.decode(a1Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700453 assertAnnotationsEquals(copiedA1, A1);
454
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700455 final byte[] a12Bytes = serializer.encode(A1_2);
456 SparseAnnotations copiedA12 = serializer.decode(a12Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700457 assertAnnotationsEquals(copiedA12, A1_2);
458 }
459
460 // code clone
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700461 protected static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700462 SparseAnnotations expected = DefaultAnnotations.builder().build();
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700463 for (SparseAnnotations a : annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700464 expected = DefaultAnnotations.union(expected, a);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700465 }
466 assertEquals(expected.keys(), actual.keys());
467 for (String key : expected.keys()) {
468 assertEquals(expected.value(key), actual.value(key));
469 }
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700470 }
471
472}