blob: b36595d46a0a300ddd3a8237cabd8e7b4b64e928 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.serializers;
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -070017
18import java.net.URI;
Sho SHIMIZU977cb602014-11-13 08:40:50 -080019import java.time.Duration;
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -070020import java.util.ArrayList;
Madan Jampani53e44e62014-10-07 12:39:51 -070021import java.util.Arrays;
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080022import java.util.Collections;
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -070023import java.util.HashMap;
alshabib3d643ec2014-10-22 18:33:00 -070024import java.util.HashSet;
Yuta HIGUCHI9def0472014-10-23 15:51:10 -070025import java.util.LinkedList;
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -070026
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.cluster.ControllerNode;
28import org.onosproject.cluster.DefaultControllerNode;
29import org.onosproject.cluster.Leadership;
30import org.onosproject.cluster.LeadershipEvent;
31import org.onosproject.cluster.NodeId;
32import org.onosproject.cluster.RoleInfo;
33import org.onosproject.core.DefaultApplicationId;
34import org.onosproject.core.DefaultGroupId;
35import org.onosproject.mastership.MastershipTerm;
36import org.onosproject.net.ConnectPoint;
37import org.onosproject.net.DefaultAnnotations;
38import org.onosproject.net.DefaultDevice;
39import org.onosproject.net.DefaultEdgeLink;
40import org.onosproject.net.DefaultLink;
41import org.onosproject.net.DefaultPath;
42import org.onosproject.net.DefaultPort;
43import org.onosproject.net.Device;
44import org.onosproject.net.DeviceId;
45import org.onosproject.net.Element;
46import org.onosproject.net.HostId;
47import org.onosproject.net.HostLocation;
48import org.onosproject.net.Link;
49import org.onosproject.net.LinkKey;
50import org.onosproject.net.Port;
51import org.onosproject.net.PortNumber;
52import org.onosproject.net.device.DefaultDeviceDescription;
53import org.onosproject.net.device.DefaultPortDescription;
54import org.onosproject.net.flow.CompletedBatchOperation;
55import org.onosproject.net.flow.DefaultFlowEntry;
56import org.onosproject.net.flow.DefaultFlowRule;
57import org.onosproject.net.flow.DefaultTrafficSelector;
58import org.onosproject.net.flow.DefaultTrafficTreatment;
59import org.onosproject.net.flow.FlowEntry;
60import org.onosproject.net.flow.FlowId;
61import org.onosproject.net.flow.FlowRuleBatchEntry;
62import org.onosproject.net.flow.FlowRuleBatchOperation;
63import org.onosproject.net.flow.StoredFlowEntry;
64import org.onosproject.net.flow.criteria.Criteria;
65import org.onosproject.net.flow.criteria.Criterion;
66import org.onosproject.net.flow.instructions.Instructions;
67import org.onosproject.net.flow.instructions.L0ModificationInstruction;
68import org.onosproject.net.flow.instructions.L2ModificationInstruction;
69import org.onosproject.net.flow.instructions.L3ModificationInstruction;
70import org.onosproject.net.host.DefaultHostDescription;
71import org.onosproject.net.host.HostDescription;
72import org.onosproject.net.intent.ConnectivityIntent;
73import org.onosproject.net.intent.HostToHostIntent;
74import org.onosproject.net.intent.Intent;
75import org.onosproject.net.intent.IntentId;
76import org.onosproject.net.intent.IntentOperation;
77import org.onosproject.net.intent.IntentOperations;
78import org.onosproject.net.intent.IntentState;
79import org.onosproject.net.intent.LinkCollectionIntent;
80import org.onosproject.net.intent.MultiPointToSinglePointIntent;
81import org.onosproject.net.intent.OpticalConnectivityIntent;
82import org.onosproject.net.intent.OpticalPathIntent;
83import org.onosproject.net.intent.PathIntent;
84import org.onosproject.net.intent.PointToPointIntent;
85import org.onosproject.net.intent.constraint.AnnotationConstraint;
86import org.onosproject.net.intent.SinglePointToMultiPointIntent;
87import org.onosproject.net.intent.constraint.BandwidthConstraint;
88import org.onosproject.net.intent.constraint.BooleanConstraint;
89import org.onosproject.net.intent.constraint.LambdaConstraint;
90import org.onosproject.net.intent.constraint.LatencyConstraint;
91import org.onosproject.net.intent.constraint.LinkTypeConstraint;
92import org.onosproject.net.intent.constraint.ObstacleConstraint;
93import org.onosproject.net.intent.constraint.WaypointConstraint;
94import org.onosproject.net.link.DefaultLinkDescription;
95import org.onosproject.net.packet.DefaultOutboundPacket;
96import org.onosproject.net.provider.ProviderId;
97import org.onosproject.net.resource.Bandwidth;
98import org.onosproject.net.resource.BandwidthResourceAllocation;
99import org.onosproject.net.resource.BandwidthResourceRequest;
100import org.onosproject.net.resource.DefaultLinkResourceAllocations;
101import org.onosproject.net.resource.DefaultLinkResourceRequest;
102import org.onosproject.net.resource.Lambda;
103import org.onosproject.net.resource.LambdaResourceAllocation;
104import org.onosproject.net.resource.LambdaResourceRequest;
105import org.onosproject.net.resource.LinkResourceRequest;
106import org.onosproject.store.Timestamp;
107import org.onosproject.store.service.BatchReadRequest;
108import org.onosproject.store.service.BatchWriteRequest;
109import org.onosproject.store.service.ReadRequest;
110import org.onosproject.store.service.ReadResult;
111import org.onosproject.store.service.ReadStatus;
112import org.onosproject.store.service.VersionedValue;
113import org.onosproject.store.service.WriteRequest;
114import org.onosproject.store.service.WriteResult;
115import org.onosproject.store.service.WriteStatus;
alshabib7911a052014-10-16 17:49:37 -0700116import org.onlab.packet.ChassisId;
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700117import org.onlab.packet.IpAddress;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800118import org.onlab.packet.Ip4Address;
119import org.onlab.packet.Ip6Address;
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700120import org.onlab.packet.IpPrefix;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800121import org.onlab.packet.Ip4Prefix;
122import org.onlab.packet.Ip6Prefix;
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -0700123import org.onlab.packet.MacAddress;
124import org.onlab.packet.VlanId;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700125import org.onlab.util.KryoNamespace;
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700126
Yuta HIGUCHI47c40882014-10-10 18:44:37 -0700127import com.google.common.collect.ImmutableList;
128import com.google.common.collect.ImmutableMap;
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -0700129import com.google.common.collect.ImmutableSet;
Yuta HIGUCHI47c40882014-10-10 18:44:37 -0700130
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700131public final class KryoNamespaces {
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700132
Yuta HIGUCHI1aa249c2014-11-05 17:40:28 -0800133 public static final KryoNamespace BASIC = KryoNamespace.newBuilder()
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800134 .nextId(KryoNamespace.FLOATING_ID)
135 .register(byte[].class)
136 .register(new ImmutableListSerializer(),
137 ImmutableList.class,
138 ImmutableList.of(1).getClass(),
139 ImmutableList.of(1, 2).getClass())
140 .register(new ImmutableSetSerializer(),
141 ImmutableSet.class,
142 ImmutableSet.of().getClass(),
143 ImmutableSet.of(1).getClass(),
144 ImmutableSet.of(1, 2).getClass())
145 .register(new ImmutableMapSerializer(),
146 ImmutableMap.class,
147 ImmutableMap.of().getClass(),
148 ImmutableMap.of("a", 1).getClass(),
149 ImmutableMap.of("R", 2, "D", 2).getClass())
150 .register(HashMap.class)
151 .register(ArrayList.class,
152 LinkedList.class,
153 HashSet.class
154 )
155 .register(new ArraysAsListSerializer(), Arrays.asList().getClass())
156 .register(Collections.singletonList(1).getClass())
157 .register(Duration.class)
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -0800158 .register(Collections.emptySet().getClass())
Yuta HIGUCHI1aa249c2014-11-05 17:40:28 -0800159 .build();
160
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700161 /**
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700162 * KryoNamespace which can serialize ON.lab misc classes.
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700163 */
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700164 public static final KryoNamespace MISC = KryoNamespace.newBuilder()
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800165 .nextId(KryoNamespace.FLOATING_ID)
166 .register(new IpPrefixSerializer(), IpPrefix.class)
167 .register(new Ip4PrefixSerializer(), Ip4Prefix.class)
168 .register(new Ip6PrefixSerializer(), Ip6Prefix.class)
169 .register(new IpAddressSerializer(), IpAddress.class)
170 .register(new Ip4AddressSerializer(), Ip4Address.class)
171 .register(new Ip6AddressSerializer(), Ip6Address.class)
172 .register(new MacAddressSerializer(), MacAddress.class)
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -0700173 .register(VlanId.class)
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700174 .build();
175
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800176 /**
177 * Kryo registration Id for user custom registration.
178 */
179 public static final int BEGIN_USER_CUSTOM_ID = 300;
180
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700181 // TODO: Populate other classes
182 /**
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700183 * KryoNamespace which can serialize API bundle classes.
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700184 */
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700185 public static final KryoNamespace API = KryoNamespace.newBuilder()
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800186 .nextId(KryoNamespace.INITIAL_ID)
Yuta HIGUCHI1aa249c2014-11-05 17:40:28 -0800187 .register(BASIC)
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800188 .nextId(KryoNamespace.INITIAL_ID + 30)
189 .register(MISC)
190 .nextId(KryoNamespace.INITIAL_ID + 30 + 10)
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700191 .register(
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700192 ControllerNode.State.class,
193 Device.Type.class,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700194 Port.Type.class,
alshabib7911a052014-10-16 17:49:37 -0700195 ChassisId.class,
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700196 DefaultAnnotations.class,
197 DefaultControllerNode.class,
198 DefaultDevice.class,
Madan Jampani53e44e62014-10-07 12:39:51 -0700199 DefaultDeviceDescription.class,
Madan Jampani2ff05592014-10-10 15:42:47 -0700200 DefaultLinkDescription.class,
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700201 Port.class,
Madan Jampani53e44e62014-10-07 12:39:51 -0700202 DefaultPortDescription.class,
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700203 Element.class,
Yuta HIGUCHI9ee60f62014-10-09 10:00:01 -0700204 Link.Type.class,
Thomas Vachuska57126fe2014-11-11 17:13:24 -0800205 Link.State.class,
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -0700206 Timestamp.class,
Madan Jampani1ee91782014-11-20 20:24:24 -0800207 Leadership.class,
208 LeadershipEvent.class,
209 LeadershipEvent.Type.class,
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -0700210 HostId.class,
211 HostDescription.class,
Madan Jampani38b250d2014-10-17 11:02:38 -0700212 DefaultHostDescription.class,
Madan Jampani117aaae2014-10-23 10:04:05 -0700213 DefaultFlowEntry.class,
214 StoredFlowEntry.class,
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700215 DefaultFlowRule.class,
alshabib3d643ec2014-10-22 18:33:00 -0700216 DefaultFlowEntry.class,
alshabibf6c2ede2014-10-22 23:31:50 -0700217 FlowEntry.FlowEntryState.class,
Yuta HIGUCHI2809bf32014-10-20 22:44:12 -0700218 FlowId.class,
Yuta HIGUCHI85d58d12014-10-20 23:59:44 -0700219 DefaultTrafficSelector.class,
220 Criteria.PortCriterion.class,
221 Criteria.EthCriterion.class,
222 Criteria.EthTypeCriterion.class,
223 Criteria.IPCriterion.class,
224 Criteria.IPProtocolCriterion.class,
225 Criteria.VlanIdCriterion.class,
226 Criteria.VlanPcpCriterion.class,
227 Criteria.TcpPortCriterion.class,
Praseed Balakrishnandb8a9d22014-12-03 11:47:55 -0800228 Criteria.OpticalSignalTypeCriterion.class,
229 Criteria.LambdaCriterion.class,
230 Criteria.MplsCriterion.class,
Yuta HIGUCHI85d58d12014-10-20 23:59:44 -0700231 Criterion.class,
232 Criterion.Type.class,
233 DefaultTrafficTreatment.class,
234 Instructions.DropInstruction.class,
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700235 Instructions.OutputInstruction.class,
Jonathan Hart68fef9d2014-10-29 17:30:03 -0700236 L0ModificationInstruction.class,
237 L0ModificationInstruction.L0SubType.class,
238 L0ModificationInstruction.ModLambdaInstruction.class,
239 L2ModificationInstruction.class,
240 L2ModificationInstruction.L2SubType.class,
241 L2ModificationInstruction.ModEtherInstruction.class,
242 L2ModificationInstruction.ModVlanIdInstruction.class,
243 L2ModificationInstruction.ModVlanPcpInstruction.class,
244 L3ModificationInstruction.class,
245 L3ModificationInstruction.L3SubType.class,
246 L3ModificationInstruction.ModIPInstruction.class,
Yuta HIGUCHI9def0472014-10-23 15:51:10 -0700247 RoleInfo.class,
248 FlowRuleBatchOperation.class,
249 CompletedBatchOperation.class,
250 FlowRuleBatchEntry.class,
Yuta HIGUCHI087019b2014-10-28 21:07:56 -0700251 FlowRuleBatchEntry.FlowRuleOperation.class,
252 IntentId.class,
253 IntentState.class,
254 Intent.class,
255 ConnectivityIntent.class,
256 PathIntent.class,
257 DefaultPath.class,
258 DefaultEdgeLink.class,
259 HostToHostIntent.class,
260 PointToPointIntent.class,
Jonathan Hart68fef9d2014-10-29 17:30:03 -0700261 MultiPointToSinglePointIntent.class,
Michele Santuari4a338072014-11-05 18:38:55 +0100262 SinglePointToMultiPointIntent.class,
Brian O'Connor41718fc2014-10-30 16:57:21 -0700263 LinkCollectionIntent.class,
264 OpticalConnectivityIntent.class,
265 OpticalPathIntent.class,
Thomas Vachuska7d0032b2014-11-04 17:39:57 -0800266 LinkResourceRequest.class,
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800267 DefaultLinkResourceRequest.class,
268 BandwidthResourceRequest.class,
269 LambdaResourceRequest.class,
Thomas Vachuska7d0032b2014-11-04 17:39:57 -0800270 Lambda.class,
271 Bandwidth.class,
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800272 DefaultLinkResourceAllocations.class,
273 BandwidthResourceAllocation.class,
274 LambdaResourceAllocation.class,
Sho SHIMIZUcd4bac82014-11-11 17:07:25 -0800275 // Constraints
Thomas Vachuska7d0032b2014-11-04 17:39:57 -0800276 LambdaConstraint.class,
277 BandwidthConstraint.class,
278 LinkTypeConstraint.class,
Sho SHIMIZUcd4bac82014-11-11 17:07:25 -0800279 LatencyConstraint.class,
280 WaypointConstraint.class,
281 ObstacleConstraint.class,
282 AnnotationConstraint.class,
Brian O'Connor72a034c2014-11-26 18:24:23 -0800283 BooleanConstraint.class,
284 IntentOperation.class,
285 IntentOperations.class
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700286 )
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800287 .register(new DefaultApplicationIdSerializer(), DefaultApplicationId.class)
288 .register(new URISerializer(), URI.class)
289 .register(new NodeIdSerializer(), NodeId.class)
290 .register(new ProviderIdSerializer(), ProviderId.class)
291 .register(new DeviceIdSerializer(), DeviceId.class)
292 .register(new PortNumberSerializer(), PortNumber.class)
293 .register(new DefaultPortSerializer(), DefaultPort.class)
294 .register(new LinkKeySerializer(), LinkKey.class)
295 .register(new ConnectPointSerializer(), ConnectPoint.class)
296 .register(new DefaultLinkSerializer(), DefaultLink.class)
297 .register(new MastershipTermSerializer(), MastershipTerm.class)
298 .register(new HostLocationSerializer(), HostLocation.class)
299 .register(new DefaultOutboundPacketSerializer(), DefaultOutboundPacket.class)
300 .register(ReadRequest.class)
301 .register(WriteRequest.class)
302 .register(WriteRequest.Type.class)
303 .register(WriteResult.class)
304 .register(ReadResult.class)
305 .register(BatchReadRequest.class)
306 .register(BatchWriteRequest.class)
307 .register(ReadStatus.class)
308 .register(WriteStatus.class)
309 .register(VersionedValue.class)
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800310 .register(DefaultGroupId.class)
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700311
312 .build();
313
314
315 // not to be instantiated
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700316 private KryoNamespaces() {}
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -0700317}