No relevant resource is found in the selected language.

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Read our privacy policy>Search

Reminder

To have a better experience, please upgrade your IE browser.

upgrade

CLI-based Configuration Guide - Reliability

AR100-S, AR110-S, AR120-S, AR150-S, AR160-S, AR200-S, AR1200-S, AR2200-S, and AR3200-S V200R009

Rate and give feedback:
Huawei uses machine translation combined with human proofreading to translate this document to different languages in order to help you better understand the content of this document. Note: Even the most advanced machine translation cannot match the quality of professional translators. Huawei shall not bear any responsibility for translation accuracy and it is recommended that you refer to the English document (a link for which has been provided).
Using Python Scripts to Implement Interworking When VRRP Nodes Fail

Using Python Scripts to Implement Interworking When VRRP Nodes Fail

Networking Requirements

In Figure 7-22, cameras on a LAN are connected to RouterC, RouterD, and RouterE and communicate with NEs through the VRRP group. RouterA and RouterB constitute a VRRP group and RouterA is the master. Normally, RouterA functions as the gateway, and user-side traffic is forwarded along the path RouterD -> RouterE -> RouterC -> RouterA -> NE1 -> NE2.

When the link from RouterC to RouterE and the link between RouterA and RouterB fail or the link quality is low, the VRRP group is required to detect the link fault and switch services to RouterB so that the NE can communicate with cameras.

Figure 7-22  Using Python scripts to implement interworking when VRRP nodes fail

Configuration Roadmap

The configuration roadmap is as follows:
  1. Assign an IP address to each interface and configure a routing protocol to ensure network connectivity.
  2. Make Python scripts Master.py and Backup.py to monitor changes of important routes and rectify faults in the scripts.

  3. Upload Master.py to RouterA and Backup.py to RouterB.

  4. Configure a Python script assistant and register the subscription event in the Python script to enable the Python script to run automatically.

