blob: a986278c4b363ad700c865a0e6fd2670f8d97fc0 [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;
Sho SHIMIZU03d42532015-11-23 17:16:30 -080047import org.onosproject.net.IndexedLambda;
Brian O'Connorabafb502014-12-02 22:26:20 -080048import org.onosproject.net.Link;
49import org.onosproject.net.Link.Type;
50import org.onosproject.net.LinkKey;
Marc De Leenheerbb382352015-04-23 18:20:34 -070051import org.onosproject.net.OchPort;
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070052import org.onosproject.net.OchSignal;
Marc De Leenheerbb382352015-04-23 18:20:34 -070053import org.onosproject.net.OduCltPort;
54import org.onosproject.net.OmsPort;
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 SHIMIZU8fa670a2016-01-14 11:17:18 -080065import org.onosproject.net.newresource.Resource;
Brian O'Connorabafb502014-12-02 22:26:20 -080066import org.onosproject.net.provider.ProviderId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070067import org.onosproject.net.resource.link.BandwidthResource;
68import org.onosproject.net.resource.link.BandwidthResourceAllocation;
69import org.onosproject.net.resource.link.DefaultLinkResourceAllocations;
70import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
71import org.onosproject.net.resource.link.LambdaResource;
72import org.onosproject.net.resource.link.LambdaResourceAllocation;
73import org.onosproject.net.resource.link.LinkResourceRequest;
Brian O'Connorabafb502014-12-02 22:26:20 -080074import org.onosproject.net.resource.ResourceAllocation;
75import org.onosproject.net.intent.constraint.AnnotationConstraint;
76import org.onosproject.net.intent.constraint.BandwidthConstraint;
77import org.onosproject.net.intent.constraint.LambdaConstraint;
78import org.onosproject.net.intent.constraint.LatencyConstraint;
79import org.onosproject.net.intent.constraint.LinkTypeConstraint;
80import org.onosproject.net.intent.constraint.ObstacleConstraint;
81import org.onosproject.net.intent.constraint.WaypointConstraint;
alshabib7911a052014-10-16 17:49:37 -070082import org.onlab.packet.ChassisId;
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070083import org.onlab.packet.IpAddress;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080084import org.onlab.packet.Ip4Address;
85import org.onlab.packet.Ip6Address;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070086import org.onlab.packet.IpPrefix;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080087import org.onlab.packet.Ip4Prefix;
88import org.onlab.packet.Ip6Prefix;
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -070089import org.onlab.packet.MacAddress;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070090import org.onlab.util.KryoNamespace;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070091
Thomas Vachuskad16ce182014-10-29 17:25:29 -070092import java.nio.ByteBuffer;
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080093import java.util.Arrays;
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -080094import java.util.Collections;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080095import java.util.HashMap;
96import java.util.Map;
97import java.util.Set;
Sho SHIMIZU977cb602014-11-13 08:40:50 -080098import java.time.Duration;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070099
100import static java.util.Arrays.asList;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800101import static org.junit.Assert.*;
Brian O'Connorabafb502014-12-02 22:26:20 -0800102import static org.onosproject.net.DeviceId.deviceId;
103import static org.onosproject.net.PortNumber.portNumber;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700104
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700105public class KryoSerializerTest {
106
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700107 private static final ProviderId PID = new ProviderId("of", "foo");
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700108 private static final ProviderId PIDA = new ProviderId("of", "foo", true);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700109 private static final DeviceId DID1 = deviceId("of:foo");
110 private static final DeviceId DID2 = deviceId("of:bar");
111 private static final PortNumber P1 = portNumber(1);
112 private static final PortNumber P2 = portNumber(2);
113 private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1);
114 private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2);
115 private static final String MFR = "whitebox";
116 private static final String HW = "1.1.x";
117 private static final String SW1 = "3.8.1";
118 private static final String SW2 = "3.9.5";
119 private static final String SN = "43311-12345";
alshabib7911a052014-10-16 17:49:37 -0700120 private static final ChassisId CID = new ChassisId();
121 private static final Device DEV1 = new DefaultDevice(PID, DID1, Device.Type.SWITCH, MFR, HW,
122 SW1, SN, CID);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700123 private static final SparseAnnotations A1 = DefaultAnnotations.builder()
124 .set("A1", "a1")
125 .set("B1", "b1")
126 .build();
127 private static final SparseAnnotations A1_2 = DefaultAnnotations.builder()
128 .remove("A1")
129 .set("B3", "b3")
130 .build();
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700131 private static final OchSignal OCH_SIGNAL1 = (OchSignal) org.onosproject.net.Lambda.ochSignal(
132 GridType.DWDM, ChannelSpacing.CHL_100GHZ, -8, 4);
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700133 private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700134
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700135 private KryoSerializer serializer;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700136
137 @BeforeClass
138 public static void setUpBeforeClass() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700139 }
140
141 @Before
142 public void setUp() throws Exception {
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700143 serializer = new KryoSerializer() {
144
145 @Override
146 protected void setupKryoPool() {
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700147 serializerPool = KryoNamespace.newBuilder()
148 .register(KryoNamespaces.API)
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800149 .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID)
150 .build();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700151 }
152 };
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700153 }
154
155 @After
156 public void tearDown() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700157 }
158
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800159 private <T> void testSerializedEquals(T original) {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700160 ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700161 serializer.encode(original, buffer);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700162 buffer.flip();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700163 T copy = serializer.decode(buffer);
164
165 T copy2 = serializer.decode(serializer.encode(original));
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700166
167 new EqualsTester()
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700168 .addEqualityGroup(original, copy, copy2)
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700169 .testEquals();
170 }
171
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800172 private <T> void testSerializable(T original) {
173 byte[] bs = serializer.encode(original);
174 T copy = serializer.decode(bs);
175 assertNotNull(copy);
176 }
177
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700178
179 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700180 public void testConnectPoint() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800181 testSerializedEquals(new ConnectPoint(DID1, P1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700182 }
183
184 @Test
185 public void testDefaultLink() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800186 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT));
187 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT, A1));
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
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700217 public void testDeviceId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800218 testSerializedEquals(DID1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700219 }
220
221 @Test
222 public void testImmutableMap() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800223 testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1));
224 testSerializedEquals(ImmutableMap.of(DID1, DEV1));
225 testSerializedEquals(ImmutableMap.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700226 }
227
228 @Test
229 public void testImmutableSet() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800230 testSerializedEquals(ImmutableSet.of(DID1, DID2));
231 testSerializedEquals(ImmutableSet.of(DID1));
232 testSerializedEquals(ImmutableSet.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700233 }
234
235 @Test
236 public void testImmutableList() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800237 testSerializedEquals(ImmutableList.of(DID1, DID2));
238 testSerializedEquals(ImmutableList.of(DID1));
239 testSerializedEquals(ImmutableList.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700240 }
241
242 @Test
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800243 public void testFlowRuleBatchEntry() {
244 final FlowRule rule1 =
Ray Milkeyd13a37b2015-06-12 11:55:17 -0700245 DefaultFlowRule.builder()
246 .forDevice(DID1)
247 .withSelector(DefaultTrafficSelector.emptySelector())
248 .withTreatment(DefaultTrafficTreatment.emptyTreatment())
249 .withPriority(0)
250 .fromApp(new DefaultApplicationId(1, "1"))
251 .makeTemporary(1)
252 .build();
253
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800254 final FlowRuleBatchEntry entry1 =
255 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
256 final FlowRuleBatchEntry entry2 =
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800257 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800258
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800259 testSerializedEquals(entry1);
260 testSerializedEquals(entry2);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800261 }
262
263 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700264 public void testIpPrefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800265 testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700266 }
267
268 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800269 public void testIp4Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800270 testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800271 }
272
273 @Test
274 public void testIp6Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800275 testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800276 }
277
278 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700279 public void testIpAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800280 testSerializedEquals(IpAddress.valueOf("192.168.0.1"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700281 }
282
283 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800284 public void testIp4Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800285 testSerializedEquals(Ip4Address.valueOf("192.168.0.1"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800286 }
287
288 @Test
289 public void testIp6Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800290 testSerializedEquals(Ip6Address.valueOf("1111:2222::"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800291 }
292
293 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700294 public void testMacAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800295 testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700296 }
297
298 @Test
299 public void testLinkKey() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800300 testSerializedEquals(LinkKey.linkKey(CP1, CP2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700301 }
302
303 @Test
304 public void testNodeId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800305 testSerializedEquals(new NodeId("SomeNodeIdentifier"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700306 }
307
308 @Test
309 public void testPortNumber() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800310 testSerializedEquals(P1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700311 }
312
313 @Test
314 public void testProviderId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800315 testSerializedEquals(PID);
316 testSerializedEquals(PIDA);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700317 }
318
319 @Test
320 public void testMastershipTerm() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800321 testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2));
322 testSerializedEquals(MastershipTerm.of(null, 0));
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700323 }
324
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700325 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700326 public void testHostLocation() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800327 testSerializedEquals(new HostLocation(CP1, 1234L));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700328 }
329
330 @Test
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700331 public void testFlowId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800332 testSerializedEquals(FlowId.valueOf(0x12345678L));
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700333 }
334
335 @Test
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700336 public void testRoleInfo() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800337 testSerializedEquals(new RoleInfo(new NodeId("master"),
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700338 asList(new NodeId("stby1"), new NodeId("stby2"))));
339 }
340
341 @Test
Sho SHIMIZU91210a72015-04-29 12:54:28 -0700342 public void testIndexedLambda() {
343 testSerializedEquals(org.onosproject.net.Lambda.indexedLambda(10L));
344 }
345
346 @Test
347 public void testOchSignal() {
348 testSerializedEquals(org.onosproject.net.Lambda.ochSignal(
349 GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1
350 ));
351 }
352
353 @Test
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800354 public void testDefaultLinkResourceRequest() {
355 testSerializable(DefaultLinkResourceRequest.builder(IntentId.valueOf(2501), ImmutableList.of())
Sho SHIMIZU014c33a2015-04-30 11:40:37 -0700356 .addLambdaRequest()
357 .addBandwidthRequest(32.195)
358 .build()
359 );
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800360 }
361
362 @Test
363 public void testDefaultLinkResourceAllocations() {
364 LinkResourceRequest request = DefaultLinkResourceRequest
365 .builder(IntentId.valueOf(2501), ImmutableList.of())
366 .addLambdaRequest()
367 .addBandwidthRequest(32.195)
368 .build();
369 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
370 allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT),
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -0700371 ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))),
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -0700372 new LambdaResourceAllocation(LambdaResource.valueOf(1))));
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800373 testSerializable(new DefaultLinkResourceAllocations(request, allocations));
374 }
375
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700376 @Test
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800377 public void testResource() {
378 testSerializedEquals(Resource.discrete(DID1, P1, VLAN1));
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700379 }
380
381 @Test
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800382 public void testResourceKey() {
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800383 testSerializedEquals(Resource.discrete(DID1, P1).id());
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800384 }
385
386 @Test
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700387 public void testResourceAllocation() {
388 testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation(
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800389 Resource.discrete(DID1, P1, VLAN1),
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700390 IntentId.valueOf(30)));
391 }
Sho SHIMIZUdee78712015-04-30 09:33:52 -0700392
393 @Test
394 public void testFrequency() {
395 testSerializedEquals(Frequency.ofGHz(100));
396 }
397
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800398 @Test
Sho SHIMIZU81697792015-05-08 11:09:38 -0700399 public void testBandwidth() {
Sho SHIMIZU31f37ed2016-01-08 18:45:54 -0800400 testSerializedEquals(Bandwidth.mbps(1000));
Sho SHIMIZU63feca72015-05-07 10:44:25 -0700401 testSerializedEquals(Bandwidth.mbps(1000.0));
Sho SHIMIZU81697792015-05-08 11:09:38 -0700402 }
403
404 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800405 public void testLambdaConstraint() {
Sho SHIMIZU03d42532015-11-23 17:16:30 -0800406 testSerializable(new LambdaConstraint(new IndexedLambda(1)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800407 }
408
409 @Test
410 public void testBandwidthConstraint() {
Sho SHIMIZUa88db492015-11-23 13:21:04 -0800411 testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800412 }
413
414 @Test
415 public void testLinkTypeConstraint() {
416 testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT));
417 }
418
419 @Test
420 public void testLatencyConstraint() {
421 testSerializable(new LatencyConstraint(Duration.ofSeconds(10)));
422 }
423
424 @Test
425 public void testWaypointConstraint() {
426 testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2")));
427 }
428
429 @Test
430 public void testObstacleConstraint() {
431 testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2")));
432 }
433
434 @Test
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800435 public void testArraysAsList() {
436 testSerializedEquals(Arrays.asList(1, 2, 3));
437 }
438
439 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800440 public void testAnnotationConstraint() {
441 testSerializable(new AnnotationConstraint("distance", 100.0));
442 }
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800443
444 @Test
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800445 public void testDefaultGroupId() {
446 testSerializedEquals(new DefaultGroupId(99));
447 }
448
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -0800449 @Test
450 public void testEmptySet() {
451 testSerializedEquals(Collections.emptySet());
452 }
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800453
454 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700455 public void testAnnotations() {
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700456 // Annotations does not have equals defined, manually test equality
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700457 final byte[] a1Bytes = serializer.encode(A1);
458 SparseAnnotations copiedA1 = serializer.decode(a1Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700459 assertAnnotationsEquals(copiedA1, A1);
460
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700461 final byte[] a12Bytes = serializer.encode(A1_2);
462 SparseAnnotations copiedA12 = serializer.decode(a12Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700463 assertAnnotationsEquals(copiedA12, A1_2);
464 }
465
466 // code clone
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700467 protected static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700468 SparseAnnotations expected = DefaultAnnotations.builder().build();
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700469 for (SparseAnnotations a : annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700470 expected = DefaultAnnotations.union(expected, a);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700471 }
472 assertEquals(expected.keys(), actual.keys());
473 for (String key : expected.keys()) {
474 assertEquals(expected.value(key), actual.value(key));
475 }
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700476 }
477
478}