Revert "Enhance netvirt l2 HA tests"
[integration/test.git] / tools / fastbgp / play.py
index b191f73d1c9d58fb2840b271226529a2a0d5d59f..0a94983e147fbad9475a33979d7971dabd4b8103 100755 (executable)
@@ -153,10 +153,26 @@ def parse_arguments():
     str_help = "How many play utilities are to be started."
     parser.add_argument("--multiplicity", default="1", type=int, help=str_help)
     str_help = "Open message includes multiprotocol extension capability l2vpn-evpn.\
-Enabling this flag makes the script not decoding the update mesage, because of not\
-supported decoding for these elements."
+    Enabling this flag makes the script not decoding the update mesage, because of not\
+    supported decoding for these elements."
     parser.add_argument("--evpn", default=False, action="store_true", help=str_help)
+    str_help = "Open message includes Multicast in MPLS/BGP IP VPNs arguments.\
+    Enabling this flag makes the script not decoding the update mesage, because of not\
+    supported decoding for these elements."
+    parser.add_argument("--mvpn", default=False, action="store_true", help=str_help)
+    str_help = "Open message includes L3VPN-MULTICAST arguments.\
+    Enabling this flag makes the script not decoding the update mesage, because of not\
+    supported decoding for these elements."
+    parser.add_argument("--l3vpn_mcast", default=False, action="store_true", help=str_help)
+    str_help = "Open message includes L3VPN-UNICAST arguments, without message decoding."
+    parser.add_argument("--l3vpn", default=False, action="store_true", help=str_help)
+    str_help = "Open message includes ROUTE-TARGET-CONSTRAIN arguments, without message decoding."
+    parser.add_argument("--rt_constrain", default=False, action="store_true", help=str_help)
+    str_help = "Add all supported families without message decoding."
+    parser.add_argument("--allf", default=False, action="store_true", help=str_help)
     parser.add_argument("--wfr", default=10, type=int, help="Wait for read timeout")
+    str_help = "Skipping well known attributes for update message"
+    parser.add_argument("--skipattr", default=False, action="store_true", help=str_help)
     arguments = parser.parse_args()
     if arguments.multiplicity < 1:
         print "Multiplicity", arguments.multiplicity, "is not positive."
@@ -353,6 +369,12 @@ class MessageGenerator(object):
         self.rfc4760 = args.rfc4760
         self.bgpls = args.bgpls
         self.evpn = args.evpn
+        self.mvpn = args.mvpn
+        self.l3vpn_mcast = args.l3vpn_mcast
+        self.l3vpn = args.l3vpn
+        self.rt_constrain = args.rt_constrain
+        self.allf = args.allf
+        self.skipattr = args.skipattr
         # Default values when BGP-LS Attributes are used
         if self.bgpls:
             self.prefix_count_to_add_default = 1
@@ -373,7 +395,7 @@ class MessageGenerator(object):
                     self.prefix_count_to_add_default + 1)
         s2_slots = ((self.remaining_prefixes_threshold - 1) /
                     (self.prefix_count_to_add_default -
-                    self.prefix_count_to_del_default) + 1)
+                     self.prefix_count_to_del_default) + 1)
         # S1_First_Index = 0
         # S1_Last_Index = s1_slots * self.prefix_count_to_add_default - 1
         s2_first_index = s1_slots * self.prefix_count_to_add_default
@@ -782,7 +804,7 @@ class MessageGenerator(object):
 
         # Optional Parameters
         optional_parameters_hex = ""
-        if self.rfc4760:
+        if self.rfc4760 or self.allf:
             optional_parameter_hex = (
                 "\x02"  # Param type ("Capability Ad")
                 "\x06"  # Length (6 bytes)
@@ -795,7 +817,7 @@ class MessageGenerator(object):
             )
             optional_parameters_hex += optional_parameter_hex
 
-        if self.bgpls:
+        if self.bgpls or self.allf:
             optional_parameter_hex = (
                 "\x02"  # Param type ("Capability Ad")
                 "\x06"  # Length (6 bytes)
@@ -808,7 +830,7 @@ class MessageGenerator(object):
             )
             optional_parameters_hex += optional_parameter_hex
 
-        if self.evpn:
+        if self.evpn or self.allf:
             optional_parameter_hex = (
                 "\x02"  # Param type ("Capability Ad")
                 "\x06"  # Length (6 bytes)
@@ -820,6 +842,84 @@ class MessageGenerator(object):
             )
             optional_parameters_hex += optional_parameter_hex
 
