2 * Copyright 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.
17 package org.onosproject.store.serializers;
19 import com.esotericsoftware.kryo.Kryo;
20 import com.esotericsoftware.kryo.Serializer;
21 import com.esotericsoftware.kryo.io.Input;
22 import com.esotericsoftware.kryo.io.Output;
23 import org.onlab.osgi.DefaultServiceDirectory;
24 import org.onosproject.net.DeviceId;
25 import org.onosproject.net.behaviour.ExtensionResolver;
26 import org.onosproject.net.driver.DefaultDriverData;
27 import org.onosproject.net.driver.DefaultDriverHandler;
28 import org.onosproject.net.driver.DriverHandler;
29 import org.onosproject.net.driver.DriverService;
30 import org.onosproject.net.flow.instructions.ExtensionInstruction;
31 import org.onosproject.net.flow.instructions.ExtensionType;
32 import org.onosproject.net.flow.instructions.Instructions;
35 * Created by jono on 10/29/15.
37 public class ExtensionInstructionSerializer extends
38 Serializer<Instructions.ExtensionInstructionWrapper> {
40 public ExtensionInstructionSerializer() {
45 public void write(Kryo kryo, Output output, Instructions.ExtensionInstructionWrapper object) {
46 kryo.writeClassAndObject(output, object.extensionInstruction().type());
47 kryo.writeClassAndObject(output, object.deviceId());
49 kryo.writeClassAndObject(output, object.extensionInstruction().serialize());
54 public Instructions.ExtensionInstructionWrapper read(Kryo kryo, Input input,
55 Class<Instructions.ExtensionInstructionWrapper> type) {
56 ExtensionType exType = (ExtensionType) kryo.readClassAndObject(input);
57 DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input);
59 DriverService driverService = DefaultServiceDirectory.getService(DriverService.class);
60 DriverHandler handler = new DefaultDriverHandler(
61 new DefaultDriverData(driverService.getDriver(deviceId), deviceId));
63 ExtensionResolver resolver = handler.behaviour(ExtensionResolver.class);
65 ExtensionInstruction instruction = resolver.getExtensionInstruction(exType);
67 byte[] bytes = (byte[]) kryo.readClassAndObject(input);
69 instruction.deserialize(bytes);
71 return Instructions.extension(instruction, deviceId);