Sfoglia il codice sorgente

Added encode_char_ip_ip6 function and two more TLVs.

AdrianSimionov 10 anni fa
parent
commit
efd23afdd1

+ 1 - 1
src/docsis_common.h

@@ -31,7 +31,7 @@
 
 
 #ifndef NUM_IDENTIFIERS
-#define NUM_IDENTIFIERS 389
+#define NUM_IDENTIFIERS 391
 #endif /*  NUM_IDENTIFIERS, needed in docsis_symtable.h  */
 
 #define MAXINT 2000000000

+ 15 - 0
src/docsis_decode.c

@@ -124,6 +124,21 @@ void decode_ip_ip6 (unsigned char *tlvbuf, symbol_type *sym, size_t length )
   }
 }
 
+void decode_char_ip_ip6 (unsigned char *tlvbuf, symbol_type *sym, size_t length )
+{
+  static char ip6_addr[INET6_ADDRSTRLEN];
+  char ipstr[INET6_ADDRSTRLEN];
+  static struct in_addr ip_addr;
+  if (length == 5 ) {
+    memcpy (&ip_addr, tlvbuf + 1, 4);
+    printf("%s %s;\n", sym->sym_ident, inet_ntoa(ip_addr) );
+  }
+  if (length == 17 ) {
+      memcpy (&ip6_addr, tlvbuf + 1, INET6_ADDRSTRLEN);
+      printf("%s %s;\n", sym->sym_ident, inet_ntop(AF_INET6,ip6_addr,ipstr,sizeof ipstr) );
+  }
+}
+
 void decode_ip_ip6_port (unsigned char *tlvbuf, symbol_type *sym, size_t length )
 {
   static char ip6_addr[INET6_ADDRSTRLEN];

+ 1 - 0
src/docsis_decode.h

@@ -35,6 +35,7 @@ void decode_uchar (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ip (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ip6 (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ip_ip6 (unsigned char *tlvbuf, symbol_type *sym, size_t length );
+void decode_char_ip_ip6 (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ip_ip6_port (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_lenzero (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ether (unsigned char *tlvbuf, symbol_type *sym, size_t length );

+ 27 - 0
src/docsis_encode.c

@@ -213,6 +213,33 @@ int encode_ip_ip6( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr
   }
 }
 
+int encode_char_ip_ip6( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
+{
+  struct in6_addr in6;
+  struct in_addr in;
+  union t_val *helper; /* We only use this to cast the void* we receive to what we think it should be */
+  
+  char ipv4 = 1;
+  char ipv6 = 2;
+
+  helper = (union t_val *) tval;
+
+  if ( inet_pton(AF_INET6, helper->strval, &in6) ) {
+    memcpy ( buf, &ipv6, sizeof(char) );
+    memcpy ( buf + 1, &in6, sizeof(struct in6_addr));
+    free(helper->strval);
+    return ( sizeof(char) + sizeof(struct in6_addr));
+  } else if ( inet_aton ( helper->strval, &in) ) {
+    memcpy ( buf, &ipv4, sizeof(char) );
+    memcpy ( buf + 1, &in, sizeof(struct in_addr));
+    free(helper->strval);
+    return ( sizeof(char) + sizeof(struct in_addr));    
+  } else {
+    fprintf(stderr, "Invalid IP address %s at line %d\n", helper->strval, line );
+    exit (-1);
+  }
+}
+
 int encode_lenzero( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
 {
   return (0);

+ 1 - 0
src/docsis_encode.h

@@ -31,6 +31,7 @@ int encode_uchar  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr
 int encode_ip     	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ip6     	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ip_ip6  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
+int encode_char_ip_ip6  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_lenzero  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ether	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_dual_qtag	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );

+ 2 - 4
src/docsis_symtable.h

@@ -217,12 +217,10 @@ symbol_type symtable[NUM_IDENTIFIERS] =  {
 { 357,    "ServiceMultiplexingValueIEEE8021ad", 3,     350,    (encode_hexstr),         (decode_hexstr),         4,           4             }, /* TLV 22.43.5.2.3 L2VPN-I13 Annex B.3.2 */
 { 358,    "ServiceMultiplexingValueMPLSPW",    4,      350,    (encode_nothing),        (decode_aggregate),      0,           0             }, /* TLV 22.43.5.2.4 L2VPN-I13 Annex B.3.2 */
 { 359,    "MPLSPseudowireID",                  1,      358,    (encode_uint),           (decode_uint),           0,           0             }, /* TLV 22.43.5.2.4.1 L2VPN-I13 Annex B.3.2 */
-/* We need a new encode/decode function for TLV 22.43.5.2.4.2 */
-/* { 360,    "MPLSPeerIpAddress",                 2,      358,    (encode_ip_ip6),         (decode_ip_ip6),         0,           0             }, */ /* TLV 22.43.5.2.4.2 L2VPN-I13 Annex B.3.2 */
+{ 360,    "MPLSPeerIpAddress",                 2,      358,    (encode_char_ip_ip6),    (decode_char_ip_ip6),    0,           0             }, /* TLV 22.43.5.2.4.2 L2VPN-I13 Annex B.3.2 */
 { 361,    "MPLSPseudowireType",                3,      358,    (encode_uchar),          (decode_uchar),          0,           0             }, /* TLV 22.43.5.2.4.3 L2VPN-I13 Annex B.3.2 */
 { 362,    "MPLSBackupPseudowireID",            4,      358,    (encode_uint),           (decode_uint),           0,           0             }, /* TLV 22.43.5.2.4.4 L2VPN-I13 Annex B.3.2 */
-/* We need a new encode/decode function for TLV 22.43.5.2.4.5 */
-/* { 363,    "MPLSBackupPeerIpAddress",           5,      358,    (encode_ip_ip6),         (decode_ip_ip6),         0,           0             }, */ /* TLV 22.43.5.2.4.5 L2VPN-I13 Annex B.3.2 */
+{ 363,    "MPLSBackupPeerIpAddress",           5,      358,    (encode_char_ip_ip6),    (decode_char_ip_ip6),    0,           0             }, /* TLV 22.43.5.2.4.5 L2VPN-I13 Annex B.3.2 */
 { 364,    "IEEE8021ahEncapsulation",           6,      350,    (encode_nothing),        (decode_aggregate),      0,           0             }, /* TLV 22.43.5.2.6 L2VPN-I13 Annex B.3.2.2 */
 { 365,    "ITCIEncapsulation",                 1,      364,    (encode_hexstr),         (decode_hexstr),         4,           4             }, /* TLV 22.43.5.2.6.1 L2VPN-I13 Annex B.3.2.2.1 */
 { 366,    "BDAEncapsulation",                  2,      364,    (encode_hexstr),         (decode_hexstr),         6,           6             }, /* TLV 22.43.5.2.6.2 L2VPN-I13 Annex B.3.2.2.2 */

BIN
tests/TLV_22_43_5_2_4_2_MPLSPeerIpAddress.cm


+ 41 - 0
tests/TLV_22_43_5_2_4_2_MPLSPeerIpAddress.conf

@@ -0,0 +1,41 @@
+Main 
+{
+	NetworkAccess 1;
+	UsServiceFlow
+	{
+		UsServiceFlowRef 1;
+		QosParamSetType 7;
+	}
+	DsServiceFlow
+	{
+		DsServiceFlowRef 2;
+		QosParamSetType 7;
+	}
+	UsPacketClass
+	{
+		VendorSpecific
+		{
+			VendorIdentifier 0xffffff;
+			L2VPNEncoding
+			{
+				NSIEncapsulationSubtype
+				{
+					ServiceMultiplexingValueMPLSPW
+					{
+						MPLSPseudowireID 1;
+						MPLSPeerIpAddress 1.1.1.1;
+						MPLSPseudowireType 5;
+						MPLSBackupPseudowireID 1;
+						MPLSBackupPeerIpAddress 2002::2:1;
+					}
+				}
+			}
+		}
+		ClassifierRef 1;
+		ServiceFlowRef 1;
+	}
+	/* CmMic d4a9a5ceac27b51bd47ed7443008ec7c; */
+	/* CmtsMic bb367e7c388dbe1e3e261d015d3dac9c; */
+	/*EndOfDataMkr*/
+	/* Pad */
+}

+ 37 - 0
tests/TLV_22_43_5_2_4_2_MPLSPeerIpAddress.txt

@@ -0,0 +1,37 @@
+Main 
+{
+NetworkAccess 1;
+UsServiceFlow
+{
+UsServiceFlowRef 1;
+QosParamSetType 7;
+}
+DsServiceFlow
+{
+DsServiceFlowRef 2;
+QosParamSetType 7;
+}
+UsPacketClass
+{
+VendorSpecific
+{
+VendorIdentifier 0xffffff;
+L2VPNEncoding
+{
+NSIEncapsulationSubtype
+{
+ServiceMultiplexingValueMPLSPW
+{
+MPLSPseudowireID 1;
+MPLSPeerIpAddress 1.1.1.1;
+MPLSPseudowireType 5;
+MPLSBackupPseudowireID 1;
+MPLSBackupPeerIpAddress 2002::2:1;
+}
+}
+}
+}
+ClassifierRef 1;
+ServiceFlowRef 1;
+}
+}