+        if self.mvpn or self.allf:
+            optional_parameter_hex = (
+                "\x02"  # Param type ("Capability Ad")
+                "\x06"  # Length (6 bytes)
+                "\x01"  # Multiprotocol extetension capability,
+                "\x04"  # Capability value length
+                "\x00\x01"  # AFI (IPV4)
+                "\x00"  # (reserved)
+                "\x05"  # SAFI (MCAST-VPN)
+            )
+            optional_parameters_hex += optional_parameter_hex
+            optional_parameter_hex = (
+                "\x02"  # Param type ("Capability Ad")
+                "\x06"  # Length (6 bytes)
+                "\x01"  # Multiprotocol extetension capability,
+                "\x04"  # Capability value length
+                "\x00\x02"  # AFI (IPV6)
+                "\x00"  # (reserved)
+                "\x05"  # SAFI (MCAST-VPN)
+            )
+            optional_parameters_hex += optional_parameter_hex
+
+        if self.l3vpn_mcast or self.allf:
+            optional_parameter_hex = (
+                "\x02"  # Param type ("Capability Ad")
+                "\x06"  # Length (6 bytes)
+                "\x01"  # Multiprotocol extetension capability,
+                "\x04"  # Capability value length
+                "\x00\x01"  # AFI (IPV4)
+                "\x00"  # (reserved)
+                "\x81"  # SAFI (L3VPN-MCAST)
+            )
+            optional_parameters_hex += optional_parameter_hex
+            optional_parameter_hex = (
+                "\x02"  # Param type ("Capability Ad")
+                "\x06"  # Length (6 bytes)
+                "\x01"  # Multiprotocol extetension capability,
+                "\x04"  # Capability value length
+                "\x00\x02"  # AFI (IPV6)
+                "\x00"  # (reserved)
+                "\x81"  # SAFI (L3VPN-MCAST)
+            )
+            optional_parameters_hex += optional_parameter_hex
+
+        if self.l3vpn or self.allf:
+            optional_parameter_hex = (
+                "\x02"  # Param type ("Capability Ad")
+                "\x06"  # Length (6 bytes)
+                "\x01"  # Multiprotocol extetension capability,
+                "\x04"  # Capability value length
+                "\x00\x01"  # AFI (IPV4)
+                "\x00"  # (reserved)
+                "\x80"  # SAFI (L3VPN-UNICAST)
+            )
+            optional_parameters_hex += optional_parameter_hex
+            optional_parameter_hex = (
+                "\x02"  # Param type ("Capability Ad")
+                "\x06"  # Length (6 bytes)
+                "\x01"  # Multiprotocol extetension capability,
+                "\x04"  # Capability value length
+                "\x00\x02"  # AFI (IPV6)
+                "\x00"  # (reserved)
+                "\x80"  # SAFI (L3VPN-UNICAST)
+            )
+            optional_parameters_hex += optional_parameter_hex
+
+        if self.rt_constrain or self.allf:
+            optional_parameter_hex = (
+                "\x02"  # Param type ("Capability Ad")
+                "\x06"  # Length (6 bytes)
+                "\x01"  # Multiprotocol extetension capability,
+                "\x04"  # Capability value length
+                "\x00\x01"  # AFI (IPV4)
+                "\x00"  # (reserved)
+                "\x84"  # SAFI (ROUTE-TARGET-CONSTRAIN)
+            )
+            optional_parameters_hex += optional_parameter_hex
+
         optional_parameter_hex = (
             "\x02"  # Param type ("Capability Ad")
             "\x06"  # Length (6 bytes)
@@ -950,7 +1050,7 @@ class MessageGenerator(object):
         # TODO: to replace hardcoded string by encoding?
         # Path Attributes
         path_attributes_hex = ""
-        if nlri_prefixes != []:
+        if not self.skipattr:
             path_attributes_hex += (
                 "\x40"  # Flags ("Well-Known")
                 "\x01"  # Type (ORIGIN)
@@ -966,6 +1066,13 @@ class MessageGenerator(object):
             )
             my_as_hex = struct.pack(">I", my_autonomous_system)
             path_attributes_hex += my_as_hex  # AS segment (4 bytes)
+            path_attributes_hex += (
+                "\x40"  # Flags ("Well-Known")
+                "\x05"  # Type (LOCAL_PREF)
+                "\x04"  # Length (4)
+                "\x00\x00\x00\x64"  # (100)
+            )
+        if nlri_prefixes != []:
             path_attributes_hex += (
                 "\x40"  # Flags ("Well-Known")
                 "\x03"  # Type (NEXT_HOP)
@@ -975,12 +1082,6 @@ class MessageGenerator(object):
             path_attributes_hex += (
                 next_hop_hex  # IP address of the next hop (4 bytes)
             )
-            path_attributes_hex += (
-                "\x40"  # Flags ("Well-Known")
-                "\x05"  # Type (LOCAL_PREF)
-                "\x04"  # Length (4)
-                "\x00\x00\x00\x64"  # (100)
-            )
             if originator_id is not None:
                 path_attributes_hex += (
                     "\x80"  # Flags ("Optional, non-transitive")
@@ -991,7 +1092,7 @@ class MessageGenerator(object):
             if cluster_list_item is not None:
                 path_attributes_hex += (
                     "\x80"  # Flags ("Optional, non-transitive")
-                    "\x09"  # Type (CLUSTER_LIST)
+                    "\x0a"  # Type (CLUSTER_LIST)
                     "\x04"  # Length (4)
                 )           # one CLUSTER_LIST item (4 bytes)
                 path_attributes_hex += struct.pack(">I", int(cluster_list_item))
@@ -1274,7 +1375,9 @@ class ReadTracker(object):
     for idle waiting.
     """
 
-    def __init__(self, bgp_socket, timer, storage, evpn=False, wait_for_read=10):
+    def __init__(self, bgp_socket, timer, storage, evpn=False, mvpn=False,
+                 l3vpn_mcast=False, allf=False, l3vpn=False, rt_constrain=False,
+                 wait_for_read=10):
         """The reader initialisation.
 
         Arguments:
@@ -1282,6 +1385,11 @@ class ReadTracker(object):
             timer: timer to be used for scheduling
             storage: thread safe dict
             evpn: flag that evpn functionality is tested
+            mvpn: flag that mvpn functionality is tested
+            l3vpn_mcast: flag that l3vpn_mcast functionality is tested
+            l3vpn: flag that l3vpn unicast functionality is tested
+            rt_constrain: flag that rt-constrain functionality is tested
+            allf: flag for all family testing.
         """
         # References to outside objects.
         self.socket = bgp_socket
@@ -1304,6 +1412,11 @@ class ReadTracker(object):
         self.rx_activity_detected = True
         self.storage = storage
         self.evpn = evpn
+        self.mvpn = mvpn
+        self.l3vpn_mcast = l3vpn_mcast
+        self.l3vpn = l3vpn
+        self.rt_constrain = rt_constrain
+        self.allf = allf
         self.wfr = wait_for_read
 
     def read_message_chunk(self):
@@ -1512,6 +1625,31 @@ class ReadTracker(object):
             logger.debug("Skipping update decoding due to evpn data expected")
             return
 
+        logger.debug("Mvpn {}".format(self.mvpn))
+        if self.mvpn:
+            logger.debug("Skipping update decoding due to mvpn data expected")
+            return
+
+        logger.debug("L3vpn-mcast {}".format(self.l3vpn_mcast))
+        if self.l3vpn_mcast:
+            logger.debug("Skipping update decoding due to l3vpn_mcast data expected")
+            return
+
+        logger.debug("L3vpn-unicast {}".format(self.l3vpn))
+        if self.l3vpn_mcast:
+            logger.debug("Skipping update decoding due to l3vpn-unicast data expected")
+            return
+
+        logger.debug("Route-Target-Constrain {}".format(self.l3vpn_mcast))
+        if self.l3vpn_mcast:
+            logger.debug("Skipping update decoding due to Route-Target-Constrain data expected")
+            return
+
+        logger.debug("Allf {}".format(self.allf))
+        if self.allf:
+            logger.debug("Skipping update decoding")
+            return
+
         if msg_type == 2:
             logger.debug("Message type: 0x%s (update)",
                          binascii.b2a_hex(msg_type_hex))
@@ -1676,7 +1814,9 @@ class StateTracker(object):
         self.generator = generator
         self.timer = timer
         # Sub-trackers.
-        self.reader = ReadTracker(bgp_socket, timer, storage, evpn=cliargs.evpn, wait_for_read=cliargs.wfr)
+        self.reader = ReadTracker(bgp_socket, timer, storage, evpn=cliargs.evpn, mvpn=cliargs.mvpn,
+                                  l3vpn_mcast=cliargs.l3vpn_mcast, l3vpn=cliargs.l3vpn, allf=cliargs.allf,
+                                  rt_constrain=cliargs.rt_constrain, wait_for_read=cliargs.wfr)
         self.writer = WriteTracker(bgp_socket, generator, timer)
         # Prioritization state.
         self.prioritize_writing = False
@@ -1850,6 +1990,7 @@ def job(arguments, inqueue, storage):
 
 class Rpcs:
     '''Handler for SimpleXMLRPCServer'''
+
     def __init__(self, sendqueue, storage):
         '''Init method