def verify_no_route_map_match(step):
    step("\n########## Verifying no route-map match ##########\n")
    step("### Removing route-map configuration ###\n")
    switch = switches[0]
    routemap = bgp_config1.routemaps[0]
    prefixlist = routemap[1]
    action = routemap[3]

    cfg_array = []
    cfg_array.append("route-map %s %s %d" %
                     (prefixlist.name, action, prefixlist.seq_num))
    cfg_array.append("no match ip address prefix-list %s" % prefixlist.name)

    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)

    reconfigure_neighbor(step)

    step("### Verifying first network of BGP1 received on BGP2 ###\n")
    switch = switches[1]
    network = bgp_config1.networks[0]
    next_hop = bgp_config1.routerid

    found = SwitchVtyshUtils.wait_for_route(switch, network, next_hop)

    assert found, "Route %s -> %s was not found on %s" % \
                  (network, next_hop, switch.name)

    step("### Previously denied network is now present in BGP2 ###\n")
def reconfigure_neighbor(step):
    step("### Reset connection from BGP2 via reconfiguring neighbor ###\n")
    switch = switches[1]
    neighbor = bgp_config2.neighbors[0]

    cfg_array = []
    cfg_array.append("router bgp %s" % bgp_config2.asn)
    cfg_array.append("no neighbor %s" % neighbor.routerid)

    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)

    step("### Waiting for route to be removed ###\n")
    network = neighbor.networks[1]
    next_hop = neighbor.routerid
    route_should_exist = False

    found = SwitchVtyshUtils.wait_for_route(switch, network, next_hop,
                                            route_should_exist)

    assert not found, "Route %s -> %s exists on %s" \
                      % (network, next_hop, switch.name)

    step("### Reconfiguring neighbor (BGP1) on BGP2 ###\n")
    cfg_array = []
    cfg_array.append("router bgp %s" % bgp_config2.asn)
    cfg_array.append("neighbor %s remote-as %s" %
                     (neighbor.routerid, neighbor.asn))
    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)

    step("### Waiting for route to be received again ###\n")

    found = SwitchVtyshUtils.wait_for_route(switch, network, next_hop)

    assert found, "Route %s -> %s was not found on %s" \
                  % (network, next_hop, switch.name)
示例#3
0
def apply_bgp_config(step):
    global all_cfg_array
    step("\n########## Applying BGP configurations... ##########\n")
    all_cfg_array = []

    i = 0
    for bgp_cfg in bgpconfigarr:
        step("### Applying configurations for BGP: %s ###\n" %
             bgp_cfg.routerid)
        cfg_array = []

        if i == 0:
            step("### Applying community list configurations for BGP1")
            cfg_array.append("ip community-list BGP_IN permit 2:0")
            cfg_array.append("ip community-list BGP_IN deny 3:0")
            step("### Applying route-map configurations for BGP1")
            cfg_array.append("route-map BGP_RMAP permit 10")
            cfg_array.append("match community BGP_IN")

        if i == 1:
            cfg_array.append("route-map BGP_2 permit 10")
            cfg_array.append("set community 2:0")

        if i == 2:
            cfg_array.append("route-map BGP_3 permit 10")
            cfg_array.append("set community 3:0")

        SwitchVtyshUtils.vtysh_cfg_cmd(switches[i], cfg_array)

        del cfg_array[:]

        # Initiate BGP configuration
        cfg_array.append("router bgp %s" % bgp_cfg.asn)
        cfg_array.append("bgp router-id %s" % bgp_cfg.routerid)

        # Add the networks this bgp will be advertising
        for network in bgp_cfg.networks:
            cfg_array.append("network %s/%s" % (network, default_pl))

        if i == 0:
            cfg_array.append("neighbor 10.0.0.2 remote-as 3")
            cfg_array.append("neighbor 10.0.0.2 route-map BGP_RMAP in")
            cfg_array.append("neighbor 9.0.0.2 remote-as 2")
            cfg_array.append("neighbor 9.0.0.2 route-map BGP_RMAP in")

        if i == 1:
            cfg_array.append("neighbor 9.0.0.1 remote-as 1")
            cfg_array.append("neighbor 9.0.0.1 route-map BGP_2 out")

        if i == 2:
            cfg_array.append("neighbor 10.0.0.1 remote-as 1")
            cfg_array.append("neighbor 10.0.0.1 route-map BGP_3 out")

        SwitchVtyshUtils.vtysh_cfg_cmd(switches[i], cfg_array)

        # Add the configuration arrays to an array so that it can be used
        # for verification later.
        all_cfg_array.append(cfg_array)

        i += 1
