OpenIxia / IxNetwork

A central location for IxNetwork sample scripts and utilities. Please also visit http://openixia.com
MIT License
50 stars 59 forks source link

How to disable/enable specific route ranges by a list of ip addresses #76

Closed hubertgee closed 4 years ago

hubertgee commented 4 years ago

Andy,

How to use RestPy to disable/enable a specific list of route range ip addresses?

andy

ajbalogh commented 4 years ago

you will have to loop through the address values and for the ips you are interested in set an overlay on the active

On Fri, Nov 1, 2019 at 3:34 PM Hubert Gee notifications@github.com wrote:

Andy,

How to use RestPy to disable/enable a specific list of route range ip addresses?

[image: andy] https://user-images.githubusercontent.com/35346527/68060265-d63ec580-fcbc-11e9-8731-04160078350b.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/OpenIxia/IxNetwork/issues/76?email_source=notifications&email_token=AHHFTFTFB26D5IYDTVEFD5DQRSVIHA5CNFSM4JIAXW7KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HWHLAUQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHHFTFWIPH4OXJAFRCHVWSLQRSVIHANCNFSM4JIAXW7A .

kaushik2306 commented 4 years ago

I want to perform similar operation using TCL-High-Level

hubertgee commented 4 years ago

Andy, doing what you recommended …

ngObj = ixNetwork.Topology.find()[0].DeviceGroup.find()[0].NetworkGroup.find()[0].Ipv4PrefixPools.find()[0]
networkAddressValues = ngObj.NetworkAddress.Values   **<-- Get all the ip addresses**

bgpObj = ixNetwork.Topology.find()[0].DeviceGroup.find()[0].NetworkGroup.find()[0].Ipv4PrefixPools.find()[0].BgpIPRouteProperty.find()[0]

setIpAddressList = ['10.10.0.1','10.10.0.3', '10.10.0.3', '10.10.0.5', '10.10.0.7']  **;# These ip addresses are what I want to set True|False**

for index, ip in enumerate(networkAddressValues):
    if ip in setIpAddressList:
        **# Using overlay to set specific indexes**
        bgpObj.Active.Overlay(index+1, True)

The above code works fine. It will set all the setIpAddressList to True. But now if I want to run the code again and set them to False, the first overlay works, but RestPy errors out. Why is that?

2019-11-04 22:06:24 [ixnetwork_restpy.connection] [DEBUG] 202 Accepted b'{"executionTimeMs":13.0,"id":"","state":"SUCCESS","progress":100,"message":null,"url":"","resultUrl":"","result":[{"href":"/api/v1/sessions/1/ixnetwork/topology/1/deviceGroup/1/networkGroup/1","id":1,"ipv4PrefixPools":[{"href":"/api/v1/sessions/1/ixnetwork/topology/1/deviceGroup/1/networkGroup/1/ipv4PrefixPools/1","id":1,"networkAddress":"/api/v1/sessions/1/ixnetwork/multivalue/113","prefixLength":"/api/v1/sessions/1/ixnetwork/multivalue/114","prefixAddrStep":"/api/v1/sessions/1/ixnetwork/multivalue/115","a'... 2019-11-04 22:06:24 [ixnetwork_restpy.connection] [DEBUG] POST https://192.168.70.3:11009/api/v1/sessions/1/ixnetwork/operations/select {"selects": [{"from": "/api/v1/sessions/1/ixnetwork/topology/1/deviceGroup/1/networkGroup/1/ipv4PrefixPools/1", "properties": [] ... 2019-11-04 22:06:24 [ixnetwork_restpy.connection] [DEBUG] 202 Accepted b'{"executionTimeMs":111.0,"id":"","state":"SUCCESS","progress":100,"message":null,"url":"","resultUrl":"","result":[{"href":"/api/v1/sessions/1/ixnetwork/topology/1/deviceGroup/1/networkGroup/1/ipv4PrefixPools/1","id":1,"bgpIPRouteProperty":[{"href":"/api/v1/sessions/1/ixnetwork/topology/1/deviceGroup/1/networkGroup/1/ipv4PrefixPools/1/bgpIPRouteProperty/1","id":1,"useTraditionalNlri":"/api/v1/sessions/1/ixnetwork/multivalue/233","sendMulticastWithProperSAFI":"/api/v1/sessions/1/ixnetwork/multivalue/234","sk'...

2019-11-04 22:06:24 [ixnetwork_restpy.connection] [DEBUG] POST https://192.168.70.3:11009/api/v1/sessions/1/ixnetwork/multivalue/295/overlay {"count": 1, "index": 7, "indexStep": 1, "value": true} 2019-11-04 22:06:24 [ixnetwork_restpy.connection] [DEBUG] 201 Created b'{"links":[{"rel":"self","method":"GET","href":"/api/v1/sessions/1/ixnetwork/multivalue/295/overlay/7"}]}' 2019-11-04 22:06:24 [ixnetwork_restpy.connection] [DEBUG] GET https://192.168.70.3:11009/api/v1/sessions/1/ixnetwork/multivalue/295/overlay/7 2019-11-04 22:06:24 [ixnetwork_restpy.connection] [DEBUG] 404 Not Found b'{"method":"GET","pathAndQuery":"/api/v1/sessions/1/ixnetwork/multivalue/295/overlay/7","errors":[{"code":404,"detail":"NotFound: The requested resource /api/v1/sessions/1/ixnetwork/multivalue/295/overlay/7 cannot be found."}]}'

