blob: 8d2d3682aa35b4b2092e7a4be29f1e6d1aaca763 [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() {
Ray Milkey2693bda2016-01-22 16:08:14 -0800186 testSerializedEquals(DefaultLink.builder()
187 .providerId(PID)
188 .src(CP1)
189 .dst(CP2)
190 .type(Link.Type.DIRECT)
191 .build());
192 testSerializedEquals(DefaultLink.builder()
193 .providerId(PID)
194 .src(CP1)
195 .dst(CP2)
196 .type(Link.Type.DIRECT)
197 .annotations(A1)
198 .build());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700199 }
200
201 @Test
202 public void testDefaultPort() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800203 testSerializedEquals(new DefaultPort(DEV1, P1, true));
204 testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700205 }
206
207 @Test
Marc De Leenheerbb382352015-04-23 18:20:34 -0700208 public void testOmsPort() {
209 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
210 Frequency.ofGHz(100)));
211 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
212 Frequency.ofGHz(100), A1_2));
213 }
214
215 @Test
216 public void testOchPort() {
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700217 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1));
218 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1, A1_2));
Marc De Leenheerbb382352015-04-23 18:20:34 -0700219 }
220
221 @Test
222 public void testOduCltPort() {
Toru Furusawa72ee30c2016-01-08 13:29:04 -0800223 testSerializedEquals(new OduCltPort(DEV1, P1, true, CltSignalType.CLT_10GBE));
224 testSerializedEquals(new OduCltPort(DEV1, P1, true, CltSignalType.CLT_10GBE, A1_2));
Marc De Leenheerbb382352015-04-23 18:20:34 -0700225 }
226
227 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700228 public void testDeviceId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800229 testSerializedEquals(DID1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700230 }
231
232 @Test
233 public void testImmutableMap() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800234 testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1));
235 testSerializedEquals(ImmutableMap.of(DID1, DEV1));
236 testSerializedEquals(ImmutableMap.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700237 }
238
239 @Test
240 public void testImmutableSet() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800241 testSerializedEquals(ImmutableSet.of(DID1, DID2));
242 testSerializedEquals(ImmutableSet.of(DID1));
243 testSerializedEquals(ImmutableSet.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700244 }
245
246 @Test
247 public void testImmutableList() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800248 testSerializedEquals(ImmutableList.of(DID1, DID2));
249 testSerializedEquals(ImmutableList.of(DID1));
250 testSerializedEquals(ImmutableList.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700251 }
252
253 @Test
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800254 public void testFlowRuleBatchEntry() {
255 final FlowRule rule1 =
Ray Milkeyd13a37b2015-06-12 11:55:17 -0700256 DefaultFlowRule.builder()
257 .forDevice(DID1)
258 .withSelector(DefaultTrafficSelector.emptySelector())
259 .withTreatment(DefaultTrafficTreatment.emptyTreatment())
260 .withPriority(0)
261 .fromApp(new DefaultApplicationId(1, "1"))
262 .makeTemporary(1)
263 .build();
264
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800265 final FlowRuleBatchEntry entry1 =
266 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
267 final FlowRuleBatchEntry entry2 =
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800268 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800269
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800270 testSerializedEquals(entry1);
271 testSerializedEquals(entry2);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800272 }
273
274 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700275 public void testIpPrefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800276 testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700277 }
278
279 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800280 public void testIp4Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800281 testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800282 }
283
284 @Test
285 public void testIp6Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800286 testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800287 }
288
289 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700290 public void testIpAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800291 testSerializedEquals(IpAddress.valueOf("192.168.0.1"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700292 }
293
294 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800295 public void testIp4Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800296 testSerializedEquals(Ip4Address.valueOf("192.168.0.1"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800297 }
298
299 @Test
300 public void testIp6Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800301 testSerializedEquals(Ip6Address.valueOf("1111:2222::"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800302 }
303
304 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700305 public void testMacAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800306 testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700307 }
308
309 @Test
310 public void testLinkKey() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800311 testSerializedEquals(LinkKey.linkKey(CP1, CP2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700312 }
313
314 @Test
315 public void testNodeId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800316 testSerializedEquals(new NodeId("SomeNodeIdentifier"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700317 }
318
319 @Test
320 public void testPortNumber() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800321 testSerializedEquals(P1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700322 }
323
324 @Test
325 public void testProviderId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800326 testSerializedEquals(PID);
327 testSerializedEquals(PIDA);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700328 }
329
330 @Test
331 public void testMastershipTerm() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800332 testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2));
333 testSerializedEquals(MastershipTerm.of(null, 0));
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700334 }
335
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700336 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700337 public void testHostLocation() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800338 testSerializedEquals(new HostLocation(CP1, 1234L));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700339 }
340
341 @Test
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700342 public void testFlowId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800343 testSerializedEquals(FlowId.valueOf(0x12345678L));
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700344 }
345
346 @Test
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700347 public void testRoleInfo() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800348 testSerializedEquals(new RoleInfo(new NodeId("master"),
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700349 asList(new NodeId("stby1"), new NodeId("stby2"))));
350 }
351
352 @Test
Sho SHIMIZU91210a72015-04-29 12:54:28 -0700353 public void testIndexedLambda() {
354 testSerializedEquals(org.onosproject.net.Lambda.indexedLambda(10L));
355 }
356
357 @Test
358 public void testOchSignal() {
359 testSerializedEquals(org.onosproject.net.Lambda.ochSignal(
360 GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1
361 ));
362 }
363
364 @Test
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800365 public void testDefaultLinkResourceRequest() {
366 testSerializable(DefaultLinkResourceRequest.builder(IntentId.valueOf(2501), ImmutableList.of())
Sho SHIMIZU014c33a2015-04-30 11:40:37 -0700367 .addLambdaRequest()
368 .addBandwidthRequest(32.195)
369 .build()
370 );
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800371 }
372
373 @Test
374 public void testDefaultLinkResourceAllocations() {
375 LinkResourceRequest request = DefaultLinkResourceRequest
376 .builder(IntentId.valueOf(2501), ImmutableList.of())
377 .addLambdaRequest()
378 .addBandwidthRequest(32.195)
379 .build();
380 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
Ray Milkey2693bda2016-01-22 16:08:14 -0800381 allocations.put(DefaultLink.builder()
382 .providerId(PID)
383 .src(CP1).dst(CP2).type(Type.DIRECT).build(),
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -0700384 ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))),
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -0700385 new LambdaResourceAllocation(LambdaResource.valueOf(1))));
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800386 testSerializable(new DefaultLinkResourceAllocations(request, allocations));
387 }
388
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700389 @Test
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800390 public void testResource() {
Sho SHIMIZUf95b96e2016-01-25 19:35:15 -0800391 testSerializedEquals(Resource.discrete(DID1, P1, VLAN1).resource());
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700392 }
393
394 @Test
Sho SHIMIZU8d5ff162016-01-22 12:56:31 -0800395 public void testResourceId() {
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800396 testSerializedEquals(Resource.discrete(DID1, P1).id());
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800397 }
398
399 @Test
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700400 public void testResourceAllocation() {
401 testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation(
Sho SHIMIZUf95b96e2016-01-25 19:35:15 -0800402 Resource.discrete(DID1, P1, VLAN1).resource(),
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700403 IntentId.valueOf(30)));
404 }
Sho SHIMIZUdee78712015-04-30 09:33:52 -0700405
406 @Test
407 public void testFrequency() {
408 testSerializedEquals(Frequency.ofGHz(100));
409 }
410
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800411 @Test
Sho SHIMIZU81697792015-05-08 11:09:38 -0700412 public void testBandwidth() {
Sho SHIMIZU31f37ed2016-01-08 18:45:54 -0800413 testSerializedEquals(Bandwidth.mbps(1000));
Sho SHIMIZU63feca72015-05-07 10:44:25 -0700414 testSerializedEquals(Bandwidth.mbps(1000.0));
Sho SHIMIZU81697792015-05-08 11:09:38 -0700415 }
416
417 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800418 public void testLambdaConstraint() {
Sho SHIMIZU03d42532015-11-23 17:16:30 -0800419 testSerializable(new LambdaConstraint(new IndexedLambda(1)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800420 }
421
422 @Test
423 public void testBandwidthConstraint() {
Sho SHIMIZUa88db492015-11-23 13:21:04 -0800424 testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800425 }
426
427 @Test
428 public void testLinkTypeConstraint() {
429 testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT));
430 }
431
432 @Test
433 public void testLatencyConstraint() {
434 testSerializable(new LatencyConstraint(Duration.ofSeconds(10)));
435 }
436
437 @Test
438 public void testWaypointConstraint() {
439 testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2")));
440 }
441
442 @Test
443 public void testObstacleConstraint() {
444 testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2")));
445 }
446
447 @Test
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800448 public void testArraysAsList() {
449 testSerializedEquals(Arrays.asList(1, 2, 3));
450 }
451
452 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800453 public void testAnnotationConstraint() {
454 testSerializable(new AnnotationConstraint("distance", 100.0));
455 }
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800456
457 @Test
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800458 public void testDefaultGroupId() {
459 testSerializedEquals(new DefaultGroupId(99));
460 }
461
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -0800462 @Test
463 public void testEmptySet() {
464 testSerializedEquals(Collections.emptySet());
465 }
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800466
467 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700468 public void testAnnotations() {
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700469 // Annotations does not have equals defined, manually test equality
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700470 final byte[] a1Bytes = serializer.encode(A1);
471 SparseAnnotations copiedA1 = serializer.decode(a1Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700472 assertAnnotationsEquals(copiedA1, A1);
473
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700474 final byte[] a12Bytes = serializer.encode(A1_2);
475 SparseAnnotations copiedA12 = serializer.decode(a12Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700476 assertAnnotationsEquals(copiedA12, A1_2);
477 }
478
479 // code clone
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700480 protected static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700481 SparseAnnotations expected = DefaultAnnotations.builder().build();
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700482 for (SparseAnnotations a : annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700483 expected = DefaultAnnotations.union(expected, a);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700484 }
485 assertEquals(expected.keys(), actual.keys());
486 for (String key : expected.keys()) {
487 assertEquals(expected.value(key), actual.value(key));
488 }
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700489 }
490
491}