move bmp to bmp aggregator
[bgpcep.git] / bmp / bmp-parser-impl / src / main / java / org / opendaylight / protocol / bmp / parser / tlv / StatType003TlvHandler.java
diff --git a/bmp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/tlv/StatType003TlvHandler.java b/bmp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/tlv/StatType003TlvHandler.java
new file mode 100644 (file)
index 0000000..76db17f
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bmp.parser.tlv;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
+import org.opendaylight.protocol.bmp.spi.parser.BmpTlvParser;
+import org.opendaylight.protocol.bmp.spi.parser.BmpTlvSerializer;
+import org.opendaylight.protocol.bmp.spi.parser.TlvUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.stat.tlvs.InvalidatedClusterListLoopTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.stat.tlvs.InvalidatedClusterListLoopTlvBuilder;
+
+public class StatType003TlvHandler implements BmpTlvParser, BmpTlvSerializer {
+
+    public static final int TYPE = 3;
+
+    @Override
+    public void serializeTlv(final Tlv tlv, final ByteBuf output) {
+        Preconditions.checkArgument(tlv instanceof InvalidatedClusterListLoopTlv, "InvalidatedClusterListLoopTlv is mandatory.");
+        TlvUtil.formatTlvCounter32(TYPE, ((InvalidatedClusterListLoopTlv) tlv).getCount(), output);
+    }
+
+    @Override
+    public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException {
+        if (buffer == null) {
+            return null;
+        }
+        return new InvalidatedClusterListLoopTlvBuilder().setCount(new Counter32(buffer.readUnsignedInt())).build();
+    }
+
+}