From 0bb46aa8b419314aa147801c9f6141272b4f4b4d Mon Sep 17 00:00:00 2001
From: Oliver Herms <oliver.herms@exaring.de>
Date: Mon, 15 Oct 2018 17:24:11 +0200
Subject: [PATCH] Added extended IP reachability TLV

---
 .../packet/tlv_extended_ip_reachability.go    | 71 +++++++++++++++++--
 1 file changed, 66 insertions(+), 5 deletions(-)

diff --git a/protocols/isis/packet/tlv_extended_ip_reachability.go b/protocols/isis/packet/tlv_extended_ip_reachability.go
index 9fbbe5c0..b53fcff3 100644
--- a/protocols/isis/packet/tlv_extended_ip_reachability.go
+++ b/protocols/isis/packet/tlv_extended_ip_reachability.go
@@ -1,14 +1,75 @@
 package packet
 
+import (
+	"bytes"
+
+	"github.com/taktv6/tflow2/convert"
+)
+
+// ExtendedIPReachabilityTLVType is the type code of an Extended IP Reachability TLV
 const ExtendedIPReachabilityTLVType = 135
 
+// ExtendedIPReachabilityTLV represents an Extended IP Reachability TLV
 type ExtendedIPReachabilityTLV struct {
-	TLVType        uint8
-	TLVLength      uint8
+	TLVType                  uint8
+	TLVLength                uint8
+	ExtendedIPReachabilities []ExtendedIPReachability
+}
+
+// ExtendedIPReachability represents a single Extendend IP Reachability Information
+type ExtendedIPReachability struct {
 	Metric         uint32
 	UDSubBitPfxLen uint8
 	Address        uint32
-	SubTLVType     uint8
-	SubTLVLength   uint8
-	SubTLVs        []interface{}
+	SubTLVs        []TLV
+}
+
+// Type gets the type of the TLV
+func (e *ExtendedIPReachabilityTLV) Type() uint8 {
+	return e.TLVType
+}
+
+// Length gets the length of the TLV
+func (e *ExtendedIPReachabilityTLV) Length() uint8 {
+	return e.TLVLength
+}
+
+// Value returns the TLV itself
+func (e *ExtendedIPReachabilityTLV) Value() interface{} {
+	return e
+}
+
+// Serialize serializes an ExtendedIPReachabilityTLV
+func (e *ExtendedIPReachabilityTLV) Serialize(buf *bytes.Buffer) {
+	buf.WriteByte(ExtendedIPReachabilityTLVType)
+	buf.WriteByte(e.TLVLength)
+
+	for _, extIPReach := range e.ExtendedIPReachabilities {
+		extIPReach.Serialize(buf)
+	}
+}
+
+// Serialize serializes an ExtendedIPReachability
+func (e *ExtendedIPReachability) Serialize(buf *bytes.Buffer) {
+	if len(e.SubTLVs) != 0 {
+		e.setSFlag()
+	}
+	buf.Write(convert.Uint32Byte(e.Metric))
+	buf.WriteByte(e.UDSubBitPfxLen)
+	buf.Write(convert.Uint32Byte(e.Address))
+	for _, tlv := range e.SubTLVs {
+		tlv.Serialize(buf)
+	}
+}
+
+func (e *ExtendedIPReachability) setSFlag() {
+	sFlag := uint8(64)
+	e.UDSubBitPfxLen = e.UDSubBitPfxLen | sFlag
+}
+
+func (e *ExtendedIPReachability) getPfxLen() uint8 {
+	tmp := e.UDSubBitPfxLen
+	tmp = tmp << 2
+	tmp = tmp >> 2
+	return tmp
 }
-- 
GitLab