Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.datastore.topology; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 2 | |
| 3 | import java.nio.ByteBuffer; |
| 4 | import java.util.HashMap; |
| 5 | import java.util.Iterator; |
| 6 | import java.util.Map; |
| 7 | |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 8 | import net.onrc.onos.core.datastore.DataStoreClient; |
| 9 | import net.onrc.onos.core.datastore.IKVTable.IKVEntry; |
Yuta HIGUCHI | 1cd9029 | 2014-04-03 14:31:10 -0700 | [diff] [blame] | 10 | import net.onrc.onos.core.datastore.serializers.Topology.PortProperty; |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 11 | import net.onrc.onos.core.datastore.utils.ByteArrayUtil; |
| 12 | import net.onrc.onos.core.datastore.utils.KVObject; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 13 | import net.onrc.onos.core.topology.PortEvent; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 14 | |
| 15 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; |
| 17 | |
| 18 | import com.esotericsoftware.kryo.Kryo; |
| 19 | import com.google.protobuf.ByteString; |
| 20 | import com.google.protobuf.InvalidProtocolBufferException; |
| 21 | |
| 22 | /** |
| 23 | * Port object in data store. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 24 | * <p/> |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 25 | * Note: This class will not maintain invariants. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 26 | * e.g., It will NOT automatically remove Links or Devices on Port, |
| 27 | * when deleting a Port. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 28 | */ |
| 29 | public class KVPort extends KVObject { |
| 30 | private static final Logger log = LoggerFactory.getLogger(KVPort.class); |
| 31 | |
Ray Milkey | 5c9f2db | 2014-04-09 10:31:21 -0700 | [diff] [blame] | 32 | private static final ThreadLocal<Kryo> PORT_KRYO = new ThreadLocal<Kryo>() { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 33 | @Override |
| 34 | protected Kryo initialValue() { |
| 35 | Kryo kryo = new Kryo(); |
| 36 | kryo.setRegistrationRequired(true); |
| 37 | kryo.setReferences(false); |
| 38 | kryo.register(byte[].class); |
| 39 | kryo.register(byte[][].class); |
| 40 | kryo.register(HashMap.class); |
| 41 | // TODO check if we should explicitly specify EnumSerializer |
| 42 | kryo.register(STATUS.class); |
| 43 | return kryo; |
| 44 | } |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 47 | static final String PORT_TABLE_SUFFIX = ":Port"; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 48 | |
| 49 | // must not re-order enum members, ordinal will be sent over wire |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 50 | /** |
| 51 | * Status. |
| 52 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 53 | public enum STATUS { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 54 | INACTIVE, ACTIVE; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | private final Long dpid; |
| 58 | private final Long number; |
| 59 | |
| 60 | private STATUS status; |
| 61 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 62 | /** |
| 63 | * Generate a PortID from port pair (dpid, number). |
| 64 | * |
| 65 | * @param dpid DPID of a switch it reside on. |
| 66 | * @param number port number of this |
| 67 | * @return PortID |
| 68 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 69 | public static byte[] getPortID(final Long dpid, final Long number) { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 70 | return PortEvent.getPortID(dpid, number).array(); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 73 | /** |
| 74 | * Gets the port pair from PortID. |
| 75 | * |
| 76 | * @param key PortID |
| 77 | * @return port pair (dpid, number) |
| 78 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 79 | public static long[] getPortPairFromKey(final byte[] key) { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 80 | return getPortPairFromKey(ByteBuffer.wrap(key)); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 83 | /** |
| 84 | * Gets the port pair from PortID. |
| 85 | * |
| 86 | * @param keyBuf PortID |
| 87 | * @return port pair (dpid, number) |
| 88 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 89 | public static long[] getPortPairFromKey(final ByteBuffer keyBuf) { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 90 | if (keyBuf.getChar() != 'S') { |
| 91 | throw new IllegalArgumentException("Invalid Port key:" + keyBuf |
| 92 | + " " |
Yuta HIGUCHI | 805bc8f | 2014-04-16 11:51:43 -0700 | [diff] [blame] | 93 | + ByteArrayUtil.toHexStringBuilder(keyBuf.array(), ":")); |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 94 | } |
Yuta HIGUCHI | a14eb17 | 2014-03-24 15:03:23 -0700 | [diff] [blame] | 95 | long[] pair = new long[2]; |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 96 | pair[0] = keyBuf.getLong(); |
| 97 | if (keyBuf.getChar() != 'P') { |
| 98 | throw new IllegalArgumentException("Invalid Port key:" + keyBuf |
| 99 | + " " |
Yuta HIGUCHI | 805bc8f | 2014-04-16 11:51:43 -0700 | [diff] [blame] | 100 | + ByteArrayUtil.toHexStringBuilder(keyBuf.array(), ":")); |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 101 | } |
| 102 | pair[1] = keyBuf.getLong(); |
| 103 | return pair; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 104 | |
| 105 | } |
| 106 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 107 | /** |
| 108 | * Gets the port number from PortID. |
| 109 | * |
| 110 | * @param key PortID |
| 111 | * @return port number |
| 112 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 113 | public static long getDpidFromKey(final byte[] key) { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 114 | return getPortPairFromKey(key)[0]; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 117 | /** |
| 118 | * Gets the dpid of an switch from PortID. |
| 119 | * |
| 120 | * @param key PortID |
| 121 | * @return dpid |
| 122 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 123 | public static long getNumberFromKey(final byte[] key) { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 124 | return getPortPairFromKey(key)[1]; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 127 | /** |
| 128 | * KVPort constructor for default namespace. |
| 129 | * |
| 130 | * @param dpid DPID of the switch this port is on |
| 131 | * @param number port number of this port |
| 132 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 133 | public KVPort(final Long dpid, final Long number) { |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 134 | this(dpid, number, DEFAULT_NAMESPACE); |
| 135 | } |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 136 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 137 | /** |
| 138 | * KVPort constructor for specified namespace. |
| 139 | * |
| 140 | * @param dpid DPID of the switch this port is on |
| 141 | * @param number port number of this port |
| 142 | * @param namespace namespace to create this object |
| 143 | */ |
| 144 | public KVPort(final Long dpid, final Long number, final String namespace) { |
| 145 | super(DataStoreClient.getClient() |
| 146 | .getTable(namespace + PORT_TABLE_SUFFIX), |
| 147 | getPortID(dpid, number), namespace); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 148 | |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 149 | this.dpid = dpid; |
| 150 | this.number = number; |
| 151 | this.status = STATUS.INACTIVE; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 155 | * Gets an instance from PortID in default namespace. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 156 | * |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 157 | * @param key PortID |
| 158 | * @return {@link KVPort} instance |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 159 | * @note You need to call `read()` to get the DB content. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 160 | */ |
| 161 | public static KVPort createFromKey(final byte[] key) { |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 162 | return createFromKey(key, DEFAULT_NAMESPACE); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Gets an instance from PortID in specified namespace. |
| 167 | * |
| 168 | * @param key PortID |
| 169 | * @param namespace namespace to create this object. |
| 170 | * @return {@link KVPort} instance |
| 171 | * @note You need to call `read()` to get the DB content. |
| 172 | */ |
| 173 | public static KVPort createFromKey(final byte[] key, final String namespace) { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 174 | long[] pair = getPortPairFromKey(key); |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 175 | return new KVPort(pair[0], pair[1], namespace); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 178 | /** |
| 179 | * Gets all the Ports in default namespace. |
| 180 | * |
| 181 | * @return Ports |
| 182 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 183 | public static Iterable<KVPort> getAllPorts() { |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 184 | return getAllPorts(DEFAULT_NAMESPACE); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 187 | /** |
| 188 | * Gets all the Ports in specified namespace. |
| 189 | * |
| 190 | * @param namespace namespace to iterate over |
| 191 | * @return Ports |
| 192 | */ |
| 193 | public static Iterable<KVPort> getAllPorts(final String namespace) { |
| 194 | return new PortEnumerator(namespace); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Utility class to provide Iterable interface. |
| 199 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 200 | public static class PortEnumerator implements Iterable<KVPort> { |
| 201 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 202 | private final String namespace; |
| 203 | |
| 204 | /** |
| 205 | * Constructor to iterate Ports in specified namespace. |
| 206 | * |
| 207 | * @param namespace namespace to iterate through |
| 208 | */ |
| 209 | public PortEnumerator(final String namespace) { |
| 210 | this.namespace = namespace; |
| 211 | } |
| 212 | |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 213 | @Override |
| 214 | public Iterator<KVPort> iterator() { |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 215 | return new PortIterator(namespace); |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 216 | } |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 219 | /** |
| 220 | * Utility class to provide Iterator over all the Port objects. |
| 221 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 222 | public static class PortIterator extends AbstractObjectIterator<KVPort> { |
| 223 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 224 | /** |
| 225 | * Constructor to create an iterator to iterate all the Ports |
| 226 | * in specified namespace. |
| 227 | * |
| 228 | * @param namespace namespace to iterate through |
| 229 | */ |
| 230 | public PortIterator(final String namespace) { |
| 231 | super(DataStoreClient.getClient() |
| 232 | .getTable(namespace + PORT_TABLE_SUFFIX), namespace); |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 233 | } |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 234 | |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 235 | @Override |
| 236 | public KVPort next() { |
| 237 | IKVEntry o = enumerator.next(); |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 238 | KVPort e = KVPort.createFromKey(o.getKey(), namespace); |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 239 | e.deserialize(o.getValue(), o.getVersion()); |
| 240 | return e; |
| 241 | } |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 244 | /** |
| 245 | * Gets the status. |
| 246 | * |
| 247 | * @return status |
| 248 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 249 | public STATUS getStatus() { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 250 | return status; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 253 | /** |
| 254 | * Sets the status. |
| 255 | * |
| 256 | * @param status new status |
| 257 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 258 | public void setStatus(final STATUS status) { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 259 | this.status = status; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 262 | /** |
| 263 | * Gets the DPID of the switch this port is on. |
| 264 | * |
| 265 | * @return DPID of the switch this port is on |
| 266 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 267 | public Long getDpid() { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 268 | return dpid; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 271 | /** |
| 272 | * Gets the port number of this port. |
| 273 | * |
| 274 | * @return port number of this port |
| 275 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 276 | public Long getNumber() { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 277 | return number; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Yuta HIGUCHI | cc56188 | 2014-05-22 10:31:32 -0700 | [diff] [blame^] | 280 | /** |
| 281 | * Gets the PortID. |
| 282 | * |
| 283 | * @return PortID |
| 284 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 285 | public byte[] getId() { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 286 | return getKey(); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public byte[] serialize() { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 291 | Map<Object, Object> map = getPropertyMap(); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 292 | |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 293 | PortProperty.Builder port = PortProperty.newBuilder(); |
| 294 | port.setDpid(dpid); |
| 295 | port.setNumber(number); |
| 296 | port.setStatus(status.ordinal()); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 297 | |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 298 | if (!map.isEmpty()) { |
Ray Milkey | 5c9f2db | 2014-04-09 10:31:21 -0700 | [diff] [blame] | 299 | byte[] propMaps = serializePropertyMap(PORT_KRYO.get(), map); |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 300 | port.setValue(ByteString.copyFrom(propMaps)); |
| 301 | } |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 302 | |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 303 | return port.build().toByteArray(); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | @Override |
| 307 | protected boolean deserialize(final byte[] bytes) { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 308 | try { |
| 309 | boolean success = true; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 310 | |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 311 | PortProperty port = PortProperty.parseFrom(bytes); |
| 312 | byte[] props = port.getValue().toByteArray(); |
Ray Milkey | 5c9f2db | 2014-04-09 10:31:21 -0700 | [diff] [blame] | 313 | success &= deserializePropertyMap(PORT_KRYO.get(), props); |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 314 | this.status = STATUS.values()[port.getStatus()]; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 315 | |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 316 | return success; |
| 317 | } catch (InvalidProtocolBufferException e) { |
| 318 | log.error("Deserializing Port: " + this + " failed.", e); |
| 319 | return false; |
| 320 | } |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | @Override |
| 324 | public String toString() { |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 325 | // TODO output all properties? |
| 326 | return "[" + this.getClass().getSimpleName() |
| 327 | + " 0x" + Long.toHexString(dpid) + "@" + number |
| 328 | + " STATUS:" + status + "]"; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 329 | } |
| 330 | } |