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.OduSignalId;
74 import org.onosproject.net.OduSignalType;
75 import org.onosproject.net.OmsPort;
76 import org.onosproject.net.Port;
77 import org.onosproject.net.PortNumber;
78 import org.onosproject.net.device.DefaultDeviceDescription;
79 import org.onosproject.net.device.DefaultPortDescription;
80 import org.onosproject.net.device.DefaultPortStatistics;
81 import org.onosproject.net.device.OchPortDescription;
82 import org.onosproject.net.device.OduCltPortDescription;
83 import org.onosproject.net.device.OmsPortDescription;
84 import org.onosproject.net.device.PortStatistics;
85 import org.onosproject.net.flow.CompletedBatchOperation;
86 import org.onosproject.net.flow.DefaultFlowEntry;
87 import org.onosproject.net.flow.DefaultFlowRule;
88 import org.onosproject.net.flow.DefaultTableStatisticsEntry;
89 import org.onosproject.net.flow.DefaultTrafficSelector;
90 import org.onosproject.net.flow.DefaultTrafficTreatment;
91 import org.onosproject.net.flow.FlowEntry;
92 import org.onosproject.net.flow.FlowId;
93 import org.onosproject.net.flow.FlowRuleBatchEntry;
94 import org.onosproject.net.flow.FlowRuleBatchEvent;
95 import org.onosproject.net.flow.FlowRuleBatchOperation;
96 import org.onosproject.net.flow.FlowRuleBatchRequest;
97 import org.onosproject.net.flow.FlowRuleEvent;
98 import org.onosproject.net.flow.FlowRuleExtPayLoad;
99 import org.onosproject.net.flow.StoredFlowEntry;
100 import org.onosproject.net.flow.TableStatisticsEntry;
101 import org.onosproject.net.flow.criteria.Criterion;
102 import org.onosproject.net.flow.criteria.EthCriterion;
103 import org.onosproject.net.flow.criteria.EthTypeCriterion;
104 import org.onosproject.net.flow.criteria.IPCriterion;
105 import org.onosproject.net.flow.criteria.IPDscpCriterion;
106 import org.onosproject.net.flow.criteria.IPEcnCriterion;
107 import org.onosproject.net.flow.criteria.IPProtocolCriterion;
108 import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion;
109 import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion;
110 import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion;
111 import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion;
112 import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
113 import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
114 import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
115 import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
116 import org.onosproject.net.flow.criteria.IndexedLambdaCriterion;
117 import org.onosproject.net.flow.criteria.LambdaCriterion;
118 import org.onosproject.net.flow.criteria.MetadataCriterion;
119 import org.onosproject.net.flow.criteria.MplsCriterion;
120 import org.onosproject.net.flow.criteria.OchSignalCriterion;
121 import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
122 import org.onosproject.net.flow.criteria.OduSignalIdCriterion;
123 import org.onosproject.net.flow.criteria.OduSignalTypeCriterion;
124 import org.onosproject.net.flow.criteria.PortCriterion;
125 import org.onosproject.net.flow.criteria.SctpPortCriterion;
126 import org.onosproject.net.flow.criteria.TcpPortCriterion;
127 import org.onosproject.net.flow.criteria.TunnelIdCriterion;
128 import org.onosproject.net.flow.criteria.UdpPortCriterion;
129 import org.onosproject.net.flow.criteria.VlanIdCriterion;
130 import org.onosproject.net.flow.criteria.VlanPcpCriterion;
131 import org.onosproject.net.flow.instructions.ExtensionType;
132 import org.onosproject.net.flow.instructions.Instructions;
133 import org.onosproject.net.flow.instructions.L0ModificationInstruction;
134 import org.onosproject.net.flow.instructions.L1ModificationInstruction;
135 import org.onosproject.net.flow.instructions.L2ModificationInstruction;
136 import org.onosproject.net.flow.instructions.L3ModificationInstruction;
137 import org.onosproject.net.flow.instructions.L4ModificationInstruction;
138 import org.onosproject.net.host.DefaultHostDescription;
139 import org.onosproject.net.host.HostDescription;
140 import org.onosproject.net.intent.ConnectivityIntent;
141 import org.onosproject.net.intent.FlowRuleIntent;
142 import org.onosproject.net.intent.HostToHostIntent;
143 import org.onosproject.net.intent.Intent;
144 import org.onosproject.net.intent.IntentId;
145 import org.onosproject.net.intent.IntentOperation;
146 import org.onosproject.net.intent.IntentState;
147 import org.onosproject.net.intent.Key;
148 import org.onosproject.net.intent.LinkCollectionIntent;
149 import org.onosproject.net.intent.MplsIntent;
150 import org.onosproject.net.intent.MplsPathIntent;
151 import org.onosproject.net.intent.MultiPointToSinglePointIntent;
152 import org.onosproject.net.intent.OpticalCircuitIntent;
153 import org.onosproject.net.intent.OpticalConnectivityIntent;
154 import org.onosproject.net.intent.OpticalPathIntent;
155 import org.onosproject.net.intent.PathIntent;
156 import org.onosproject.net.intent.PointToPointIntent;
157 import org.onosproject.net.intent.SinglePointToMultiPointIntent;
158 import org.onosproject.net.intent.constraint.AnnotationConstraint;
159 import org.onosproject.net.intent.constraint.BandwidthConstraint;
160 import org.onosproject.net.intent.constraint.BooleanConstraint;
161 import org.onosproject.net.intent.constraint.LambdaConstraint;
162 import org.onosproject.net.intent.constraint.LatencyConstraint;
163 import org.onosproject.net.intent.constraint.LinkTypeConstraint;
164 import org.onosproject.net.intent.constraint.ObstacleConstraint;
165 import org.onosproject.net.intent.constraint.PartialFailureConstraint;
166 import org.onosproject.net.intent.constraint.WaypointConstraint;
167 import org.onosproject.net.link.DefaultLinkDescription;
168 import org.onosproject.net.meter.MeterId;
169 import org.onosproject.net.newresource.ResourceAllocation;
170 import org.onosproject.net.newresource.ResourcePath;
171 import org.onosproject.net.packet.DefaultOutboundPacket;
172 import org.onosproject.net.packet.DefaultPacketRequest;
173 import org.onosproject.net.packet.PacketPriority;
174 import org.onosproject.net.provider.ProviderId;
175 import org.onosproject.net.resource.link.BandwidthResource;
176 import org.onosproject.net.resource.link.BandwidthResourceAllocation;
177 import org.onosproject.net.resource.link.BandwidthResourceRequest;
178 import org.onosproject.net.resource.link.DefaultLinkResourceAllocations;
179 import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
180 import org.onosproject.net.resource.link.LambdaResource;
181 import org.onosproject.net.resource.link.LambdaResourceAllocation;
182 import org.onosproject.net.resource.link.LambdaResourceRequest;
183 import org.onosproject.net.resource.link.LinkResourceRequest;
184 import org.onosproject.net.resource.link.MplsLabel;
185 import org.onosproject.net.resource.link.MplsLabelResourceAllocation;
186 import org.onosproject.net.resource.link.MplsLabelResourceRequest;
187 import org.onosproject.store.Timestamp;
188 import org.onosproject.store.service.MapEvent;
189 import org.onosproject.store.service.SetEvent;
190 import org.onosproject.store.service.Versioned;
193 import java.time.Duration;
194 import java.util.ArrayList;
195 import java.util.Arrays;
196 import java.util.Collections;
197 import java.util.HashMap;
198 import java.util.HashSet;
199 import java.util.LinkedList;
200 import java.util.Optional;
201 import java.util.concurrent.ConcurrentHashMap;
202 import java.util.concurrent.CopyOnWriteArraySet;
203 import java.util.concurrent.atomic.AtomicBoolean;
204 import java.util.concurrent.atomic.AtomicInteger;
205 import java.util.concurrent.atomic.AtomicLong;
207 public final class KryoNamespaces {
209 public static final KryoNamespace BASIC = KryoNamespace.newBuilder()
210 .nextId(KryoNamespace.FLOATING_ID)
211 .register(byte[].class)
212 .register(AtomicBoolean.class)
213 .register(AtomicInteger.class)
214 .register(AtomicLong.class)
215 .register(new ImmutableListSerializer(),
217 ImmutableList.of(1).getClass(),
218 ImmutableList.of(1, 2).getClass())
219 .register(new ImmutableSetSerializer(),
221 ImmutableSet.of().getClass(),
222 ImmutableSet.of(1).getClass(),
223 ImmutableSet.of(1, 2).getClass())
224 .register(new ImmutableMapSerializer(),
226 ImmutableMap.of().getClass(),
227 ImmutableMap.of("a", 1).getClass(),
228 ImmutableMap.of("R", 2, "D", 2).getClass())
229 .register(HashMap.class)
230 .register(ConcurrentHashMap.class)
231 .register(CopyOnWriteArraySet.class)
232 .register(ArrayList.class,
236 .register(Maps.immutableEntry("a", "b").getClass())
237 .register(new ArraysAsListSerializer(), Arrays.asList().getClass())
238 .register(Collections.singletonList(1).getClass())
239 .register(Duration.class)
240 .register(Collections.emptySet().getClass())
241 .register(Optional.class)
242 .register(Collections.emptyList().getClass())
243 .register(Collections.unmodifiableSet(Collections.emptySet()).getClass())
244 .register(Collections.singleton(Object.class).getClass())
248 * KryoNamespace which can serialize ON.lab misc classes.
250 public static final KryoNamespace MISC = KryoNamespace.newBuilder()
251 .nextId(KryoNamespace.FLOATING_ID)
252 .register(new IpPrefixSerializer(), IpPrefix.class)
253 .register(new Ip4PrefixSerializer(), Ip4Prefix.class)
254 .register(new Ip6PrefixSerializer(), Ip6Prefix.class)
255 .register(new IpAddressSerializer(), IpAddress.class)
256 .register(new Ip4AddressSerializer(), Ip4Address.class)
257 .register(new Ip6AddressSerializer(), Ip6Address.class)
258 .register(new MacAddressSerializer(), MacAddress.class)
259 .register(VlanId.class)
260 .register(Frequency.class)
261 .register(Bandwidth.class)
265 * Kryo registration Id for user custom registration.
267 public static final int BEGIN_USER_CUSTOM_ID = 300;
269 // TODO: Populate other classes
271 * KryoNamespace which can serialize API bundle classes.
273 public static final KryoNamespace API = KryoNamespace.newBuilder()
274 .nextId(KryoNamespace.INITIAL_ID)
276 .nextId(KryoNamespace.INITIAL_ID + 30)
278 .nextId(KryoNamespace.INITIAL_ID + 30 + 10)
280 Instructions.MeterInstruction.class,
283 ControllerNode.State.class,
284 ApplicationState.class,
285 ApplicationRole.class,
286 DefaultApplication.class,
290 DefaultControllerNode.class,
292 DefaultDeviceDescription.class,
294 DefaultLinkDescription.class,
296 DefaultPortDescription.class,
302 LeadershipEvent.class,
303 LeadershipEvent.Type.class,
305 HostDescription.class,
306 DefaultHostDescription.class,
307 DefaultFlowEntry.class,
308 StoredFlowEntry.class,
309 DefaultFlowRule.class,
310 DefaultFlowEntry.class,
311 DefaultPacketRequest.class,
312 PacketPriority.class,
313 FlowEntry.FlowEntryState.class,
315 DefaultTrafficSelector.class,
317 MetadataCriterion.class,
320 EthTypeCriterion.class,
321 VlanIdCriterion.class,
322 VlanPcpCriterion.class,
323 IPDscpCriterion.class,
324 IPEcnCriterion.class,
325 IPProtocolCriterion.class,
328 TcpPortCriterion.class,
329 UdpPortCriterion.class,
330 SctpPortCriterion.class,
331 IcmpTypeCriterion.class,
332 IcmpCodeCriterion.class,
333 IPv6FlowLabelCriterion.class,
334 Icmpv6TypeCriterion.class,
335 Icmpv6CodeCriterion.class,
336 IPv6NDTargetAddressCriterion.class,
337 IPv6NDLinkLayerAddressCriterion.class,
339 TunnelIdCriterion.class,
340 IPv6ExthdrFlagsCriterion.class,
341 LambdaCriterion.class,
342 IndexedLambdaCriterion.class,
343 OchSignalCriterion.class,
344 OchSignalTypeCriterion.class,
345 OduSignalIdCriterion.class,
346 OduSignalTypeCriterion.class,
348 Criterion.Type.class,
349 DefaultTrafficTreatment.class,
350 Instructions.DropInstruction.class,
351 Instructions.NoActionInstruction.class,
352 Instructions.OutputInstruction.class,
353 Instructions.GroupInstruction.class,
354 Instructions.TableTypeTransition.class,
355 L0ModificationInstruction.class,
356 L0ModificationInstruction.L0SubType.class,
357 L0ModificationInstruction.ModLambdaInstruction.class,
358 L0ModificationInstruction.ModOchSignalInstruction.class,
359 L1ModificationInstruction.class,
360 L1ModificationInstruction.L1SubType.class,
361 L1ModificationInstruction.ModOduSignalIdInstruction.class,
362 L2ModificationInstruction.class,
363 L2ModificationInstruction.L2SubType.class,
364 L2ModificationInstruction.ModEtherInstruction.class,
365 L2ModificationInstruction.PushHeaderInstructions.class,
366 L2ModificationInstruction.ModVlanIdInstruction.class,
367 L2ModificationInstruction.ModVlanPcpInstruction.class,
368 L2ModificationInstruction.PopVlanInstruction.class,
369 L2ModificationInstruction.ModMplsLabelInstruction.class,
370 L2ModificationInstruction.ModMplsTtlInstruction.class,
371 L2ModificationInstruction.ModTunnelIdInstruction.class,
372 L3ModificationInstruction.class,
373 L3ModificationInstruction.L3SubType.class,
374 L3ModificationInstruction.ModIPInstruction.class,
375 L3ModificationInstruction.ModIPv6FlowLabelInstruction.class,
376 L3ModificationInstruction.ModTtlInstruction.class,
377 L4ModificationInstruction.class,
378 L4ModificationInstruction.L4SubType.class,
379 L4ModificationInstruction.ModTransportPortInstruction.class,
381 FlowRuleBatchEvent.class,
382 FlowRuleBatchEvent.Type.class,
383 FlowRuleBatchRequest.class,
384 FlowRuleBatchOperation.class,
386 FlowRuleEvent.Type.class,
387 CompletedBatchOperation.class,
388 FlowRuleBatchEntry.class,
389 FlowRuleBatchEntry.FlowRuleOperation.class,
392 //Key.class, is abstract
393 Key.of(1L, new DefaultApplicationId(0, "bar")).getClass(), //LongKey.class
394 Key.of("foo", new DefaultApplicationId(0, "bar")).getClass(), //StringKey.class
396 ConnectivityIntent.class,
399 DefaultEdgeLink.class,
400 HostToHostIntent.class,
401 PointToPointIntent.class,
402 MultiPointToSinglePointIntent.class,
403 SinglePointToMultiPointIntent.class,
404 FlowRuleIntent.class,
405 LinkCollectionIntent.class,
406 OpticalConnectivityIntent.class,
407 OpticalPathIntent.class,
408 OpticalCircuitIntent.class,
409 LinkResourceRequest.class,
410 DefaultLinkResourceRequest.class,
411 BandwidthResourceRequest.class,
412 LambdaResourceRequest.class,
413 LambdaResource.class,
414 BandwidthResource.class,
415 DefaultLinkResourceAllocations.class,
416 BandwidthResourceAllocation.class,
417 LambdaResourceAllocation.class,
419 ResourceAllocation.class,
421 LambdaConstraint.class,
422 BandwidthConstraint.class,
423 LinkTypeConstraint.class,
424 LatencyConstraint.class,
425 WaypointConstraint.class,
426 ObstacleConstraint.class,
427 AnnotationConstraint.class,
428 BooleanConstraint.class,
429 PartialFailureConstraint.class,
430 IntentOperation.class,
431 FlowRuleExtPayLoad.class,
433 DefaultAnnotations.class,
434 PortStatistics.class,
435 DefaultPortStatistics.class,
436 IntentDomainId.class,
437 TableStatisticsEntry.class,
438 DefaultTableStatisticsEntry.class
440 .register(new DefaultApplicationIdSerializer(), DefaultApplicationId.class)
441 .register(new URISerializer(), URI.class)
442 .register(new NodeIdSerializer(), NodeId.class)
443 .register(new ProviderIdSerializer(), ProviderId.class)
444 .register(new DeviceIdSerializer(), DeviceId.class)
445 .register(new PortNumberSerializer(), PortNumber.class)
446 .register(new DefaultPortSerializer(), DefaultPort.class)
447 .register(new LinkKeySerializer(), LinkKey.class)
448 .register(new ConnectPointSerializer(), ConnectPoint.class)
449 .register(new DefaultLinkSerializer(), DefaultLink.class)
450 .register(new MastershipTermSerializer(), MastershipTerm.class)
451 .register(new HostLocationSerializer(), HostLocation.class)
452 .register(new DefaultOutboundPacketSerializer(), DefaultOutboundPacket.class)
453 .register(new AnnotationsSerializer(), DefaultAnnotations.class)
454 .register(new ExtensionInstructionSerializer(), Instructions.ExtensionInstructionWrapper.class)
455 .register(ExtensionType.class)
456 .register(Versioned.class)
457 .register(MapEvent.class)
458 .register(MapEvent.Type.class)
459 .register(SetEvent.class)
460 .register(SetEvent.Type.class)
461 .register(DefaultGroupId.class)
462 .register(Annotations.class)
463 .register(OmsPort.class)
464 .register(OchPort.class)
465 .register(OduSignalType.class)
466 .register(OchSignalType.class)
467 .register(GridType.class)
468 .register(ChannelSpacing.class)
469 .register(OduCltPort.class)
470 .register(OduCltPort.SignalType.class)
471 .register(IndexedLambda.class)
472 .register(OchSignal.class)
473 .register(OduSignalId.class)
474 .register(OduCltPortDescription.class)
475 .register(OchPortDescription.class)
476 .register(OmsPortDescription.class)
479 MplsPathIntent.class,
480 MplsLabelResourceAllocation.class,
481 MplsLabelResourceRequest.class,
483 org.onlab.packet.MplsLabel.class,
484 org.onlab.packet.MPLS.class
490 // not to be instantiated
491 private KryoNamespaces() {}