示例#4
0
def change_password(step, password):
    step("### Changing password to \"%s\" ###\n" % password)
    switch = switches[0]
    cfg_array = []
    cfg_array.append("router bgp %s" % bgp1_asn)
    cfg_array.append("neighbor %s password %s" % (bgp1_neighbor, password))
    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)
def unconfigure_neighbor_bgp(step):
    step("\n########## Unconfiguring neighbor for BGP1... ##########\n")

    switch = switches[0]

    cfg_array = []
    cfg_array.append("router bgp %s" % bgp1_asn)
    cfg_array.append("no neighbor %s" % bgp1_neighbor)
    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)
def configure_bgp(step):
    step("\n########## Applying BGP configurations... ##########\n")

    i = 0
    for switch in switches:
        cfg_array = bgp_configs[i]
        i += 1

        SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)
示例#7
0
def configure_bgp(step):
    step("\n########## Configuring BGP on all switches.. ##########\n")

    i = 0
    for switch in switches:
        cfg_array = bgp_configs[i]
        i += 1

        SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)
示例#8
0
def unconfigure_remove_private_as(step):
    step("### Unconfiguring remove private AS for BGP2... ###\n")

    switch = switches[1]

    cfg_array = []
    cfg_array.append("router bgp %s" % bgp2_asn)
    cfg_array.append("no neighbor %s remove-private-AS" % bgp2_neighbor)

    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)
示例#9
0
def configure_bgp(step):
    step("\n########## Configuring BGP on all switches.. ##########\n")

    i = num_of_switches - 1
    for iteration in range(num_of_switches):
        switch = switches[i]
        cfg_array = bgp_configs[i]
        i -= 1

        SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)
def unconfigure_peer_group(step):
    switch = switches[0]

    step("\n########## Unconfiguring peer-group on %s ##########\n" %
         switch.name)

    cfg_array = []
    cfg_array.append("router bgp %s" % bgp1_asn)
    cfg_array.append("no neighbor %s peer-group %s" %
                     (bgp1_neighbor, bgp_peer_group))

    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)
示例#11
0
def change_to_no_neighbor_password(step):
    step("### Unsetting password ###\n")

    switch = switches[0]
    cfg_array = []
    cfg_array.append("router bgp %s" % bgp1_asn)
    cfg_array.append("no neighbor %s password" % bgp1_neighbor)
    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)

    switch = switches[1]
    cfg_array = []
    cfg_array.append("router bgp %s" % bgp2_asn)
    cfg_array.append("no neighbor %s password" % bgp2_neighbor)
    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)
def verify_no_set_metric_and_community_values(step):
    step("\n########## Verifying no community and no "
         "set metric values ##########\n")

    step("### Setting no set metric and no community on BGP1 ###\n")
    switch = switches[0]
    # Network 2 of BGP1 is the permitted route
    network = bgp_config1.networks[1]
    next_hop = bgp_config1.routerid
    routemap = bgp_config1.routemaps[0]
    prefixlist = routemap[1]
    action = routemap[3]
    metric = routemap[4]

    cfg_array = []
    cfg_array.append("route-map %s %s %d" %
                     (prefixlist.name, action, prefixlist.seq_num))
    cfg_array.append("no set metric")
    cfg_array.append("no set community")

    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)

    reconfigure_neighbor(step)

    step("### Verifying no set metric. Metric should not exist ###\n")
    switch = switches[1]
    cmd = "show ip bgp"
    routes = switch(cmd).split("\r\n")

    metric_found = False
    for rte in routes:
        if (network in rte) and (next_hop in rte) and (metric in rte):
            metric_found = True
            break

    assert not metric_found, "Metric was found"

    step("### Metric was successfully unset on BGP1 ###\n")
    step("### Verifying no set community ###\n")

    cmd = "sh ip bgp %s" % network
    network_info = switch(cmd)

    assert rm_community not in network_info, "Community should not be set"

    step("### Community value was successfully unset ###\n")
