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