Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.util.serializers; |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 2 | |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 3 | import java.net.Inet4Address; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 4 | import java.net.InetAddress; |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 5 | import java.util.ArrayList; |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 6 | import java.util.Date; |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 7 | import java.util.HashMap; |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 8 | import java.util.HashSet; |
Yuta HIGUCHI | c25861a | 2014-06-17 23:17:09 -0700 | [diff] [blame] | 9 | import java.util.LinkedList; |
Yuta HIGUCHI | e57e10e | 2014-08-20 14:25:30 -0700 | [diff] [blame] | 10 | import java.util.List; |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 11 | import java.util.concurrent.ConcurrentHashMap; |
Yuta HIGUCHI | e57e10e | 2014-08-20 14:25:30 -0700 | [diff] [blame] | 12 | import java.util.concurrent.ConcurrentLinkedQueue; |
| 13 | |
| 14 | import javax.annotation.concurrent.ThreadSafe; |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 15 | |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 16 | import net.floodlightcontroller.core.IFloodlightProviderService.Role; |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 17 | import net.floodlightcontroller.util.MACAddress; |
Pavlin Radoslavov | dd08e8c | 2014-08-14 11:02:57 -0700 | [diff] [blame] | 18 | import net.onrc.onos.api.batchoperation.BatchOperationEntry; |
Toshio Koide | d6cbec3 | 2014-08-27 15:23:44 -0700 | [diff] [blame] | 19 | import net.onrc.onos.api.flowmanager.FlowBatchOperation; |
| 20 | import net.onrc.onos.api.flowmanager.FlowBatchState; |
Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 21 | import net.onrc.onos.api.flowmanager.FlowId; |
| 22 | import net.onrc.onos.api.flowmanager.FlowLink; |
Toshio Koide | b7a578c | 2014-08-22 18:00:54 -0700 | [diff] [blame] | 23 | import net.onrc.onos.api.flowmanager.FlowState; |
Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 24 | import net.onrc.onos.api.flowmanager.OpticalPathFlow; |
| 25 | import net.onrc.onos.api.flowmanager.PacketPathFlow; |
| 26 | import net.onrc.onos.api.flowmanager.SingleDstTreeFlow; |
| 27 | import net.onrc.onos.api.flowmanager.Tree; |
Sho SHIMIZU | 1674fb3 | 2014-08-20 14:44:31 -0700 | [diff] [blame] | 28 | import net.onrc.onos.api.newintent.AbstractIntent; |
| 29 | import net.onrc.onos.api.newintent.ConnectivityIntent; |
| 30 | import net.onrc.onos.api.newintent.IntentEvent; |
| 31 | import net.onrc.onos.api.newintent.IntentId; |
Sho SHIMIZU | 07ace75 | 2014-08-21 09:04:41 -0700 | [diff] [blame] | 32 | import net.onrc.onos.api.newintent.IntentState; |
Sho SHIMIZU | 1674fb3 | 2014-08-20 14:44:31 -0700 | [diff] [blame] | 33 | import net.onrc.onos.api.newintent.MultiPointToSinglePointIntent; |
| 34 | import net.onrc.onos.api.newintent.OpticalConnectivityIntent; |
| 35 | import net.onrc.onos.api.newintent.PacketConnectivityIntent; |
| 36 | import net.onrc.onos.api.newintent.PointToPointIntent; |
| 37 | import net.onrc.onos.api.newintent.SinglePointToMultiPointIntent; |
TeruU | 3c049c4 | 2014-04-15 10:13:25 -0700 | [diff] [blame] | 38 | import net.onrc.onos.apps.proxyarp.ArpCacheNotification; |
Jonathan Hart | 0961fe8 | 2014-04-03 09:56:25 -0700 | [diff] [blame] | 39 | import net.onrc.onos.apps.proxyarp.ArpReplyNotification; |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 40 | import net.onrc.onos.core.hostmanager.Host; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 41 | import net.onrc.onos.core.intent.ConstrainedShortestPathIntent; |
| 42 | import net.onrc.onos.core.intent.ErrorIntent; |
| 43 | import net.onrc.onos.core.intent.Intent; |
| 44 | import net.onrc.onos.core.intent.IntentOperation; |
| 45 | import net.onrc.onos.core.intent.IntentOperationList; |
Yuta HIGUCHI | 1fc395e | 2014-05-13 14:06:28 -0700 | [diff] [blame] | 46 | import net.onrc.onos.core.intent.Path; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 47 | import net.onrc.onos.core.intent.PathIntent; |
| 48 | import net.onrc.onos.core.intent.ShortestPathIntent; |
| 49 | import net.onrc.onos.core.intent.runtime.IntentStateList; |
Brian O'Connor | 0efc906 | 2014-09-02 14:47:28 -0700 | [diff] [blame] | 50 | import net.onrc.onos.core.matchaction.MatchAction; |
| 51 | import net.onrc.onos.core.matchaction.MatchActionId; |
| 52 | import net.onrc.onos.core.matchaction.MatchActionOperationEntry; |
| 53 | import net.onrc.onos.core.matchaction.MatchActionOperations; |
| 54 | import net.onrc.onos.core.matchaction.MatchActionOperationsId; |
| 55 | import net.onrc.onos.core.matchaction.MatchActionOperationsState; |
| 56 | import net.onrc.onos.core.matchaction.SwitchResult; |
| 57 | import net.onrc.onos.core.matchaction.SwitchResultList; |
Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 58 | import net.onrc.onos.core.matchaction.action.ModifyDstMacAction; |
| 59 | import net.onrc.onos.core.matchaction.action.ModifySrcMacAction; |
Brian O'Connor | ab3e9e6 | 2014-09-09 23:45:55 -0700 | [diff] [blame] | 60 | import net.onrc.onos.core.matchaction.action.NullAction; |
Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 61 | import net.onrc.onos.core.matchaction.action.OutputAction; |
| 62 | import net.onrc.onos.core.matchaction.match.PacketMatch; |
Sho SHIMIZU | 07ace75 | 2014-08-21 09:04:41 -0700 | [diff] [blame] | 63 | import net.onrc.onos.core.newintent.IntentCompilationResult; |
Sho SHIMIZU | 1674fb3 | 2014-08-20 14:44:31 -0700 | [diff] [blame] | 64 | import net.onrc.onos.core.newintent.PathFlowIntent; |
| 65 | import net.onrc.onos.core.newintent.SingleDstTreeFlowIntent; |
| 66 | import net.onrc.onos.core.newintent.SingleSrcTreeFlowIntent; |
Sho SHIMIZU | 95d53c8 | 2014-08-21 09:18:47 -0700 | [diff] [blame] | 67 | import net.onrc.onos.core.newintent.TestIntent; |
| 68 | import net.onrc.onos.core.newintent.TestSubclassIntent; |
Jonathan Hart | 313fdf0 | 2014-04-10 14:09:46 -0700 | [diff] [blame] | 69 | import net.onrc.onos.core.packetservice.BroadcastPacketOutNotification; |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 70 | import net.onrc.onos.core.packetservice.PacketOutNotification; |
Jonathan Hart | 313fdf0 | 2014-04-10 14:09:46 -0700 | [diff] [blame] | 71 | import net.onrc.onos.core.packetservice.SinglePacketOutNotification; |
Praseed Balakrishnan | 2aa6c0b | 2014-07-17 11:42:05 -0700 | [diff] [blame] | 72 | import net.onrc.onos.core.topology.AdminStatus; |
| 73 | import net.onrc.onos.core.topology.ConfigState; |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 74 | import net.onrc.onos.core.topology.HostData; |
| 75 | import net.onrc.onos.core.topology.LinkData; |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 76 | import net.onrc.onos.core.topology.MastershipData; |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 77 | import net.onrc.onos.core.topology.PortData; |
| 78 | import net.onrc.onos.core.topology.SwitchData; |
Pavlin Radoslavov | dd08e8c | 2014-08-14 11:02:57 -0700 | [diff] [blame] | 79 | import net.onrc.onos.core.topology.TopologyBatchOperation; |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 80 | import net.onrc.onos.core.topology.TopologyElement; |
Praseed Balakrishnan | 2aa6c0b | 2014-07-17 11:42:05 -0700 | [diff] [blame] | 81 | import net.onrc.onos.core.topology.TopologyEvent; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 82 | import net.onrc.onos.core.util.Dpid; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 83 | import net.onrc.onos.core.util.IPv4; |
| 84 | import net.onrc.onos.core.util.IPv4Net; |
| 85 | import net.onrc.onos.core.util.IPv6; |
| 86 | import net.onrc.onos.core.util.IPv6Net; |
Yuta HIGUCHI | 02ccb8c | 2014-07-10 11:29:45 -0700 | [diff] [blame] | 87 | import net.onrc.onos.core.util.LinkTuple; |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame] | 88 | import net.onrc.onos.core.util.OnosInstanceId; |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame] | 89 | import net.onrc.onos.core.util.PortNumber; |
Yuta HIGUCHI | 5c8cbeb | 2014-06-27 11:13:48 -0700 | [diff] [blame] | 90 | import net.onrc.onos.core.util.SwitchPort; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 91 | |
Yuta HIGUCHI | 2d5ac52 | 2014-01-22 10:21:41 -0800 | [diff] [blame] | 92 | import com.esotericsoftware.kryo.Kryo; |
Yuta HIGUCHI | e57e10e | 2014-08-20 14:25:30 -0700 | [diff] [blame] | 93 | import com.esotericsoftware.kryo.io.Input; |
| 94 | import com.esotericsoftware.kryo.io.Output; |
Pavlin Radoslavov | aaace7f | 2013-10-25 19:42:00 -0700 | [diff] [blame] | 95 | |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Class factory for allocating Kryo instances for |
| 98 | * serialization/deserialization of classes. |
| 99 | */ |
Yuta HIGUCHI | e57e10e | 2014-08-20 14:25:30 -0700 | [diff] [blame] | 100 | @ThreadSafe |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 101 | public class KryoFactory { |
Yuta HIGUCHI | e57e10e | 2014-08-20 14:25:30 -0700 | [diff] [blame] | 102 | |
Yuta HIGUCHI | 0af53d2 | 2014-03-31 14:01:35 -0700 | [diff] [blame] | 103 | private static final int DEFAULT_PREALLOCATIONS = 100; |
Yuta HIGUCHI | e57e10e | 2014-08-20 14:25:30 -0700 | [diff] [blame] | 104 | /** |
| 105 | * Default buffer size used for serialization. |
| 106 | * |
| 107 | * @see #serialize(Object) |
| 108 | */ |
| 109 | public static final int DEFAULT_BUFFER_SIZE = 1 * 1000 * 1000; |
| 110 | |
| 111 | private static final KryoFactory GLOBAL_POOL = new KryoFactory(); |
| 112 | |
| 113 | private ConcurrentLinkedQueue<Kryo> kryoList = new ConcurrentLinkedQueue<Kryo>(); |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * Default constructor. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 117 | * <p/> |
Yuta HIGUCHI | 0af53d2 | 2014-03-31 14:01:35 -0700 | [diff] [blame] | 118 | * Preallocates {@code DEFAULT_PREALLOCATIONS} Kryo instances. |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 119 | */ |
| 120 | public KryoFactory() { |
Yuta HIGUCHI | 0af53d2 | 2014-03-31 14:01:35 -0700 | [diff] [blame] | 121 | this(DEFAULT_PREALLOCATIONS); |
| 122 | } |
| 123 | |
| 124 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 125 | * Constructor to explicitly specify number of Kryo instances to pool. |
Yuta HIGUCHI | 0af53d2 | 2014-03-31 14:01:35 -0700 | [diff] [blame] | 126 | * |
| 127 | * @param initialCapacity number of Kryo instance to preallocate |
| 128 | */ |
| 129 | public KryoFactory(final int initialCapacity) { |
| 130 | // Preallocate |
Yuta HIGUCHI | 0af53d2 | 2014-03-31 14:01:35 -0700 | [diff] [blame] | 131 | for (int i = 0; i < initialCapacity; i++) { |
Pavlin Radoslavov | 9c7b14c | 2014-07-03 17:24:27 -0700 | [diff] [blame] | 132 | Kryo kryo = newKryoObject(); |
Yuta HIGUCHI | 0af53d2 | 2014-03-31 14:01:35 -0700 | [diff] [blame] | 133 | kryoList.add(kryo); |
| 134 | } |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /** |
Pavlin Radoslavov | 9c7b14c | 2014-07-03 17:24:27 -0700 | [diff] [blame] | 138 | * Gets a new Kryo object. |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 139 | * |
Pavlin Radoslavov | 9c7b14c | 2014-07-03 17:24:27 -0700 | [diff] [blame] | 140 | * @return the Kryo object. |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 141 | */ |
| 142 | public Kryo newKryo() { |
Yuta HIGUCHI | e57e10e | 2014-08-20 14:25:30 -0700 | [diff] [blame] | 143 | Kryo kryo = kryoList.poll(); |
| 144 | if (kryo == null) { |
| 145 | // Will defer additional allocation until deleteKryo(). |
| 146 | // It is more likely that it is no longer latency sensitive |
| 147 | // by the time caller is recycling Kryo instance. |
| 148 | return newKryoObject(); |
| 149 | } else { |
| 150 | return kryo; |
| 151 | } |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** |
Pavlin Radoslavov | 9c7b14c | 2014-07-03 17:24:27 -0700 | [diff] [blame] | 155 | * Deletes an existing Kryo object. |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 156 | * |
| 157 | * @param deleteKryo the object to delete. |
| 158 | */ |
Yuta HIGUCHI | e57e10e | 2014-08-20 14:25:30 -0700 | [diff] [blame] | 159 | public void deleteKryo(final Kryo deleteKryo) { |
| 160 | if (kryoList.isEmpty()) { |
| 161 | // buffer extra if kryo instance pool has exhausted. |
| 162 | List<Kryo> kryos = new ArrayList<>(DEFAULT_PREALLOCATIONS); |
| 163 | for (int i = 0; i < DEFAULT_PREALLOCATIONS; ++i) { |
| 164 | kryos.add(newKryoObject()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 165 | } |
Yuta HIGUCHI | e57e10e | 2014-08-20 14:25:30 -0700 | [diff] [blame] | 166 | kryoList.addAll(kryos); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 167 | } |
Yuta HIGUCHI | e57e10e | 2014-08-20 14:25:30 -0700 | [diff] [blame] | 168 | |
| 169 | // recycle |
| 170 | kryoList.add(deleteKryo); |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /** |
Pavlin Radoslavov | 9c7b14c | 2014-07-03 17:24:27 -0700 | [diff] [blame] | 174 | * Creates and initializes a new Kryo object. |
| 175 | *<p> |
| 176 | * NOTE: This operation can be slow and should be used only if the |
| 177 | * application needs a single Kryo instance (e.g., during startup). |
| 178 | * For faster allocation, the application should use #newKryo() |
| 179 | * and #deleteKryo() factory methods. |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 180 | * |
| 181 | * @return the created Kryo object. |
| 182 | */ |
Pavlin Radoslavov | 9c7b14c | 2014-07-03 17:24:27 -0700 | [diff] [blame] | 183 | public static Kryo newKryoObject() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 184 | Kryo kryo = new Kryo(); |
| 185 | kryo.setRegistrationRequired(true); |
| 186 | // |
| 187 | // WARNING: Order of register() calls affects serialized bytes. |
| 188 | // - Do no insert new entry in the middle, always add to the end. |
| 189 | // - Do not simply remove existing entry |
| 190 | // |
Yuta HIGUCHI | 0af53d2 | 2014-03-31 14:01:35 -0700 | [diff] [blame] | 191 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 192 | // kryo.setReferences(false); |
| 193 | // |
| 194 | kryo.register(ArrayList.class); |
Pavlin Radoslavov | aaace7f | 2013-10-25 19:42:00 -0700 | [diff] [blame] | 195 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 196 | // FlowPath and related classes |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 197 | kryo.register(Dpid.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 198 | kryo.register(IPv4.class); |
| 199 | kryo.register(IPv4Net.class); |
| 200 | kryo.register(IPv6.class); |
| 201 | kryo.register(IPv6Net.class); |
| 202 | kryo.register(byte[].class); |
| 203 | kryo.register(MACAddress.class); |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame] | 204 | kryo.register(PortNumber.class); |
Yuta HIGUCHI | 5c8cbeb | 2014-06-27 11:13:48 -0700 | [diff] [blame] | 205 | kryo.register(SwitchPort.class); |
Yuta HIGUCHI | 02ccb8c | 2014-07-10 11:29:45 -0700 | [diff] [blame] | 206 | kryo.register(LinkTuple.class); |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 207 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 208 | // New data model-related classes |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame] | 209 | kryo.register(AdminStatus.class); |
| 210 | kryo.register(ConcurrentHashMap.class); |
| 211 | kryo.register(ConfigState.class); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 212 | kryo.register(HostData.class); |
Yuta HIGUCHI | c25861a | 2014-06-17 23:17:09 -0700 | [diff] [blame] | 213 | kryo.register(LinkedList.class); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 214 | kryo.register(LinkData.class); |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 215 | kryo.register(MastershipData.class); |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame] | 216 | kryo.register(OnosInstanceId.class); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 217 | kryo.register(PortData.class); |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 218 | kryo.register(Role.class); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 219 | kryo.register(SwitchData.class); |
Pavlin Radoslavov | dd08e8c | 2014-08-14 11:02:57 -0700 | [diff] [blame] | 220 | kryo.register(TopologyBatchOperation.class); |
| 221 | kryo.register(TopologyBatchOperation.Operator.class); |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 222 | kryo.register(TopologyElement.class); |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame] | 223 | kryo.register(TopologyEvent.class); |
Pavlin Radoslavov | 31f8510 | 2014-08-15 13:55:44 -0700 | [diff] [blame] | 224 | kryo.register(TopologyEvent.Type.class); |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 225 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 226 | // Intent-related classes |
| 227 | kryo.register(Path.class); |
| 228 | kryo.register(Intent.class); |
| 229 | kryo.register(Intent.IntentState.class); |
| 230 | kryo.register(PathIntent.class); |
| 231 | kryo.register(ShortestPathIntent.class); |
| 232 | kryo.register(ConstrainedShortestPathIntent.class); |
| 233 | kryo.register(ErrorIntent.class); |
| 234 | kryo.register(ErrorIntent.ErrorType.class); |
| 235 | kryo.register(IntentOperation.class); |
| 236 | kryo.register(IntentOperation.Operator.class); |
| 237 | kryo.register(IntentOperationList.class); |
| 238 | kryo.register(IntentStateList.class); |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 239 | kryo.register(HashMap.class); |
Toshio Koide | eb90d91 | 2014-02-18 21:30:22 -0800 | [diff] [blame] | 240 | |
Pavlin Radoslavov | dd08e8c | 2014-08-14 11:02:57 -0700 | [diff] [blame] | 241 | // New intent-related classes |
| 242 | kryo.register(BatchOperationEntry.class); |
Sho SHIMIZU | 1674fb3 | 2014-08-20 14:44:31 -0700 | [diff] [blame] | 243 | kryo.register(IntentId.class); |
| 244 | kryo.register(IntentEvent.class); |
Sho SHIMIZU | 07ace75 | 2014-08-21 09:04:41 -0700 | [diff] [blame] | 245 | kryo.register(IntentState.class); |
| 246 | kryo.register(IntentCompilationResult.class); |
Sho SHIMIZU | 1674fb3 | 2014-08-20 14:44:31 -0700 | [diff] [blame] | 247 | kryo.register(AbstractIntent.class); |
| 248 | kryo.register(ConnectivityIntent.class); |
| 249 | kryo.register(PointToPointIntent.class); |
| 250 | kryo.register(MultiPointToSinglePointIntent.class); |
| 251 | kryo.register(SinglePointToMultiPointIntent.class); |
| 252 | kryo.register(net.onrc.onos.api.newintent.PathIntent.class); |
| 253 | kryo.register(PathFlowIntent.class); |
| 254 | kryo.register(SingleSrcTreeFlowIntent.class); |
| 255 | kryo.register(SingleDstTreeFlowIntent.class); |
| 256 | kryo.register(PacketConnectivityIntent.class); |
| 257 | kryo.register(OpticalConnectivityIntent.class); |
Sho SHIMIZU | 95d53c8 | 2014-08-21 09:18:47 -0700 | [diff] [blame] | 258 | // FIXME: due to lack of functionality to register a serializer |
| 259 | // in API user side, we added the following two classes. |
| 260 | // Theoretically the classes are only for test. we should create |
| 261 | // a way to register serializer without editing source code |
| 262 | kryo.register(TestIntent.class); |
| 263 | kryo.register(TestSubclassIntent.class); |
Pavlin Radoslavov | dd08e8c | 2014-08-14 11:02:57 -0700 | [diff] [blame] | 264 | |
Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 265 | // New flow manager related classes |
| 266 | kryo.register(FlowId.class); |
Toshio Koide | b7a578c | 2014-08-22 18:00:54 -0700 | [diff] [blame] | 267 | kryo.register(FlowState.class); |
Toshio Koide | d6cbec3 | 2014-08-27 15:23:44 -0700 | [diff] [blame] | 268 | kryo.register(FlowBatchOperation.class); |
| 269 | kryo.register(FlowBatchOperation.Operator.class); |
| 270 | kryo.register(FlowBatchState.class); |
Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 271 | kryo.register(net.onrc.onos.api.flowmanager.Path.class); |
| 272 | kryo.register(Tree.class); |
| 273 | kryo.register(FlowLink.class); |
| 274 | kryo.register(OpticalPathFlow.class); |
| 275 | kryo.register(PacketPathFlow.class); |
| 276 | kryo.register(SingleDstTreeFlow.class); |
| 277 | |
| 278 | // New match action related classes |
Brian O'Connor | 0efc906 | 2014-09-02 14:47:28 -0700 | [diff] [blame] | 279 | kryo.register(MatchAction.class); |
| 280 | kryo.register(MatchActionId.class); |
Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 281 | kryo.register(PacketMatch.class); |
| 282 | kryo.register(OutputAction.class); |
| 283 | kryo.register(ModifyDstMacAction.class); |
| 284 | kryo.register(ModifySrcMacAction.class); |
Brian O'Connor | 0efc906 | 2014-09-02 14:47:28 -0700 | [diff] [blame] | 285 | kryo.register(MatchActionOperations.class); |
| 286 | kryo.register(MatchActionOperations.Operator.class); |
| 287 | kryo.register(MatchActionOperationsId.class); |
| 288 | kryo.register(MatchActionOperationsState.class); |
| 289 | kryo.register(MatchActionOperationEntry.class); |
| 290 | kryo.register(SwitchResultList.class); |
| 291 | kryo.register(SwitchResult.class); |
| 292 | kryo.register(SwitchResult.Status.class); |
Brian O'Connor | ab3e9e6 | 2014-09-09 23:45:55 -0700 | [diff] [blame] | 293 | kryo.register(NullAction.class); |
Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 294 | |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 295 | // Host-related classes |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 296 | kryo.register(HashSet.class); |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 297 | kryo.register(Host.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 298 | kryo.register(Date.class); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 299 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 300 | // ProxyArp-related classes |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 301 | kryo.register(PacketOutNotification.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 302 | kryo.register(BroadcastPacketOutNotification.class); |
| 303 | kryo.register(SinglePacketOutNotification.class); |
| 304 | kryo.register(ArpReplyNotification.class); |
TeruU | 3c049c4 | 2014-04-15 10:13:25 -0700 | [diff] [blame] | 305 | kryo.register(ArpCacheNotification.class); |
Yuta HIGUCHI | c25861a | 2014-06-17 23:17:09 -0700 | [diff] [blame] | 306 | // TODO check if InetAddress related is still used |
| 307 | // TODO check if InetAddress can be correctly serialized |
| 308 | kryo.register(InetAddress.class); |
| 309 | kryo.register(Inet4Address.class); |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 310 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 311 | return kryo; |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 312 | } |
Yuta HIGUCHI | e57e10e | 2014-08-20 14:25:30 -0700 | [diff] [blame] | 313 | |
| 314 | /** |
| 315 | * Serializes given object to byte array using Kryo instance in global pool. |
| 316 | * <p> |
| 317 | * Note: Serialized bytes must be smaller than DEFAULT_BUFFER_SIZE (=1MB). |
| 318 | * |
| 319 | * @param obj Object to serialize (Class must be registered to KryoFactory) |
| 320 | * @return serialized bytes |
| 321 | */ |
| 322 | public static byte[] serialize(final Object obj) { |
| 323 | return serialize(obj, DEFAULT_BUFFER_SIZE); |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Serializes given object to byte array using Kryo instance in global pool. |
| 328 | * |
| 329 | * @param obj Object to serialize (Class must be registered to KryoFactory) |
| 330 | * @param bufferSize maximum size of serialized bytes |
| 331 | * @return serialized bytes |
| 332 | */ |
| 333 | public static byte[] serialize(final Object obj, final int bufferSize) { |
| 334 | Output out = new Output(bufferSize); |
| 335 | Kryo kryo = GLOBAL_POOL.newKryo(); |
| 336 | try { |
| 337 | kryo.writeClassAndObject(out, obj); |
| 338 | return out.toBytes(); |
| 339 | } finally { |
| 340 | GLOBAL_POOL.deleteKryo(kryo); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Deserializes given byte array to Object using Kryo instance in global pool. |
| 346 | * |
| 347 | * @param bytes serialized bytes |
| 348 | * @param <T> deserialized Object type |
| 349 | * @return deserialized Object (Class must be registered to KryoFactory) |
| 350 | */ |
| 351 | public static <T> T deserialize(final byte[] bytes) { |
| 352 | Input in = new Input(bytes); |
| 353 | Kryo kryo = GLOBAL_POOL.newKryo(); |
| 354 | try { |
| 355 | @SuppressWarnings("unchecked") |
| 356 | T obj = (T) kryo.readClassAndObject(in); |
| 357 | return obj; |
| 358 | } finally { |
| 359 | GLOBAL_POOL.deleteKryo(kryo); |
| 360 | } |
| 361 | } |
Pavlin Radoslavov | e0a643e | 2013-10-24 13:33:39 -0700 | [diff] [blame] | 362 | } |