1 # Copyright (c) 2018 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """This module implements keywords to configure proxyARP using Honeycomb
17 from resources.libraries.python.HTTPRequest import HTTPCodes
18 from resources.libraries.python.honeycomb.HoneycombSetup import HoneycombError
19 from resources.libraries.python.honeycomb.HoneycombUtil \
20 import HoneycombUtil as HcUtil
21 from resources.libraries.python.honeycomb.HoneycombUtil \
22 import DataRepresentation
23 from resources.libraries.python.topology import Topology
26 class ProxyARPKeywords(object):
27 """Implementation of keywords which make it possible to:
28 - configure proxyARP behaviour
29 - enable/disable proxyARP on individual interfaces
37 def configure_proxyarp(node, data):
38 """Configure the proxyARP feature and check the return code.
40 :param node: Honeycomb node.
41 :param data: Configuration to use.
44 :returns: Content of response.
46 :raises HoneycombError: If the status code in response to PUT is not
47 200 = OK or 201 = ACCEPTED.
58 status_code, resp = HcUtil.\
59 put_honeycomb_data(node, "config_proxyarp_ranges", data,
60 data_representation=DataRepresentation.JSON)
62 if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED):
64 "proxyARP configuration unsuccessful. "
65 "Status code: {0}.".format(status_code))
70 def remove_proxyarp_configuration(node):
71 """Delete the proxyARP node, removing all of its configuration.
73 :param node: Honeycomb node.
75 :returns: Content of response.
77 :raises HoneycombError: If the status code in response is not 200 = OK.
80 status_code, resp = HcUtil. \
81 delete_honeycomb_data(node, "config_proxyarp_ranges")
83 if status_code != HTTPCodes.OK:
85 "proxyARP removal unsuccessful. "
86 "Status code: {0}.".format(status_code))
91 def get_proxyarp_operational_data(node):
92 """Retrieve proxyARP properties from Honeycomb operational data.
93 Note: The proxyARP feature has no operational data available.
95 :param node: Honeycomb node.
97 :returns: proxyARP operational data.
101 raise NotImplementedError("Not supported in VPP.")
104 def set_proxyarp_interface_config(node, interface, state):
105 """Enable or disable the proxyARP feature on the specified interface.
107 :param node: Honeycomb node.
108 :param interface: Name or sw_if_index of an interface on the node.
109 :param state: Desired proxyARP state: enable, disable.
113 :raises ValueError: If the state argument is incorrect.
114 :raises HoneycombError: If the status code in response is not
115 200 = OK or 201 = ACCEPTED.
118 interface = Topology.convert_interface_reference(
119 node, interface, "name")
120 interface = interface.replace("/", "%2F")
122 path = "/interface/{0}/proxy-arp".format(interface)
124 if state == "disable":
125 status_code, _ = HcUtil.delete_honeycomb_data(
126 node, "config_vpp_interfaces", path)
127 elif state == "enable":
128 data = {"proxy-arp": {}}
129 status_code, _ = HcUtil.put_honeycomb_data(
130 node, "config_vpp_interfaces", data, path)
132 raise ValueError("State argument has to be enable or disable.")
134 if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED):
135 raise HoneycombError(
136 "Interface proxyARP configuration on node {0} was not"
137 " successful.".format(node["host"]))
140 def get_proxyarp_interface_assignment(node, interface):
141 """Read the status of proxyARP feature on the specified interface.
142 Note: The proxyARP feature has no operational data available.
144 :param node: Honeycomb node.
145 :param interface: Name or sw_if_index of an interface on the node.
148 :returns: Content of response.
152 raise NotImplementedError("Not supported in VPP.")
155 class IPv6NDProxyKeywords(object):
156 """Keywords for IPv6 Neighbor Discovery proxy configuration."""
162 def configure_ipv6nd(node, interface, addresses=None):
163 """Configure IPv6 Neighbor Discovery proxy on the specified interface,
164 or remove/replace an existing configuration.
166 :param node: Honeycomb node.
167 :param interface: Name of an interface on the node.
168 :param addresses: IPv6 addresses to configure ND proxy with. If no
169 address is provided, ND proxy configuration will be removed.
172 :type addresses: list
173 :returns: Content of response.
175 :raises HoneycombError: If the operation fails.
178 interface = Topology.convert_interface_reference(
179 node, interface, "name")
180 interface = interface.replace("/", "%2F")
182 path = "/interface/{0}/ietf-ip:ipv6/nd-proxies".format(interface)
184 if addresses is None:
185 status_code, resp = HcUtil. \
186 delete_honeycomb_data(node, "config_vpp_interfaces", path)
190 "nd-proxy": [{"address": x} for x in addresses]
194 status_code, resp = HcUtil. \
195 put_honeycomb_data(node, "config_vpp_interfaces", data, path,
196 data_representation=DataRepresentation.JSON)
198 if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED):
199 raise HoneycombError(
200 "IPv6 ND proxy configuration unsuccessful. "
201 "Status code: {0}.".format(status_code))
206 def get_ipv6nd_configuration(node, interface):
207 """Read IPv6 Neighbor Discovery proxy configuration on the specified
210 :param node: Honeycomb node.
211 :param interface: Name of an interface on the node.
214 :returns: Content of response.
216 :raises HoneycombError: If the configuration could not be read.
219 interface = Topology.convert_interface_reference(
220 node, interface, "name")
221 interface = interface.replace("/", "%2F")
223 path = "/interface/{0}/ietf-ip:ipv6/nd-proxies".format(interface)
225 status_code, resp = HcUtil.get_honeycomb_data(
226 node, "config_vpp_interfaces", path)
227 if status_code != HTTPCodes.OK:
228 raise HoneycombError(
229 "Could not read IPv6 ND proxy configuration. "
230 "Status code: {0}.".format(status_code))