示例#13
0
def apply_bgp_config(step):
    global all_cfg_array
    step("\n########## Applying BGP configurations... ##########\n")
    all_cfg_array = []

    i = 0
    for bgp_cfg in bgpconfigarr:
        step("### Applying configurations for BGP: %s ###\n" %
             bgp_cfg.routerid)
        cfg_array = []

        # Add any prefix-lists
        add_prefix_list_configs(bgp_cfg, cfg_array)
        print(cfg_array)

        SwitchVtyshUtils.vtysh_cfg_cmd(switches[i], cfg_array)

        del cfg_array[:]

        # Initiate BGP configuration
        cfg_array.append("router bgp %s" % bgp_cfg.asn)
        cfg_array.append("bgp router-id %s" % bgp_cfg.routerid)

        # Add the networks this bgp will be advertising
        for network in bgp_cfg.networks:
            cfg_array.append("network %s/%s" % (network, default_pl))

        # Add the neighbors of this switch
        for neighbor in bgp_cfg.neighbors:
            cfg_array.append("neighbor %s remote-as %s" %
                             (neighbor.routerid, neighbor.asn))

        if bgp_cfg.asn is "1":
            # Add the neighbor prefix-list configs
            add_neighbor_prefix_list_configs(step, cfg_array)

        SwitchVtyshUtils.vtysh_cfg_cmd(switches[i], cfg_array)

        print(cfg_array)

        # Add the configuration arrays to an array so that it can be used
        # for verification later.
        all_cfg_array.append(cfg_array)

        i += 1
def verify_no_peer_group(step):
    step("\n########### Verifying no peer-group ##########\n")
    step("### Removing peer-group ###\n")

    switch = switches[0]
    cfg_array = []
    cfg_array.append("router bgp %s" % bgp1_asn)
    peer_group_cfg = "neighbor %s" % bgp_peer_group
    cfg_array.append("no %s" % peer_group_cfg)

    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)

    step("### Verifying peer-group config removed ###\n")

    exists = SwitchVtyshUtils.verify_cfg_exist(switch, [peer_group_cfg])

    assert not exists, "Peer-group was not unconfigured"

    step("### Peer-group unconfigured successfully ###\n")
示例#15
0
def verify_no_ip_community(step):
    step("\n########## Verifying no ip prefix-list ##########\n")
    switch = switches[0]

    cmd = "no ip community-list BGP_IN"

    step("### Unconfiguring ip community-list BGP_IN ###\n")
    SwitchVtyshUtils.vtysh_cfg_cmd(switch, [cmd])

    cfg = "ip community-list BGP_IN permit 2:0"
    step("### Checking ip community-list config ###\n")
    exists = SwitchVtyshUtils.verify_cfg_exist(switch, [])
    assert not exists, "Config \"%s\" was not removed" % cfg

    cfg = "ip community-list BGP_IN permit 3:0"
    step("### Checking ip community-list config ###\n")
    exists = SwitchVtyshUtils.verify_cfg_exist(switch, [])
    assert not exists, "Config \"%s\" was not removed" % cfg

    step("### ip community-list  configs were successfully removed ###\n")
示例#16
0
def reconfigure_neighbor(step):
    step("### Reconfiguring neighbor to refresh routes ###\n")
    switch = switches[0]
    cfg_array = []
    cfg_array.append("router bgp %s" % bgp1_asn)
    cfg_array.append("no neighbor %s" % bgp1_neighbor)
    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)

    step("### Verifying route removed prior to proceeding ###\n")
    network = bgp3_network
    next_hop = bgp2_router_id
    route_should_exist = False
    found = SwitchVtyshUtils.wait_for_route(switch, network, next_hop,
                                            route_should_exist)

    assert not found, "Route %s -> %s still exists" % (network, next_hop)

    step("### Configuring neighbor again... ###\n")
    cfg_array = []
    cfg_array.append("router bgp %s" % bgp1_asn)
    cfg_array.append("neighbor %s remote-as %s" %
                     (bgp1_neighbor, bgp1_neighbor_asn))
    SwitchVtyshUtils.vtysh_cfg_cmd(switch, cfg_array)