Procedure

  1. Connect devices.

    # Configure an IP address for each interface. RouterA is used as an example. The configuration of RouterB is similar to the configuration of RouterA, and is not mentioned here. For details, see configuration files.

    <Huawei> system-view
    [Huawei] sysname RouterA
    [RouterA] vlan 2002
    [RouterA-vlan2002] port gigabitethernet 0/0/0 to 0/0/1
    [RouterA-vlan2002] quit
    [RouterA] interface vlanif 2002
    [RouterA-vlanif2002] ip address 2.2.2.2 24
    [RouterA-vlanif2002] quit
    [RouterA] interface gigabitethernet 0/0/0
    [RouterA-GigabitEthernet0/0/0] vrrp vrid 1 virtual-ip 2.2.2.1
    [RouterA-GigabitEthernet0/0/0] vrrp vrid 1 priority 150
    [RouterA-GigabitEthernet0/0/0] quit
    

    # Configure OSPF between RouterA and RouterB. The configuration of RouterB is similar to the configuration of RouterA, and is not mentioned here. For details, see the configuration files.

    [RouterA] ospf 1
    [RouterA-ospf-1] area 0
    [RouterA-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255
    [RouterA-ospf-1-area-0.0.0.0] network 192.168.1.0 0.0.0.255
    [RouterA-ospf-1-area-0.0.0.0] quit
    [RouterA-ospf-1] quit

    # Configure the ports of RouterC, RouterD and RouterE, and add them to VLAN2002. The configuration of RouterD and RouterE is similar to the configuration of RouterC, and is not mentioned here. For details, see the configuration files.

    <Huawei> system-view
    [Huawei] sysname RouterC
    [RouterC] vlan 2002
    [RouterC-vlan2002] port gigabitethernet 0/0/0 to 0/0/2
    [RouterC-vlan2002] quit

  2. Make Python scripts.

    # Make Python scripts Master.py and Backup.py to implement the following functions. For details on how to make a Python script, see Making a Python Script.
    • Master.py is used to monitor the interface status of RouterA and rectify faults on the interface of RouterA.

    • Backup.py is used to monitor the interface status of RouterB and rectify faults on the interface of RouterB.

  3. Upload and install the Python scripts.

    # Upload Python scripts of the PC to routers. That is, upload Master.py to RouterA and Backup.py to RouterB.

    # Install the Python script Master.py on RouterA.

    <routerA> ops install file Master.py

    # Install the Python script Backup.py on RouterB.

    <routerB> ops install file Backup.py

  4. Configure an assistant.

    # Configure an assistant and register the command line event in the script Master.py to wait for the event to be triggered.

    <Huawei> system-view
    [Huawei] sysname RouterA
    [RouterA] ops
    [RouterA-ops] script-assistant python Master.py
    [RouterA-ops] quit
    [RouterA] quit

    # Configure an assistant and register the command line event in the script Backup.py to wait for the event to be triggered.

    <Huawei> system-view
    [Huawei] sysname RouterB
    [RouterB] ops
    [RouterB-ops] script-assistant python Backup.py
    [RouterB-ops] quit
    [RouterB] quit

  5. Verify the configuration.

    # Simulate a circuit fault and verify the configuration.

    When GE0/0/0 on RouterA goes Down, the link fails and NEs cannot communicate with cameras. The script is triggered to restore the link so that NEs can communicate with cameras.

Configuration Files and Scripts

  • RouterA configuration file

    #
    sysname RouterA
    #
    vlan 2002
     port gigabitethernet 0/0/0 to 0/0/1
    #
    interface Vlanif2002
     ip address 2.2.2.2 255.255.255.0
     vrrp vrid 1 virtual-ip 2.2.2.1
     vrrp vrid 1 priority 150
    #
    ospf 1
     area 0.0.0.0
      network 2.2.2.0 0.0.0.255
      network 10.12.5.0 0.0.0.255
    #
    return
  • RouterB configuration file

    #
    sysname RouterB
    #
    vlan 2002
     port gigabitethernet 0/0/0 to 0/0/1
    #
    interface Vlanif2002
     ip address 2.2.2.3 255.255.255.0
     vrrp vrid 1 virtual-ip 2.2.2.1
    #
    ospf 1
     area 0.0.0.0
      network 2.2.2.0 0.0.0.255
      network 10.12.6.0 0.0.0.255
    #
    return
  • RouterC configuration file

    #
    sysname RouterC
    #
    vlan 2002
     port gigabitethernet 0/0/0 to 0/0/2
    #
    return
  • RouterD configuration file

    #
    sysname RouterD
    #
    vlan 2002
     port gigabitethernet 0/0/0 to 0/0/2
    #
    return
  • RouterE configuration file

    #
    sysname RouterE
    #
    vlan 2002
     port gigabitethernet 0/0/0 to 0/0/2
    #
    return
  • Master.py

    import ops
    import sys
    import re
    
    def ops_condition (o):
        print("It enters ops_condition")
        #configure eth condition to execute the ops script;
        status, err_str = o.interface.ifstat_subscribe("interface1", 1, "GigabitEthernet0/0/0", 2)
        return status
    
    def ops_execute (o):
    	handle, err_desp = o.cli.open()
    	print("OPS opens the process of command:",err_desp)	
    	result, n11, n21 = o.cli.execute(handle,"return")
    	result, n11, n21 = o.cli.execute(handle,"display interface brief | include GigabitEthernet0/0/0")##Check the physical state 
    	p1 = re.compile("GigabitEthernet\S*\s*\S*(down|up)\s*\S*\s*")
    	physical_state = p1.findall(result)
    	physical = physical_state[0]	
    	if physical == "down":
    	 	status, err_str = o.timedelay(15)
    		print("Begin to reset arp")
    		result, n11, n21 = o.cli.execute(handle,"return")
    		result, n11, n21 = o.cli.execute(handle,"reset arp interface Vlanif 2002")
    		status, err_str = o.timedelay(30)
    		print("the result of reset arp is:",result )
    	
    		print("Begin to analysis ARP IP Address")
    		p1 = re.compile(r"((25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d))")  
    		result, n11, n21 = o.cli.execute(handle,"dis arp interface GigabitEthernet 0/0/1")
    		arp_ip = p1.findall(result)
    		print arp_ip
    		
    		print("Begin to configure IP Address")
    		flag = 0
    		result, n11, n21 = o.cli.execute(handle,"dis arp interface GigabitEthernet 0/0/1")
    		p2 = re.compile("Total:(\d)")
    		total_arp = p2.findall(result)			
    		while flag < int(total_arp[0]) :
    			result, n11, n21 = o.cli.execute(handle,"return")
    			result, n11, n21 = o.cli.execute(handle,"system-view")
    			cmd_arp_ip = "ip route-static %s 32 Vlanif 2002 %s tag 2002" %(arp_ip[flag][0], arp_ip[flag][0])
    			result, n11, n21 = o.cli.execute(handle,command = cmd_arp_ip)
    			result, n11, n21 = o.cli.execute(handle,"ospf 1")
    			result, n11, n21 = o.cli.execute(handle,"import-route static tag 2002")
    			result, n11, n21 = o.cli.execute(handle,"return")
    			flag = flag + 1
    		print("Configured IP Address successfully")
    		result = o.cli.close(handle)
    		return 0
    	else :
    	 	status, err_str = o.timedelay(15)
    		print("Recoverying: Begin to recover ospf")
    		result, n11, n21 = o.cli.execute(handle,"return")
    		result, n11, n21 = o.cli.execute(handle,"system-view")
    		result, n11, n21 = o.cli.execute(handle,"ospf 1")
    		result, n11, n21 = o.cli.execute(handle,"undo import-route static")
    		
    		print("Recoverying: Begin to analysis ARP IP Address")
    		result, n11, n21 = o.cli.execute(handle,"return")
    		result, n11, n21 = o.cli.execute(handle,"dis arp interface GigabitEthernet 0/0/1")
    		p1 = re.compile(r"((25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d))")  
    		arp_ip = p1.findall(result)
    		print arp_ip
    		
    		print("Recoverying: Begin to recover IP Address")
    		flag = 0	
    		result, n11, n21 = o.cli.execute(handle,"dis arp interface GigabitEthernet 0/0/1")
    		p2 = re.compile("Total:(\d)")
    		total_arp = p2.findall(result)
    		while flag <  int(total_arp[0]) :
    			result, n11, n21 = o.cli.execute(handle,"return")
    			result, n11, n21 = o.cli.execute(handle,"system-view")
    			cmd_arp_ip = "undo ip route-static %s 32 Vlanif 2002 %s tag 2002" %(arp_ip[flag][0], arp_ip[flag][0])
    			result, n11, n21 = o.cli.execute(handle,command = cmd_arp_ip)
    			flag = flag + 1
    		print("Recoverying: Recovered IP Address successfully")
    		result = o.cli.close(handle)
    		return 0
  • Backup.py

    import ops
    import sys
    import re
    
    def ops_condition (o):
        print("It enters ops_condition")
        #configure eth condition to execute the ops script;
        status, err_str = o.interface.ifstat_subscribe("interface1", 1, "GigabitEthernet0/0/0", 2)
        return status
    
    def ops_execute (o):
    	handle, err_desp = o.cli.open()
    	print("OPS opens the process of command:",err_desp)	
    	result, n11, n21 = o.cli.execute(handle,"return")
    	result, n11, n21 = o.cli.execute(handle,"display interface brief | include GigabitEthernet0/0/0")##Check the physical state 
    	p1 = re.compile("GigabitEthernet\S*\s*\S*(down|up)\s*\S*\s*")
    	physical_state = p1.findall(result)
    	physical = physical_state[0]	
    	if physical == "down":
    		status, err_str = o.timedelay(15)
    		result, n11, n21 = o.cli.execute(handle,"return")
    		result, n11, n21 = o.cli.execute(handle,"dis vrrp interface vlanif 2002")
    		p1 = re.compile("State : (Master|Backup)")
    		vrrp_state = p1.findall(result)
    		vrrp = vrrp_state[0]
    		print("vrrp state should be Master, the real state is :", vrrp)
    		if vrrp == "Master":
    			print("Begin to reset arp")
    			result, n11, n21 = o.cli.execute(handle,"return")
    			result, n11, n21 = o.cli.execute(handle,"reset arp interface Vlanif 2002")
    			status, err_str = o.timedelay(30)
    			print("the result of reset arp is:",result )
    		
    			print("Begin to analysis ARP IP Address")
    			p1 = re.compile(r"((25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d))")  
    			result, n11, n21 = o.cli.execute(handle,"dis arp interface GigabitEthernet 0/0/1")
    			arp_ip = p1.findall(result)
    			print arp_ip
    			
    			print("Begin to configure IP Address")
    			flag = 0
    			result, n11, n21 = o.cli.execute(handle,"dis arp interface GigabitEthernet 0/0/1")
    			p2 = re.compile("Total:(\d)")
    			total_arp = p2.findall(result)			
    			while flag < int(total_arp[0]) :
    				result, n11, n21 = o.cli.execute(handle,"return")
    				result, n11, n21 = o.cli.execute(handle,"system-view")
    				cmd_arp_ip = "ip route-static %s 32 Vlanif 2002 %s tag 2002" %(arp_ip[flag][0], arp_ip[flag][0])
    				result, n11, n21 = o.cli.execute(handle,command = cmd_arp_ip)
    				result, n11, n21 = o.cli.execute(handle,"ospf 1")
    				result, n11, n21 = o.cli.execute(handle,"import-route static tag 2002")
    				result, n11, n21 = o.cli.execute(handle,"return")
    				flag = flag + 1
    			print("Configured IP Address successfully")
    		result = o.cli.close(handle)
    		return 0
    	else :
    		status, err_str = o.timedelay(15)
    		result, n11, n21 = o.cli.execute(handle,"return")
    		result, n11, n21 = o.cli.execute(handle,"dis vrrp interface vlanif 2002")
    		p1 = re.compile("State : (Master|Backup)")
    		vrrp_state = p1.findall(result)
    		vrrp = vrrp_state[0]
    		print("vrrp state should be Backup, the real state is :", vrrp)
    		if vrrp == "Backup":
    			print("Recoverying: Begin to recover ospf")
    			result, n11, n21 = o.cli.execute(handle,"return")
    			result, n11, n21 = o.cli.execute(handle,"system-view")
    			result, n11, n21 = o.cli.execute(handle,"ospf 1")
    			result, n11, n21 = o.cli.execute(handle,"undo import-route static")
    			
    			print("Recoverying: Begin to analysis ARP IP Address")
    			result, n11, n21 = o.cli.execute(handle,"return")
    			result, n11, n21 = o.cli.execute(handle,"dis arp interface GigabitEthernet 0/0/1")
    			p1 = re.compile(r"((25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d))")  
    			arp_ip = p1.findall(result)
    			print arp_ip
    			
    			print("Recoverying: Begin to recover IP Address")
    			flag = 0	
    			result, n11, n21 = o.cli.execute(handle,"dis arp interface GigabitEthernet 0/0/1")
    			p2 = re.compile("Total:(\d)")
    			total_arp = p2.findall(result)
    			while flag <  int(total_arp[0]) :
    				result, n11, n21 = o.cli.execute(handle,"return")
    				result, n11, n21 = o.cli.execute(handle,"system-view")
    				cmd_arp_ip = "undo ip route-static %s 32 Vlanif 2002 %s tag 2002" %(arp_ip[flag][0], arp_ip[flag][0])
    				result, n11, n21 = o.cli.execute(handle,command = cmd_arp_ip)
    				flag = flag + 1
    			print("Recoverying: Recovered IP Address successfully")
    		result = o.cli.close(handle)
    		return 0
Translation
Download
Updated: 2019-05-17

Document ID: EDOC1000174116

Views: 51310

Downloads: 19

Average rating:
This Document Applies to these Products
Related Documents
Related Version
Share
Previous Next