2 * Copyright 2014-2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.store.serializers;
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.collect.Maps;
22 import org.onlab.packet.ChassisId;
23 import org.onlab.packet.EthType;
24 import org.onlab.packet.Ip4Address;
25 import org.onlab.packet.Ip4Prefix;
26 import org.onlab.packet.Ip6Address;
27 import org.onlab.packet.Ip6Prefix;
28 import org.onlab.packet.IpAddress;
29 import org.onlab.packet.IpPrefix;
30 import org.onlab.packet.MacAddress;
31 import org.onlab.packet.TpPort;
32 import org.onlab.packet.VlanId;
33 import org.onlab.util.Bandwidth;
34 import org.onlab.util.Frequency;
35 import org.onlab.util.KryoNamespace;
36 import org.onosproject.app.ApplicationState;
37 import org.onosproject.cluster.ControllerNode;
38 import org.onosproject.cluster.DefaultControllerNode;
39 import org.onosproject.cluster.Leadership;
40 import org.onosproject.cluster.LeadershipEvent;
41 import org.onosproject.cluster.NodeId;
42 import org.onosproject.cluster.RoleInfo;
43 import org.onosproject.core.ApplicationRole;
44 import org.onosproject.core.DefaultApplication;
45 import org.onosproject.core.DefaultApplicationId;
46 import org.onosproject.core.DefaultGroupId;
47 import org.onosproject.core.Version;
48 import org.onosproject.incubator.net.domain.IntentDomainId;
49 import org.onosproject.mastership.MastershipTerm;
50 import org.onosproject.net.Annotations;
51 import org.onosproject.net.ChannelSpacing;
52 import org.onosproject.net.ConnectPoint;
53 import org.onosproject.net.DefaultAnnotations;
54 import org.onosproject.net.DefaultDevice;
55 import org.onosproject.net.DefaultEdgeLink;
56 import org.onosproject.net.DefaultHost;
57 import org.onosproject.net.DefaultLink;
58 import org.onosproject.net.DefaultPath;
59 import org.onosproject.net.DefaultPort;
60 import org.onosproject.net.Device;
61 import org.onosproject.net.DeviceId;
62 import org.onosproject.net.Element;
63 import org.onosproject.net.GridType;
64 import org.onosproject.net.HostId;
65 import org.onosproject.net.HostLocation;
66 import org.onosproject.net.IndexedLambda;
67 import org.onosproject.net.Link;
68 import org.onosproject.net.LinkKey;
69 import org.onosproject.net.OchPort;
70 import org.onosproject.net.OchSignal;
71 import org.onosproject.net.OchSignalType;
72 import org.onosproject.net.OduCltPort;
73 import org.onosproject.net.OduSignalType;
74 import org.onosproject.net.OmsPort;
75 import org.onosproject.net.Port;
76 import org.onosproject.net.PortNumber;
77 import org.onosproject.net.device.DefaultDeviceDescription;
78 import org.onosproject.net.device.DefaultPortDescription;
79 import org.onosproject.net.device.DefaultPortStatistics;
80 import org.onosproject.net.device.OchPortDescription;
81 import org.onosproject.net.device.OduCltPortDescription;
82 import org.onosproject.net.device.OmsPortDescription;
83 import org.onosproject.net.device.PortStatistics;
84 import org.onosproject.net.flow.CompletedBatchOperation;
85 import org.onosproject.net.flow.DefaultFlowEntry;
86 import org.onosproject.net.flow.DefaultFlowRule;
87 import org.onosproject.net.flow.DefaultTableStatisticsEntry;
88 import org.onosproject.net.flow.DefaultTrafficSelector;
89 import org.onosproject.net.flow.DefaultTrafficTreatment;
90 import org.onosproject.net.flow.FlowEntry;
91 import org.onosproject.net.flow.FlowId;
92 import org.onosproject.net.flow.FlowRuleBatchEntry;
93 import org.onosproject.net.flow.FlowRuleBatchEvent;
94 import org.onosproject.net.flow.FlowRuleBatchOperation;
95 import org.onosproject.net.flow.FlowRuleBatchRequest;
96 import org.onosproject.net.flow.FlowRuleEvent;
97 import org.onosproject.net.flow.FlowRuleExtPayLoad;
98 import org.onosproject.net.flow.StoredFlowEntry;
99 import org.onosproject.net.flow.TableStatisticsEntry;
100 import org.onosproject.net.flow.criteria.Criterion;
101 import org.onosproject.net.flow.criteria.EthCriterion;
102 import org.onosproject.net.flow.criteria.EthTypeCriterion;
103 import org.onosproject.net.flow.criteria.IPCriterion;
104 import org.onosproject.net.flow.criteria.IPDscpCriterion;
105 import org.onosproject.net.flow.criteria.IPEcnCriterion;
106 import org.onosproject.net.flow.criteria.IPProtocolCriterion;
107 import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion;
108 import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion;
109 import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion;
110 import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion;
111 import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
112 import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
113 import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
114 import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
115 import org.onosproject.net.flow.criteria.IndexedLambdaCriterion;
116 import org.onosproject.net.flow.criteria.LambdaCriterion;
117 import org.onosproject.net.flow.criteria.MetadataCriterion;
118 import org.onosproject.net.flow.criteria.MplsCriterion;
119 import org.onosproject.net.flow.criteria.OchSignalCriterion;
120 import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
121 import org.onosproject.net.flow.criteria.PortCriterion;
122 import org.onosproject.net.flow.criteria.SctpPortCriterion;
123 import org.onosproject.net.flow.criteria.TcpPortCriterion;
124 import org.onosproject.net.flow.criteria.TunnelIdCriterion;
125 import org.onosproject.net.flow.criteria.UdpPortCriterion;
126 import org.onosproject.net.flow.criteria.VlanIdCriterion;
127 import org.onosproject.net.flow.criteria.VlanPcpCriterion;
128 import org.onosproject.net.flow.instructions.Instructions;
129 import org.onosproject.net.flow.instructions.L0ModificationInstruction;
130 import org.onosproject.net.flow.instructions.L2ModificationInstruction;
131 import org.onosproject.net.flow.instructions.L3ModificationInstruction;
132 import org.onosproject.net.flow.instructions.L4ModificationInstruction;
133 import org.onosproject.net.host.DefaultHostDescription;
134 import org.onosproject.net.host.HostDescription;
135 import org.onosproject.net.intent.ConnectivityIntent;
136 import org.onosproject.net.intent.FlowRuleIntent;
137 import org.onosproject.net.intent.HostToHostIntent;
138 import org.onosproject.net.intent.Intent;
139 import org.onosproject.net.intent.IntentId;
140 import org.onosproject.net.intent.IntentOperation;
141 import org.onosproject.net.intent.IntentState;
142 import org.onosproject.net.intent.Key;
143 import org.onosproject.net.intent.LinkCollectionIntent;
144 import org.onosproject.net.intent.MplsIntent;
145 import org.onosproject.net.intent.MplsPathIntent;
146 import org.onosproject.net.intent.MultiPointToSinglePointIntent;
147 import org.onosproject.net.intent.OpticalCircuitIntent;
148 import org.onosproject.net.intent.OpticalConnectivityIntent;
149 import org.onosproject.net.intent.OpticalPathIntent;
150 import org.onosproject.net.intent.PathIntent;
151 import org.onosproject.net.intent.PointToPointIntent;
152 import org.onosproject.net.intent.SinglePointToMultiPointIntent;
153 import org.onosproject.net.intent.constraint.AnnotationConstraint;
154 import org.onosproject.net.intent.constraint.BandwidthConstraint;
155 import org.onosproject.net.intent.constraint.BooleanConstraint;
156 import org.onosproject.net.intent.constraint.LambdaConstraint;
157 import org.onosproject.net.intent.constraint.LatencyConstraint;
158 import org.onosproject.net.intent.constraint.LinkTypeConstraint;
159 import org.onosproject.net.intent.constraint.ObstacleConstraint;
160 import org.onosproject.net.intent.constraint.PartialFailureConstraint;
161 import org.onosproject.net.intent.constraint.WaypointConstraint;
162 import org.onosproject.net.link.DefaultLinkDescription;
163 import org.onosproject.net.meter.MeterId;
164 import org.onosproject.net.newresource.ResourceAllocation;
165 import org.onosproject.net.newresource.ResourcePath;
166 import org.onosproject.net.packet.DefaultOutboundPacket;
167 import org.onosproject.net.packet.DefaultPacketRequest;
168 import org.onosproject.net.packet.PacketPriority;
169 import org.onosproject.net.provider.ProviderId;
170 import org.onosproject.net.resource.link.BandwidthResource;
171 import org.onosproject.net.resource.link.BandwidthResourceAllocation;
172 import org.onosproject.net.resource.link.BandwidthResourceRequest;
173 import org.onosproject.net.resource.link.DefaultLinkResourceAllocations;
174 import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
175 import org.onosproject.net.resource.link.LambdaResource;
176 import org.onosproject.net.resource.link.LambdaResourceAllocation;
177 import org.onosproject.net.resource.link.LambdaResourceRequest;
178 import org.onosproject.net.resource.link.LinkResourceRequest;
179 import org.onosproject.net.resource.link.MplsLabel;
180 import org.onosproject.net.resource.link.MplsLabelResourceAllocation;
181 import org.onosproject.net.resource.link.MplsLabelResourceRequest;
182 import org.onosproject.store.Timestamp;
183 import org.onosproject.store.service.MapEvent;
184 import org.onosproject.store.service.SetEvent;
185 import org.onosproject.store.service.Versioned;
188 import java.time.Duration;
189 import java.util.ArrayList;
190 import java.util.Arrays;
191 import java.util.Collections;
192 import java.util.HashMap;
193 import java.util.HashSet;
194 import java.util.LinkedList;
195 import java.util.Optional;
196 import java.util.concurrent.ConcurrentHashMap;
197 import java.util.concurrent.CopyOnWriteArraySet;
198 import java.util.concurrent.atomic.AtomicBoolean;
199 import java.util.concurrent.atomic.AtomicInteger;
200 import java.util.concurrent.atomic.AtomicLong;
202 public final class KryoNamespaces {
204 public static final KryoNamespace BASIC = KryoNamespace.newBuilder()
205 .nextId(KryoNamespace.FLOATING_ID)
206 .register(byte[].class)
207 .register(AtomicBoolean.class)
208 .register(AtomicInteger.class)
209 .register(AtomicLong.class)
210 .register(new ImmutableListSerializer(),
212 ImmutableList.of(1).getClass(),
213 ImmutableList.of(1, 2).getClass())
214 .register(new ImmutableSetSerializer(),
216 ImmutableSet.of().getClass(),
217 ImmutableSet.of(1).getClass(),
218 ImmutableSet.of(1, 2).getClass())
219 .register(new ImmutableMapSerializer(),
221 ImmutableMap.of().getClass(),
222 ImmutableMap.of("a", 1).getClass(),
223 ImmutableMap.of("R", 2, "D", 2).getClass())
224 .register(HashMap.class)
225 .register(ConcurrentHashMap.class)
226 .register(CopyOnWriteArraySet.class)
227 .register(ArrayList.class,
231 .register(Maps.immutableEntry("a", "b").getClass())
232 .register(new ArraysAsListSerializer(), Arrays.asList().getClass())
233 .register(Collections.singletonList(1).getClass())
234 .register(Duration.class)
235 .register(Collections.emptySet().getClass())
236 .register(Optional.class)
237 .register(Collections.emptyList().getClass())
238 .register(Collections.unmodifiableSet(Collections.emptySet()).getClass())
239 .register(Collections.singleton(Object.class).getClass())
243 * KryoNamespace which can serialize ON.lab misc classes.
245 public static final KryoNamespace MISC = KryoNamespace.newBuilder()
246 .nextId(KryoNamespace.FLOATING_ID)
247 .register(new IpPrefixSerializer(), IpPrefix.class)
248 .register(new Ip4PrefixSerializer(), Ip4Prefix.class)
249 .register(new Ip6PrefixSerializer(), Ip6Prefix.class)
250 .register(new IpAddressSerializer(), IpAddress.class)
251 .register(new Ip4AddressSerializer(), Ip4Address.class)
252 .register(new Ip6AddressSerializer(), Ip6Address.class)
253 .register(new MacAddressSerializer(), MacAddress.class)
254 .register(VlanId.class)
255 .register(Frequency.class)
256 .register(Bandwidth.class)
260 * Kryo registration Id for user custom registration.
262 public static final int BEGIN_USER_CUSTOM_ID = 300;
264 // TODO: Populate other classes
266 * KryoNamespace which can serialize API bundle classes.
268 public static final KryoNamespace API = KryoNamespace.newBuilder()
269 .nextId(KryoNamespace.INITIAL_ID)
271 .nextId(KryoNamespace.INITIAL_ID + 30)
273 .nextId(KryoNamespace.INITIAL_ID + 30 + 10)
275 Instructions.MeterInstruction.class,
278 ControllerNode.State.class,
279 ApplicationState.class,
280 ApplicationRole.class,
281 DefaultApplication.class,
285 DefaultControllerNode.class,
287 DefaultDeviceDescription.class,
289 DefaultLinkDescription.class,
291 DefaultPortDescription.class,
297 LeadershipEvent.class,
298 LeadershipEvent.Type.class,
300 HostDescription.class,
301 DefaultHostDescription.class,
302 DefaultFlowEntry.class,
303 StoredFlowEntry.class,
304 DefaultFlowRule.class,
305 DefaultFlowEntry.class,
306 DefaultPacketRequest.class,
307 PacketPriority.class,
308 FlowEntry.FlowEntryState.class,
310 DefaultTrafficSelector.class,
312 MetadataCriterion.class,
315 EthTypeCriterion.class,
316 VlanIdCriterion.class,
317 VlanPcpCriterion.class,
318 IPDscpCriterion.class,
319 IPEcnCriterion.class,
320 IPProtocolCriterion.class,
323 TcpPortCriterion.class,
324 UdpPortCriterion.class,
325 SctpPortCriterion.class,
326 IcmpTypeCriterion.class,
327 IcmpCodeCriterion.class,
328 IPv6FlowLabelCriterion.class,
329 Icmpv6TypeCriterion.class,
330 Icmpv6CodeCriterion.class,
331 IPv6NDTargetAddressCriterion.class,
332 IPv6NDLinkLayerAddressCriterion.class,
334 TunnelIdCriterion.class,
335 IPv6ExthdrFlagsCriterion.class,
336 LambdaCriterion.class,
337 IndexedLambdaCriterion.class,
338 OchSignalCriterion.class,
339 OchSignalTypeCriterion.class,
341 Criterion.Type.class,
342 DefaultTrafficTreatment.class,
343 Instructions.DropInstruction.class,
344 Instructions.NoActionInstruction.class,
345 Instructions.OutputInstruction.class,
346 Instructions.GroupInstruction.class,
347 Instructions.TableTypeTransition.class,
348 L0ModificationInstruction.class,
349 L0ModificationInstruction.L0SubType.class,
350 L0ModificationInstruction.ModLambdaInstruction.class,
351 L0ModificationInstruction.ModOchSignalInstruction.class,
352 L2ModificationInstruction.class,
353 L2ModificationInstruction.L2SubType.class,
354 L2ModificationInstruction.ModEtherInstruction.class,
355 L2ModificationInstruction.PushHeaderInstructions.class,
356 L2ModificationInstruction.ModVlanIdInstruction.class,
357 L2ModificationInstruction.ModVlanPcpInstruction.class,
358 L2ModificationInstruction.PopVlanInstruction.class,
359 L2ModificationInstruction.ModMplsLabelInstruction.class,
360 L2ModificationInstruction.ModMplsTtlInstruction.class,
361 L2ModificationInstruction.ModTunnelIdInstruction.class,
362 L3ModificationInstruction.class,
363 L3ModificationInstruction.L3SubType.class,
364 L3ModificationInstruction.ModIPInstruction.class,
365 L3ModificationInstruction.ModIPv6FlowLabelInstruction.class,
366 L3ModificationInstruction.ModTtlInstruction.class,
367 L4ModificationInstruction.class,
368 L4ModificationInstruction.L4SubType.class,
369 L4ModificationInstruction.ModTransportPortInstruction.class,
371 FlowRuleBatchEvent.class,
372 FlowRuleBatchEvent.Type.class,
373 FlowRuleBatchRequest.class,
374 FlowRuleBatchOperation.class,
376 FlowRuleEvent.Type.class,
377 CompletedBatchOperation.class,
378 FlowRuleBatchEntry.class,
379 FlowRuleBatchEntry.FlowRuleOperation.class,
382 //Key.class, is abstract
383 Key.of(1L, new DefaultApplicationId(0, "bar")).getClass(), //LongKey.class
384 Key.of("foo", new DefaultApplicationId(0, "bar")).getClass(), //StringKey.class
386 ConnectivityIntent.class,
389 DefaultEdgeLink.class,
390 HostToHostIntent.class,
391 PointToPointIntent.class,
392 MultiPointToSinglePointIntent.class,
393 SinglePointToMultiPointIntent.class,
394 FlowRuleIntent.class,
395 LinkCollectionIntent.class,
396 OpticalConnectivityIntent.class,
397 OpticalPathIntent.class,
398 OpticalCircuitIntent.class,
399 LinkResourceRequest.class,
400 DefaultLinkResourceRequest.class,
401 BandwidthResourceRequest.class,
402 LambdaResourceRequest.class,
403 LambdaResource.class,
404 BandwidthResource.class,
405 DefaultLinkResourceAllocations.class,
406 BandwidthResourceAllocation.class,
407 LambdaResourceAllocation.class,
409 ResourceAllocation.class,
411 LambdaConstraint.class,
412 BandwidthConstraint.class,
413 LinkTypeConstraint.class,
414 LatencyConstraint.class,
415 WaypointConstraint.class,
416 ObstacleConstraint.class,
417 AnnotationConstraint.class,
418 BooleanConstraint.class,
419 PartialFailureConstraint.class,
420 IntentOperation.class,
421 FlowRuleExtPayLoad.class,
423 DefaultAnnotations.class,
424 PortStatistics.class,
425 DefaultPortStatistics.class,
426 IntentDomainId.class,
427 TableStatisticsEntry.class,
428 DefaultTableStatisticsEntry.class
430 .register(new DefaultApplicationIdSerializer(), DefaultApplicationId.class)
431 .register(new URISerializer(), URI.class)
432 .register(new NodeIdSerializer(), NodeId.class)
433 .register(new ProviderIdSerializer(), ProviderId.class)
434 .register(new DeviceIdSerializer(), DeviceId.class)
435 .register(new PortNumberSerializer(), PortNumber.class)
436 .register(new DefaultPortSerializer(), DefaultPort.class)
437 .register(new LinkKeySerializer(), LinkKey.class)
438 .register(new ConnectPointSerializer(), ConnectPoint.class)
439 .register(new DefaultLinkSerializer(), DefaultLink.class)
440 .register(new MastershipTermSerializer(), MastershipTerm.class)
441 .register(new HostLocationSerializer(), HostLocation.class)
442 .register(new DefaultOutboundPacketSerializer(), DefaultOutboundPacket.class)
443 .register(new AnnotationsSerializer(), DefaultAnnotations.class)
444 .register(Versioned.class)
445 .register(MapEvent.class)
446 .register(MapEvent.Type.class)
447 .register(SetEvent.class)
448 .register(SetEvent.Type.class)
449 .register(DefaultGroupId.class)
450 .register(Annotations.class)
451 .register(OmsPort.class)
452 .register(OchPort.class)
453 .register(OduSignalType.class)
454 .register(OchSignalType.class)
455 .register(GridType.class)
456 .register(ChannelSpacing.class)
457 .register(OduCltPort.class)
458 .register(OduCltPort.SignalType.class)
459 .register(IndexedLambda.class)
460 .register(OchSignal.class)
461 .register(OduCltPortDescription.class)
462 .register(OchPortDescription.class)
463 .register(OmsPortDescription.class)
466 MplsPathIntent.class,
467 MplsLabelResourceAllocation.class,
468 MplsLabelResourceRequest.class,
470 org.onlab.packet.MplsLabel.class,
471 org.onlab.packet.MPLS.class
477 // not to be instantiated
478 private KryoNamespaces() {}