Error: Traceback (most recent call last): File "deviceId.py", line 77, in bgpObj.Active.Overlay(index+1, True) File "/usr/local/python3.7.0/lib/python3.7/site-packages/ixnetwork_restpy/multivalue.py", line 373, in Overlay self._connection._create(href, payload) File "/usr/local/python3.7.0/lib/python3.7/site-packages/ixnetwork_restpy/connection.py", line 188, in _create return self._send_recv('POST', url, payload) File "/usr/local/python3.7.0/lib/python3.7/site-packages/ixnetwork_restpy/connection.py", line 370, in _send_recv return self._send_recv('GET', href) File "/usr/local/python3.7.0/lib/python3.7/site-packages/ixnetwork_restpy/connection.py", line 376, in _send_recv self._process_response_status_code(response) File "/usr/local/python3.7.0/lib/python3.7/site-packages/ixnetwork_restpy/connection.py", line 284, in _process_response_status_code raise NotFoundError(response) ixnetwork_restpy.errors.NotFoundError: https://192.168.70.3:11009/api/v1/sessions/1/ixnetwork/multivalue/295/overlay/7 => 404 Not Found {"method":"GET","pathAndQuery":"/api/v1/sessions/1/ixnetwork/multivalue/295/overlay/7","errors":[{"code":404,"detail":"NotFound: The requested resource /api/v1/sessions/1/ixnetwork/multivalue/295/overlay/7 cannot be found."}]}

therkong commented 4 years ago

HLAPI has command to enable/disable the route ranges; however, you need to pass in the handle to the route range. For example:

create BGP route range

_result_ = ixiangpf.emulation_bgp_route_config(
    handle                                   = networkGroup_3_handle,
    mode                                     = "create",
    protocol_route_name                      = """BGP IP Route Range 1""",
    active                                   = "1",
    …
    …
)
if _result_['status'] != IxiaHlt.SUCCESS:
    ixnHLT_errorHandler('emulation_bgp_route_config', _result_)

bgpIPRouteProperty_1_handle = _result_['ip_routes']
ixnHLT['HANDLE,//topology:<2>/deviceGroup:<1>/networkGroup:<1>/ipv4PrefixPools:<1>/bgpIPRouteProperty:<1>'] = bgpIPRouteProperty_1_handle

disable the route range:

_result_ = ixiangpf.emulation_bgp_route_config(
    handle                                   = bgpIPRouteProperty_1_handle,
    mode                                     = "modify",
    protocol_route_name                      = """BGP IP Route Range 1""",
    active                                   = "0"
)

HLAPI lacks the command to retrieve the IP addresses associated with the route range.  You must  use ixNet low level api to retrieve it.
ajbalogh commented 4 years ago

why are you setting it to false - just remove all your overlays that you set - networkAddress.ClearOverlays() will remove any overlays

On Mon, Nov 4, 2019 at 3:10 PM therkong notifications@github.com wrote:

HLAPI has command to enable/disable the route ranges; however, you need to pass in the handle to the route range. For example: create BGP route range

result = ixiangpf.emulation_bgp_route_config(

handle                                   = networkGroup_3_handle,

mode                                     = "create",

protocol_route_name                      = """BGP IP Route Range 1""",

active                                   = "1",

…

…

)

if result['status'] != IxiaHlt.SUCCESS:

ixnHLT_errorHandler('emulation_bgp_route_config', _result_)

bgpIPRouteProperty_1_handle = result['ip_routes']

ixnHLT['HANDLE,//topology:<2>/deviceGroup:<1>/networkGroup:<1>/ipv4PrefixPools:<1>/bgpIPRouteProperty:<1>'] = bgpIPRouteProperty_1_handle

disable the route range:

result = ixiangpf.emulation_bgp_route_config(

handle                                   = bgpIPRouteProperty_1_handle,

mode                                     = "modify",

protocol_route_name                      = """BGP IP Route Range 1""",

active                                   = "0"

)

HLAPI lacks the command to retrieve the IP addresses associated with the route range. You must use ixNet low level api to retrieve it.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OpenIxia/IxNetwork/issues/76?email_source=notifications&email_token=AHHFTFQFZNN4YK7AFFOEYJDQSCTXTA5CNFSM4JIAXW7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDBBGQQ#issuecomment-549589826, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHHFTFV3MSQJD5DMOXF5IOLQSCTXTANCNFSM4JIAXW7A .

hubertgee commented 4 years ago

Got it! I didn't know exactly how overlay works. Thanks.