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