Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.serializers; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.ImmutableMap; |
| 20 | import com.google.common.collect.ImmutableSet; |
| 21 | import com.google.common.testing.EqualsTester; |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 22 | |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 23 | import org.junit.After; |
| 24 | import org.junit.Before; |
| 25 | import org.junit.BeforeClass; |
| 26 | import org.junit.Test; |
Sho SHIMIZU | 08ec48f | 2015-07-27 11:27:26 -0700 | [diff] [blame] | 27 | import org.onlab.packet.VlanId; |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 28 | import org.onlab.util.Bandwidth; |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 29 | import org.onlab.util.Frequency; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.cluster.NodeId; |
| 31 | import org.onosproject.cluster.RoleInfo; |
Ray Milkey | d13a37b | 2015-06-12 11:55:17 -0700 | [diff] [blame] | 32 | import org.onosproject.core.DefaultApplicationId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.core.DefaultGroupId; |
| 34 | import org.onosproject.mastership.MastershipTerm; |
| 35 | import org.onosproject.net.Annotations; |
Sho SHIMIZU | 014c33a | 2015-04-30 11:40:37 -0700 | [diff] [blame] | 36 | import org.onosproject.net.ChannelSpacing; |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 37 | import org.onosproject.net.CltSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 38 | import org.onosproject.net.ConnectPoint; |
| 39 | import org.onosproject.net.DefaultAnnotations; |
| 40 | import org.onosproject.net.DefaultDevice; |
| 41 | import org.onosproject.net.DefaultLink; |
| 42 | import org.onosproject.net.DefaultPort; |
| 43 | import org.onosproject.net.Device; |
| 44 | import org.onosproject.net.DeviceId; |
Sho SHIMIZU | 014c33a | 2015-04-30 11:40:37 -0700 | [diff] [blame] | 45 | import org.onosproject.net.GridType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 46 | import org.onosproject.net.HostLocation; |
| 47 | import org.onosproject.net.Link; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 48 | import org.onosproject.net.LinkKey; |
Yuta HIGUCHI | eb28a7c | 2017-01-13 18:59:27 -0800 | [diff] [blame] | 49 | import org.onosproject.net.MarkerResource; |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 50 | import org.onosproject.net.OchPort; |
Sho SHIMIZU | 0abceb8 | 2015-05-04 09:20:53 -0700 | [diff] [blame] | 51 | import org.onosproject.net.OchSignal; |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 52 | import org.onosproject.net.OduCltPort; |
| 53 | import org.onosproject.net.OmsPort; |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 54 | import org.onosproject.net.OtuPort; |
| 55 | import org.onosproject.net.OtuSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 56 | import org.onosproject.net.PortNumber; |
Sho SHIMIZU | 014c33a | 2015-04-30 11:40:37 -0700 | [diff] [blame] | 57 | import org.onosproject.net.OduSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 58 | import org.onosproject.net.SparseAnnotations; |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 59 | import org.onosproject.net.flow.DefaultFlowRule; |
| 60 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 61 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 62 | import org.onosproject.net.flow.FlowId; |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 63 | import org.onosproject.net.flow.FlowRule; |
| 64 | import org.onosproject.net.flow.FlowRuleBatchEntry; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 65 | import org.onosproject.net.intent.IntentId; |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 66 | import org.onosproject.net.resource.ResourceAllocation; |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 67 | import org.onosproject.net.resource.ResourceConsumerId; |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 68 | import org.onosproject.net.resource.Resources; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 69 | import org.onosproject.net.provider.ProviderId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 70 | import org.onosproject.net.intent.constraint.AnnotationConstraint; |
| 71 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 72 | import org.onosproject.net.intent.constraint.LatencyConstraint; |
| 73 | import org.onosproject.net.intent.constraint.LinkTypeConstraint; |
| 74 | import org.onosproject.net.intent.constraint.ObstacleConstraint; |
| 75 | import org.onosproject.net.intent.constraint.WaypointConstraint; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 76 | import org.onlab.packet.ChassisId; |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 77 | import org.onlab.packet.IpAddress; |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 78 | import org.onlab.packet.Ip4Address; |
| 79 | import org.onlab.packet.Ip6Address; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 80 | import org.onlab.packet.IpPrefix; |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 81 | import org.onlab.packet.Ip4Prefix; |
| 82 | import org.onlab.packet.Ip6Prefix; |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 83 | import org.onlab.packet.MacAddress; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 84 | |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 85 | import java.nio.ByteBuffer; |
Yuta HIGUCHI | 91768e3 | 2014-11-22 05:06:35 -0800 | [diff] [blame] | 86 | import java.util.Arrays; |
Jordi Ortiz | 1b1a3b4 | 2017-03-03 12:36:54 +0100 | [diff] [blame] | 87 | import java.util.BitSet; |
Yuta HIGUCHI | ae1d210 | 2014-11-25 19:26:01 -0800 | [diff] [blame] | 88 | import java.util.Collections; |
Sho SHIMIZU | 977cb60 | 2014-11-13 08:40:50 -0800 | [diff] [blame] | 89 | import java.time.Duration; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 90 | |
| 91 | import static java.util.Arrays.asList; |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 92 | import static org.junit.Assert.*; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 93 | import static org.onosproject.net.DeviceId.deviceId; |
| 94 | import static org.onosproject.net.PortNumber.portNumber; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 95 | |
Yuta HIGUCHI | 9ee0d5b | 2014-10-05 00:03:47 -0700 | [diff] [blame] | 96 | public class KryoSerializerTest { |
| 97 | |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 98 | private static final ProviderId PID = new ProviderId("of", "foo"); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 99 | private static final ProviderId PIDA = new ProviderId("of", "foo", true); |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 100 | private static final DeviceId DID1 = deviceId("of:foo"); |
| 101 | private static final DeviceId DID2 = deviceId("of:bar"); |
| 102 | private static final PortNumber P1 = portNumber(1); |
| 103 | private static final PortNumber P2 = portNumber(2); |
| 104 | private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1); |
| 105 | private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2); |
| 106 | private static final String MFR = "whitebox"; |
| 107 | private static final String HW = "1.1.x"; |
| 108 | private static final String SW1 = "3.8.1"; |
| 109 | private static final String SW2 = "3.9.5"; |
| 110 | private static final String SN = "43311-12345"; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 111 | private static final ChassisId CID = new ChassisId(); |
| 112 | private static final Device DEV1 = new DefaultDevice(PID, DID1, Device.Type.SWITCH, MFR, HW, |
| 113 | SW1, SN, CID); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 114 | private static final SparseAnnotations A1 = DefaultAnnotations.builder() |
| 115 | .set("A1", "a1") |
| 116 | .set("B1", "b1") |
| 117 | .build(); |
| 118 | private static final SparseAnnotations A1_2 = DefaultAnnotations.builder() |
| 119 | .remove("A1") |
| 120 | .set("B3", "b3") |
| 121 | .build(); |
Sho SHIMIZU | 0abceb8 | 2015-05-04 09:20:53 -0700 | [diff] [blame] | 122 | private static final OchSignal OCH_SIGNAL1 = (OchSignal) org.onosproject.net.Lambda.ochSignal( |
| 123 | GridType.DWDM, ChannelSpacing.CHL_100GHZ, -8, 4); |
Sho SHIMIZU | 08ec48f | 2015-07-27 11:27:26 -0700 | [diff] [blame] | 124 | private static final VlanId VLAN1 = VlanId.vlanId((short) 100); |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 125 | |
HIGUCHI Yuta | e729065 | 2016-05-18 11:29:01 -0700 | [diff] [blame] | 126 | private StoreSerializer serializer; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 127 | |
| 128 | @BeforeClass |
| 129 | public static void setUpBeforeClass() throws Exception { |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Before |
| 133 | public void setUp() throws Exception { |
HIGUCHI Yuta | e729065 | 2016-05-18 11:29:01 -0700 | [diff] [blame] | 134 | serializer = StoreSerializer.using(KryoNamespaces.API); |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | @After |
| 138 | public void tearDown() throws Exception { |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 141 | private <T> void testSerializedEquals(T original) { |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 142 | ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 143 | serializer.encode(original, buffer); |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 144 | buffer.flip(); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 145 | T copy = serializer.decode(buffer); |
| 146 | |
| 147 | T copy2 = serializer.decode(serializer.encode(original)); |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 148 | |
| 149 | new EqualsTester() |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 150 | .addEqualityGroup(original, copy, copy2) |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 151 | .testEquals(); |
| 152 | } |
| 153 | |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 154 | private <T> void testSerializable(T original) { |
| 155 | byte[] bs = serializer.encode(original); |
| 156 | T copy = serializer.decode(bs); |
| 157 | assertNotNull(copy); |
| 158 | } |
| 159 | |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 160 | |
| 161 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 162 | public void testConnectPoint() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 163 | testSerializedEquals(new ConnectPoint(DID1, P1)); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | @Test |
| 167 | public void testDefaultLink() { |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 168 | testSerializedEquals(DefaultLink.builder() |
| 169 | .providerId(PID) |
| 170 | .src(CP1) |
| 171 | .dst(CP2) |
| 172 | .type(Link.Type.DIRECT) |
| 173 | .build()); |
| 174 | testSerializedEquals(DefaultLink.builder() |
| 175 | .providerId(PID) |
| 176 | .src(CP1) |
| 177 | .dst(CP2) |
| 178 | .type(Link.Type.DIRECT) |
| 179 | .annotations(A1) |
| 180 | .build()); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | @Test |
| 184 | public void testDefaultPort() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 185 | testSerializedEquals(new DefaultPort(DEV1, P1, true)); |
| 186 | testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2)); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Test |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 190 | public void testOmsPort() { |
| 191 | testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300), |
| 192 | Frequency.ofGHz(100))); |
| 193 | testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300), |
| 194 | Frequency.ofGHz(100), A1_2)); |
| 195 | } |
| 196 | |
| 197 | @Test |
| 198 | public void testOchPort() { |
Sho SHIMIZU | 0abceb8 | 2015-05-04 09:20:53 -0700 | [diff] [blame] | 199 | testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1)); |
| 200 | testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1, A1_2)); |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | @Test |
| 204 | public void testOduCltPort() { |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 205 | testSerializedEquals(new OduCltPort(DEV1, P1, true, CltSignalType.CLT_10GBE)); |
| 206 | testSerializedEquals(new OduCltPort(DEV1, P1, true, CltSignalType.CLT_10GBE, A1_2)); |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | @Test |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 210 | public void testOtuPort() { |
| 211 | testSerializedEquals(new OtuPort(DEV1, P1, true, OtuSignalType.OTU2)); |
| 212 | testSerializedEquals(new OtuPort(DEV1, P1, true, OtuSignalType.OTU2, A1_2)); |
| 213 | } |
| 214 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 215 | public void testDeviceId() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 216 | testSerializedEquals(DID1); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | @Test |
| 220 | public void testImmutableMap() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 221 | testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1)); |
| 222 | testSerializedEquals(ImmutableMap.of(DID1, DEV1)); |
| 223 | testSerializedEquals(ImmutableMap.of()); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | @Test |
| 227 | public void testImmutableSet() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 228 | testSerializedEquals(ImmutableSet.of(DID1, DID2)); |
| 229 | testSerializedEquals(ImmutableSet.of(DID1)); |
| 230 | testSerializedEquals(ImmutableSet.of()); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | @Test |
| 234 | public void testImmutableList() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 235 | testSerializedEquals(ImmutableList.of(DID1, DID2)); |
| 236 | testSerializedEquals(ImmutableList.of(DID1)); |
| 237 | testSerializedEquals(ImmutableList.of()); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Test |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 241 | public void testFlowRuleBatchEntry() { |
| 242 | final FlowRule rule1 = |
Ray Milkey | d13a37b | 2015-06-12 11:55:17 -0700 | [diff] [blame] | 243 | DefaultFlowRule.builder() |
| 244 | .forDevice(DID1) |
| 245 | .withSelector(DefaultTrafficSelector.emptySelector()) |
| 246 | .withTreatment(DefaultTrafficTreatment.emptyTreatment()) |
| 247 | .withPriority(0) |
| 248 | .fromApp(new DefaultApplicationId(1, "1")) |
| 249 | .makeTemporary(1) |
| 250 | .build(); |
| 251 | |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 252 | final FlowRuleBatchEntry entry1 = |
| 253 | new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1); |
| 254 | final FlowRuleBatchEntry entry2 = |
Sho SHIMIZU | 7446da9 | 2015-01-22 16:27:06 -0800 | [diff] [blame] | 255 | new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L); |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 256 | |
Sho SHIMIZU | 7446da9 | 2015-01-22 16:27:06 -0800 | [diff] [blame] | 257 | testSerializedEquals(entry1); |
| 258 | testSerializedEquals(entry2); |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 262 | public void testIpPrefix() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 263 | testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24")); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | @Test |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 267 | public void testIp4Prefix() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 268 | testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24")); |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | @Test |
| 272 | public void testIp6Prefix() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 273 | testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120")); |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 277 | public void testIpAddress() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 278 | testSerializedEquals(IpAddress.valueOf("192.168.0.1")); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | @Test |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 282 | public void testIp4Address() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 283 | testSerializedEquals(Ip4Address.valueOf("192.168.0.1")); |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Test |
| 287 | public void testIp6Address() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 288 | testSerializedEquals(Ip6Address.valueOf("1111:2222::")); |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 292 | public void testMacAddress() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 293 | testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab")); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | @Test |
| 297 | public void testLinkKey() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 298 | testSerializedEquals(LinkKey.linkKey(CP1, CP2)); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | @Test |
| 302 | public void testNodeId() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 303 | testSerializedEquals(new NodeId("SomeNodeIdentifier")); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | @Test |
| 307 | public void testPortNumber() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 308 | testSerializedEquals(P1); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | @Test |
| 312 | public void testProviderId() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 313 | testSerializedEquals(PID); |
| 314 | testSerializedEquals(PIDA); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | @Test |
| 318 | public void testMastershipTerm() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 319 | testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2)); |
| 320 | testSerializedEquals(MastershipTerm.of(null, 0)); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Yuta HIGUCHI | 9ee0d5b | 2014-10-05 00:03:47 -0700 | [diff] [blame] | 323 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 324 | public void testHostLocation() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 325 | testSerializedEquals(new HostLocation(CP1, 1234L)); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | @Test |
Yuta HIGUCHI | 2fcfde9 | 2014-10-20 18:37:14 -0700 | [diff] [blame] | 329 | public void testFlowId() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 330 | testSerializedEquals(FlowId.valueOf(0x12345678L)); |
Yuta HIGUCHI | 2fcfde9 | 2014-10-20 18:37:14 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | @Test |
Yuta HIGUCHI | 40d0177 | 2014-10-21 00:08:44 -0700 | [diff] [blame] | 334 | public void testRoleInfo() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 335 | testSerializedEquals(new RoleInfo(new NodeId("master"), |
Yuta HIGUCHI | 40d0177 | 2014-10-21 00:08:44 -0700 | [diff] [blame] | 336 | asList(new NodeId("stby1"), new NodeId("stby2")))); |
| 337 | } |
| 338 | |
| 339 | @Test |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 340 | public void testOchSignal() { |
| 341 | testSerializedEquals(org.onosproject.net.Lambda.ochSignal( |
| 342 | GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1 |
| 343 | )); |
| 344 | } |
| 345 | |
| 346 | @Test |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 347 | public void testResource() { |
Sho SHIMIZU | 460b972 | 2016-01-28 10:48:26 -0800 | [diff] [blame] | 348 | testSerializedEquals(Resources.discrete(DID1, P1, VLAN1).resource()); |
Sho SHIMIZU | 08ec48f | 2015-07-27 11:27:26 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | @Test |
Sho SHIMIZU | 8d5ff16 | 2016-01-22 12:56:31 -0800 | [diff] [blame] | 352 | public void testResourceId() { |
Sho SHIMIZU | 460b972 | 2016-01-28 10:48:26 -0800 | [diff] [blame] | 353 | testSerializedEquals(Resources.discrete(DID1, P1).id()); |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | @Test |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 357 | public void testResourceAllocation() { |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 358 | testSerializedEquals(new ResourceAllocation( |
Sho SHIMIZU | 460b972 | 2016-01-28 10:48:26 -0800 | [diff] [blame] | 359 | Resources.discrete(DID1, P1, VLAN1).resource(), |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 360 | ResourceConsumerId.of(30L, IntentId.class))); |
Sho SHIMIZU | 08ec48f | 2015-07-27 11:27:26 -0700 | [diff] [blame] | 361 | } |
Sho SHIMIZU | dee7871 | 2015-04-30 09:33:52 -0700 | [diff] [blame] | 362 | |
| 363 | @Test |
| 364 | public void testFrequency() { |
| 365 | testSerializedEquals(Frequency.ofGHz(100)); |
| 366 | } |
| 367 | |
Sho SHIMIZU | 977cb60 | 2014-11-13 08:40:50 -0800 | [diff] [blame] | 368 | @Test |
Sho SHIMIZU | 8169779 | 2015-05-08 11:09:38 -0700 | [diff] [blame] | 369 | public void testBandwidth() { |
Sho SHIMIZU | 31f37ed | 2016-01-08 18:45:54 -0800 | [diff] [blame] | 370 | testSerializedEquals(Bandwidth.mbps(1000)); |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 371 | testSerializedEquals(Bandwidth.mbps(1000.0)); |
Sho SHIMIZU | 8169779 | 2015-05-08 11:09:38 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | @Test |
Sho SHIMIZU | 977cb60 | 2014-11-13 08:40:50 -0800 | [diff] [blame] | 375 | public void testBandwidthConstraint() { |
Sho SHIMIZU | a88db49 | 2015-11-23 13:21:04 -0800 | [diff] [blame] | 376 | testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0))); |
Sho SHIMIZU | 977cb60 | 2014-11-13 08:40:50 -0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | @Test |
| 380 | public void testLinkTypeConstraint() { |
| 381 | testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT)); |
| 382 | } |
| 383 | |
| 384 | @Test |
| 385 | public void testLatencyConstraint() { |
| 386 | testSerializable(new LatencyConstraint(Duration.ofSeconds(10))); |
| 387 | } |
| 388 | |
| 389 | @Test |
| 390 | public void testWaypointConstraint() { |
| 391 | testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2"))); |
| 392 | } |
| 393 | |
| 394 | @Test |
| 395 | public void testObstacleConstraint() { |
| 396 | testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2"))); |
| 397 | } |
| 398 | |
| 399 | @Test |
Yuta HIGUCHI | 91768e3 | 2014-11-22 05:06:35 -0800 | [diff] [blame] | 400 | public void testArraysAsList() { |
| 401 | testSerializedEquals(Arrays.asList(1, 2, 3)); |
| 402 | } |
| 403 | |
| 404 | @Test |
Sho SHIMIZU | 977cb60 | 2014-11-13 08:40:50 -0800 | [diff] [blame] | 405 | public void testAnnotationConstraint() { |
| 406 | testSerializable(new AnnotationConstraint("distance", 100.0)); |
| 407 | } |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 408 | |
| 409 | @Test |
Yuta HIGUCHI | f617123 | 2014-11-25 15:14:44 -0800 | [diff] [blame] | 410 | public void testDefaultGroupId() { |
| 411 | testSerializedEquals(new DefaultGroupId(99)); |
| 412 | } |
| 413 | |
Yuta HIGUCHI | ae1d210 | 2014-11-25 19:26:01 -0800 | [diff] [blame] | 414 | @Test |
| 415 | public void testEmptySet() { |
| 416 | testSerializedEquals(Collections.emptySet()); |
| 417 | } |
Yuta HIGUCHI | f617123 | 2014-11-25 15:14:44 -0800 | [diff] [blame] | 418 | |
| 419 | @Test |
Yuta HIGUCHI | eb28a7c | 2017-01-13 18:59:27 -0800 | [diff] [blame] | 420 | public void testMarkerResource() { |
| 421 | testSerializedEquals(MarkerResource.marker("testString")); |
| 422 | } |
| 423 | |
| 424 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 425 | public void testAnnotations() { |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 426 | // Annotations does not have equals defined, manually test equality |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 427 | final byte[] a1Bytes = serializer.encode(A1); |
| 428 | SparseAnnotations copiedA1 = serializer.decode(a1Bytes); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 429 | assertAnnotationsEquals(copiedA1, A1); |
| 430 | |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 431 | final byte[] a12Bytes = serializer.encode(A1_2); |
| 432 | SparseAnnotations copiedA12 = serializer.decode(a12Bytes); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 433 | assertAnnotationsEquals(copiedA12, A1_2); |
| 434 | } |
| 435 | |
| 436 | // code clone |
Sho SHIMIZU | 7d4f2f7 | 2016-04-06 16:42:29 -0700 | [diff] [blame] | 437 | private static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) { |
Yuta HIGUCHI | 9ee0d5b | 2014-10-05 00:03:47 -0700 | [diff] [blame] | 438 | SparseAnnotations expected = DefaultAnnotations.builder().build(); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 439 | for (SparseAnnotations a : annotations) { |
Yuta HIGUCHI | 9ee0d5b | 2014-10-05 00:03:47 -0700 | [diff] [blame] | 440 | expected = DefaultAnnotations.union(expected, a); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 441 | } |
| 442 | assertEquals(expected.keys(), actual.keys()); |
| 443 | for (String key : expected.keys()) { |
| 444 | assertEquals(expected.value(key), actual.value(key)); |
| 445 | } |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Jordi Ortiz | 1b1a3b4 | 2017-03-03 12:36:54 +0100 | [diff] [blame] | 448 | @Test |
| 449 | public void testBitSet() { |
| 450 | BitSet bs = new BitSet(32); |
| 451 | bs.set(2); |
| 452 | bs.set(8); |
| 453 | bs.set(12); |
| 454 | bs.set(18); |
| 455 | bs.set(25); |
| 456 | bs.set(511); |
| 457 | |
| 458 | testSerializedEquals(bs); |
| 459 | } |
| 460 | |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 461 | } |