Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

issue 116 - implemented request to get routes for ipv6 destinations #117

Merged
merged 9 commits into from
Apr 28, 2017
33 changes: 24 additions & 9 deletions napalm_iosxr/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,15 +1240,30 @@ def get_route_to(self, destination='', protocol=''):
prefix_tag = '<PrefixLength>{prefix_length}</PrefixLength>'.format(
prefix_length=dest_split[1])

route_info_rpc_command = '<Get><Operational><RIB><VRFTable><VRF><Naming><VRFName>default\
</VRFName></Naming><AFTable><AF><Naming><AFName>IPv4</AFName></Naming><SAFTable><SAF>\
<Naming><SAFName>Unicast</SAFName></Naming><IP_RIBRouteTable><IP_RIBRoute><Naming>\
<RouteTableName>default</RouteTableName></Naming><RouteTable><Route><Naming><Address>\
{network}</Address>{prefix}</Naming></Route></RouteTable></IP_RIBRoute></IP_RIBRouteTable>\
</SAF></SAFTable></AF></AFTable></VRF></VRFTable></RIB></Operational></Get>'.format(
network=network,
prefix=prefix_tag
)
ipv = 4
try:
ipv = IPAddress(network).version
except AddrFormatError:
return {'error': 'Wrong destination IP Address!'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please raise TypeError instead or returning a dictionary.


if ipv == 6:
route_info_rpc_command = '<Get><Operational><IPV6_RIB><VRFTable><VRF><Naming><VRFName>\
default</VRFName></Naming><AFTable><AF><Naming><AFName>IPv6</AFName></Naming><SAFTable>\
<SAF><Naming><SAFName>Unicast</SAFName></Naming><IP_RIBRouteTable><IP_RIBRoute><Naming>\
<RouteTableName>default</RouteTableName></Naming><RouteTable><Route><Naming><Address>\
{network}</Address>{prefix}</Naming></Route></RouteTable></IP_RIBRoute>\
</IP_RIBRouteTable></SAF></SAFTable></AF></AFTable></VRF></VRFTable></IPV6_RIB>\
</Operational></Get>'.format(network=network, prefix=prefix_tag)
else:
route_info_rpc_command = '<Get><Operational><RIB><VRFTable><VRF><Naming><VRFName>default\
</VRFName></Naming><AFTable><AF><Naming><AFName>IPv4</AFName></Naming><SAFTable><SAF>\
<Naming><SAFName>Unicast</SAFName></Naming><IP_RIBRouteTable><IP_RIBRoute><Naming>\
<RouteTableName>default</RouteTableName></Naming><RouteTable><Route><Naming><Address>\
{network}</Address>{prefix}</Naming></Route></RouteTable></IP_RIBRoute></IP_RIBRouteTable>\
</SAF></SAFTable></AF></AFTable></VRF></VRFTable></RIB></Operational></Get>'.format(
network=network,
prefix=prefix_tag
)

routes_tree = ETREE.fromstring(self.device.make_rpc_call(route_info_rpc_command))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Response MajorVersion="1" MinorVersion="0"><Get><Operational><IPV6_RIB MajorVersion="4" MinorVersion="0"><VRFTable><VRF><Naming><VRFName>default</VRFName></Naming><AFTable><AF><Naming><AFName>IPv6</AFName></Naming><SAFTable><SAF><Naming><SAFName>Unicast</SAFName></Naming><IP_RIBRouteTable><IP_RIBRoute><Naming><RouteTableName>default</RouteTableName></Naming><RouteTable><Route><Naming><Address>dead:beef:210:210::53</Address></Naming></Route></RouteTable></IP_RIBRoute></IP_RIBRouteTable></SAF></SAFTable></AF></AFTable></VRF></VRFTable></IPV6_RIB></Operational></Get><ResultSummary ErrorCount="0"/></Response>