Add keyword to manipulate vhost-user parameters
[csit.git] / resources / libraries / python / honeycomb / HcAPIKwInterfaces.py
1 # Copyright (c) 2016 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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """Keywords to manipulate interface configuration using Honeycomb REST API.
15
16 The keywords make possible to put and get configuration data and to get
17 operational data.
18 """
19
20 from resources.libraries.python.HTTPRequest import HTTPCodes
21 from resources.libraries.python.honeycomb.HoneycombSetup import HoneycombError
22 from resources.libraries.python.honeycomb.HoneycombUtil \
23     import DataRepresentation
24 from resources.libraries.python.honeycomb.HoneycombUtil \
25     import HoneycombUtil as HcUtil
26
27
28 class InterfaceKeywords(object):
29     """Keywords for Interface manipulation.
30
31     Implements keywords which get configuration and operational data about
32     vpp interfaces and set the interface's parameters using Honeycomb REST API.
33     """
34
35     INTF_PARAMS = ("name", "description", "type", "enabled",
36                    "link-up-down-trap-enable")
37     IPV4_PARAMS = ("enabled", "forwarding", "mtu")
38     IPV6_PARAMS = ("enabled", "forwarding", "mtu", "dup-addr-detect-transmits")
39     IPV6_AUTOCONF_PARAMS = ("create-global-addresses",
40                             "create-temporary-addresses",
41                             "temporary-valid-lifetime",
42                             "temporary-preferred-lifetime")
43     ETH_PARAMS = ("mtu", )
44     ROUTING_PARAMS = ("vrf-id", )
45     VXLAN_PARAMS = ("src", "dst", "vni", "encap-vrf-id")
46     L2_PARAMS = ("bridge-domain", "split-horizon-group",
47                  "bridged-virtual-interface")
48     TAP_PARAMS = ("tap-name", "mac", "device-instance")
49     VHOST_USER_PARAMS = ("socket", "role")
50
51     def __init__(self):
52         pass
53
54     @staticmethod
55     def _configure_interface(node, interface, data,
56                              data_representation=DataRepresentation.JSON):
57         """Send interface configuration data and check the response.
58
59         :param node: Honeycomb node.
60         :param interface: The name of interface.
61         :param data: Configuration data to be sent in PUT request.
62         :param data_representation: How the data is represented.
63         :type node: dict
64         :type interface: str
65         :type data: dict
66         :type data_representation: DataRepresentation
67         :return: Content of response.
68         :rtype: bytearray
69         :raises HoneycombError: If the status code in response on PUT is not
70         200 = OK.
71         """
72
73         status_code, resp = HcUtil.\
74             put_honeycomb_data(node, "config_vpp_interfaces", data,
75                                data_representation=data_representation)
76         if status_code != HTTPCodes.OK:
77             raise HoneycombError(
78                 "The configuration of interface '{0}' was not successful. "
79                 "Status code: {1}.".format(interface, status_code))
80         return resp
81
82     @staticmethod
83     def get_all_interfaces_cfg_data(node):
84         """Get configuration data about all interfaces from Honeycomb.
85
86         :param node: Honeycomb node.
87         :type node: dict
88         :return: Configuration data about all interfaces from Honeycomb.
89         :rtype: list
90         :raises HoneycombError: If it is not possible to get configuration data.
91         """
92
93         status_code, resp = HcUtil.\
94             get_honeycomb_data(node, "config_vpp_interfaces")
95         if status_code != HTTPCodes.OK:
96             raise HoneycombError(
97                 "Not possible to get configuration information about the "
98                 "interfaces. Status code: {0}.".format(status_code))
99         try:
100             return resp["interfaces"]["interface"]
101
102         except (KeyError, TypeError):
103             return []
104
105     @staticmethod
106     def get_interface_cfg_data(node, interface):
107         """Get configuration data about the given interface from Honeycomb.
108
109         :param node: Honeycomb node.
110         :param interface: The name of interface.
111         :type node: dict
112         :type interface: str
113         :return: Configuration data about the given interface from Honeycomb.
114         :rtype: dict
115         """
116
117         intfs = InterfaceKeywords.get_all_interfaces_cfg_data(node)
118         for intf in intfs:
119             if intf["name"] == interface:
120                 return intf
121         return {}
122
123     @staticmethod
124     def get_all_interfaces_oper_data(node):
125         """Get operational data about all interfaces from Honeycomb.
126
127         :param node: Honeycomb node.
128         :type node: dict
129         :return: Operational data about all interfaces from Honeycomb.
130         :rtype: list
131         :raises HoneycombError: If it is not possible to get operational data.
132         """
133
134         status_code, resp = HcUtil.\
135             get_honeycomb_data(node, "oper_vpp_interfaces")
136         if status_code != HTTPCodes.OK:
137             raise HoneycombError(
138                 "Not possible to get operational information about the "
139                 "interfaces. Status code: {0}.".format(status_code))
140         try:
141             return resp["interfaces-state"]["interface"]
142
143         except (KeyError, TypeError):
144             return []
145
146     @staticmethod
147     def get_interface_oper_data(node, interface):
148         """Get operational data about the given interface from Honeycomb.
149
150         :param node: Honeycomb node.
151         :param interface: The name of interface.
152         :type node: dict
153         :type interface: str
154         :return: Operational data about the given interface from Honeycomb.
155         :rtype: dict
156         """
157
158         intfs = InterfaceKeywords.get_all_interfaces_oper_data(node)
159         for intf in intfs:
160             if intf["name"] == interface:
161                 return intf
162         return {}
163
164     @staticmethod
165     def _set_interface_properties(node, interface, path, new_value=None):
166         """Set interface properties.
167
168         This method reads interface configuration data, creates, changes or
169         removes the requested data and puts it back to Honeycomb.
170
171         :param node: Honeycomb node.
172         :param interface: The name of interface.
173         :param path:  Path to data we want to change / create / remove.
174         :param new_value: The new value to be set. If None, the item will be
175         removed.
176         :type node: dict
177         :type interface: str
178         :type path: tuple
179         :type new_value: str, dict or list
180         :return: Content of response.
181         :rtype: bytearray
182         :raises HoneycombError: If it is not possible to get or set the data.
183         """
184
185         status_code, resp = HcUtil.\
186             get_honeycomb_data(node, "config_vpp_interfaces")
187         if status_code != HTTPCodes.OK:
188             raise HoneycombError(
189                 "Not possible to get configuration information about the "
190                 "interfaces. Status code: {0}.".format(status_code))
191
192         if new_value:
193             new_data = HcUtil.set_item_value(resp, path, new_value)
194         else:
195             new_data = HcUtil.remove_item(resp, path)
196         return InterfaceKeywords._configure_interface(node, interface, new_data)
197
198     @staticmethod
199     def set_interface_state(node, interface, state="up"):
200         """Set VPP interface state.
201
202         The keyword changes the administration state of interface to up or down
203         depending on the parameter "state".
204
205         :param node: Honeycomb node.
206         :param interface: The name of interface.
207         :param state: The requested state, only "up" and "down" are valid
208         values.
209         :type node: dict
210         :type interface: str
211         :type state: str
212         :return: Content of response.
213         :rtype: bytearray
214         :raises KeyError: If the argument "state" is nor "up" or "down".
215         :raises HoneycombError: If the interface is not present on the node.
216         """
217
218         intf_state = {"up": "true",
219                       "down": "false"}
220
221         path = ("interfaces", ("interface", "name", str(interface)), "enabled")
222         return InterfaceKeywords._set_interface_properties(
223             node, interface, path, intf_state[state.lower()])
224
225     @staticmethod
226     def set_interface_up(node, interface):
227         """Set the administration state of VPP interface to up.
228
229         :param node: Honeycomb node.
230         :param interface: The name of interface.
231         :type node: dict
232         :type interface: str
233         :return: Content of response
234         :rtype: bytearray
235         """
236
237         return InterfaceKeywords.set_interface_state(node, interface, "up")
238
239     @staticmethod
240     def set_interface_down(node, interface):
241         """Set the administration state of VPP interface to down.
242
243         :param node: Honeycomb node.
244         :param interface: The name of interface.
245         :type node: dict
246         :type interface: str
247         :return: Content of response.
248         :rtype: bytearray
249         """
250
251         return InterfaceKeywords.set_interface_state(node, interface, "down")
252
253     @staticmethod
254     def add_bridge_domain_to_interface(node, interface, bd_name,
255                                        split_horizon_group=None, bvi=None):
256         """Add a new bridge domain to an interface and set its parameters.
257
258         :param node: Honeycomb node.
259         :param interface: The name of interface.
260         :param bd_name: Bridge domain name.
261         :param split_horizon_group: Split-horizon group name.
262         :param bvi: The bridged virtual interface.
263         :type node: dict
264         :type interface: str
265         :type bd_name: str
266         :type split_horizon_group: str
267         :type bvi: str
268         :return: Content of response.
269         :rtype: bytearray
270         :raises HoneycombError: If the interface is not present on the node.
271         """
272
273         v3po_l2 = {"bridge-domain": str(bd_name)}
274         if split_horizon_group:
275             v3po_l2["split-horizon-group"] = str(split_horizon_group)
276         if bvi:
277             v3po_l2["bridged-virtual-interface"] = str(bvi)
278
279         path = ("interfaces", ("interface", "name", str(interface)), "v3po:l2")
280
281         return InterfaceKeywords._set_interface_properties(
282             node, interface, path, v3po_l2)
283
284     @staticmethod
285     def configure_interface_base(node, interface, param, value):
286         """Configure the base parameters of interface.
287
288         :param node: Honeycomb node.
289         :param interface: The name of interface.
290         :param param: Parameter to configure (set, change, remove)
291         :param value: The value of parameter. If None, the parameter will be
292         removed.
293         :type node: dict
294         :type interface: str
295         :type param: str
296         :type value: str
297         :return: Content of response.
298         :rtype: bytearray
299         :raises HoneycombError: If the parameter is not valid.
300         """
301
302         if param not in InterfaceKeywords.INTF_PARAMS:
303             raise HoneycombError("The parameter {0} is invalid.".format(param))
304
305         path = ("interfaces", ("interface", "name", interface), param)
306         return InterfaceKeywords._set_interface_properties(
307             node, interface, path, value)
308
309     @staticmethod
310     def configure_interface_ipv4(node, interface, param, value):
311         """Configure IPv4 parameters of interface
312
313         :param node: Honeycomb node.
314         :param interface: The name of interface.
315         :param param: Parameter to configure (set, change, remove)
316         :param value: The value of parameter. If None, the parameter will be
317         removed.
318         :type node: dict
319         :type interface: str
320         :type param: str
321         :type value: str
322         :return: Content of response.
323         :rtype: bytearray
324         :raises HoneycombError: If the parameter is not valid.
325         """
326
327         if param not in InterfaceKeywords.IPV4_PARAMS:
328             raise HoneycombError("The parameter {0} is invalid.".format(param))
329
330         path = ("interfaces", ("interface", "name", interface),
331                 "ietf-ip:ipv4", param)
332         return InterfaceKeywords._set_interface_properties(
333             node, interface, path, value)
334
335     @staticmethod
336     def add_first_ipv4_address(node, interface, ip_addr, network):
337         """Add the first IPv4 address.
338
339         If there are any other addresses configured, they will be removed.
340
341         :param node: Honeycomb node.
342         :param interface: The name of interface.
343         :param ip_addr: IPv4 address to be set.
344         :param network: Netmask or length of network prefix.
345         :type node: dict
346         :type interface: str
347         :type ip_addr: str
348         :type network: str or int
349         :return: Content of response.
350         :rtype: bytearray
351         """
352
353         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4")
354         if isinstance(network, basestring):
355             address = {"address": [{"ip": ip_addr, "netmask": network}, ]}
356         elif isinstance(network, int) and (0 < network < 33):
357             address = {"address": [{"ip": ip_addr, "prefix-length": network}, ]}
358         else:
359             raise HoneycombError("Value {0} is not a valid netmask or network "
360                                  "prefix length.".format(network))
361         return InterfaceKeywords._set_interface_properties(
362             node, interface, path, address)
363
364     @staticmethod
365     def add_ipv4_address(node, interface, ip_addr, network):
366         """Add IPv4 address.
367
368         :param node: Honeycomb node.
369         :param interface: The name of interface.
370         :param ip_addr: IPv4 address to be set.
371         :param network: Netmask or length of network prefix.
372         :type node: dict
373         :type interface: str
374         :type ip_addr: str
375         :type network: str or int
376         :return: Content of response.
377         :rtype: bytearray
378         """
379
380         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
381                 "address")
382         if isinstance(network, basestring):
383             address = {"address": [{"ip": ip_addr, "netmask": network}, ]}
384         elif isinstance(network, int) and (0 < network < 33):
385             address = {"address": [{"ip": ip_addr, "prefix-length": network}, ]}
386         else:
387             raise HoneycombError("Value {0} is not a valid netmask or network "
388                                  "prefix length.".format(network))
389         return InterfaceKeywords._set_interface_properties(
390             node, interface, path, address)
391
392     @staticmethod
393     def remove_all_ipv4_addresses(node, interface):
394         """Remove all IPv4 addresses from interface.
395
396         :param node: Honeycomb node.
397         :param interface: The name of interface.
398         :type node: dict
399         :type interface: str
400         :return: Content of response.
401         :rtype: bytearray
402         """
403
404         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
405                 "address")
406         return InterfaceKeywords._set_interface_properties(
407             node, interface, path, None)
408
409     @staticmethod
410     def add_first_ipv4_neighbor(node, interface, ip_addr, link_layer_address):
411         """Add the first IPv4 neighbour.
412
413         If there are any other neighbours configured, they will be removed.
414
415         :param node: Honeycomb node.
416         :param interface: The name of interface.
417         :param ip_addr: IPv4 address of neighbour to be set.
418         :param link_layer_address: Link layer address.
419         :type node: dict
420         :type interface: str
421         :type ip_addr: str
422         :type link_layer_address: str
423         :return: Content of response.
424         :rtype: bytearray
425         """
426
427         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4")
428         neighbor = {"neighbor": [{"ip": ip_addr,
429                                   "link-layer-address": link_layer_address}, ]}
430         return InterfaceKeywords._set_interface_properties(
431             node, interface, path, neighbor)
432
433     @staticmethod
434     def add_ipv4_neighbor(node, interface, ip_addr, link_layer_address):
435         """Add the IPv4 neighbour.
436
437         :param node: Honeycomb node.
438         :param interface: The name of interface.
439         :param ip_addr: IPv4 address of neighbour to be set.
440         :param link_layer_address: Link layer address.
441         :type node: dict
442         :type interface: str
443         :type ip_addr: str
444         :type link_layer_address: str
445         :return: Content of response.
446         :rtype: bytearray
447         """
448
449         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
450                 "neighbor")
451         neighbor = [{"ip": ip_addr, "link-layer-address": link_layer_address}, ]
452         return InterfaceKeywords._set_interface_properties(
453             node, interface, path, neighbor)
454
455     @staticmethod
456     def remove_all_ipv4_neighbors(node, interface):
457         """Remove all IPv4 neighbours.
458
459         :param node: Honeycomb node.
460         :param interface: The name of interface.
461         :type node: dict
462         :type interface: str
463         :return: Content of response.
464         :rtype: bytearray
465         """
466
467         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
468                 "neighbor")
469         return InterfaceKeywords._set_interface_properties(
470             node, interface, path, None)
471
472     @staticmethod
473     def configure_interface_ipv6(node, interface, param, value):
474         """Configure IPv6 parameters of interface
475
476         :param node: Honeycomb node.
477         :param interface: The name of interface.
478         :param param: Parameter to configure (set, change, remove)
479         :param value: The value of parameter. If None, the parameter will be
480         removed.
481         :type node: dict
482         :type interface: str
483         :type param: str
484         :type value: str
485         :return: Content of response.
486         :rtype: bytearray
487         :raises HoneycombError: If the parameter is not valid.
488         """
489
490         if param in InterfaceKeywords.IPV6_PARAMS:
491             path = ("interfaces", ("interface", "name", interface),
492                     "ietf-ip:ipv6", param)
493         elif param in InterfaceKeywords.IPV6_AUTOCONF_PARAMS:
494             path = ("interfaces", ("interface", "name", interface),
495                     "ietf-ip:ipv6", "autoconf", param)
496         else:
497             raise HoneycombError("The parameter {0} is invalid.".format(param))
498
499         return InterfaceKeywords._set_interface_properties(
500             node, interface, path, value)
501
502     @staticmethod
503     def add_first_ipv6_address(node, interface, ip_addr, prefix_len):
504         """Add the first IPv6 address.
505
506         If there are any other addresses configured, they will be removed.
507
508         :param node: Honeycomb node.
509         :param interface: The name of interface.
510         :param ip_addr: IPv6 address to be set.
511         :param prefix_len: Prefix length.
512         :type node: dict
513         :type interface: str
514         :type ip_addr: str
515         :type prefix_len: str
516         :return: Content of response.
517         :rtype: bytearray
518         """
519
520         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6")
521         address = {"address": [{"ip": ip_addr, "prefix-length": prefix_len}, ]}
522         return InterfaceKeywords._set_interface_properties(
523             node, interface, path, address)
524
525     @staticmethod
526     def add_ipv6_address(node, interface, ip_addr, prefix_len):
527         """Add IPv6 address.
528
529         :param node: Honeycomb node.
530         :param interface: The name of interface.
531         :param ip_addr: IPv6 address to be set.
532         :param prefix_len: Prefix length.
533         :type node: dict
534         :type interface: str
535         :type ip_addr: str
536         :type prefix_len: str
537         :return: Content of response.
538         :rtype: bytearray
539         """
540
541         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6",
542                 "address")
543         address = [{"ip": ip_addr, "prefix-length": prefix_len}, ]
544         return InterfaceKeywords._set_interface_properties(
545             node, interface, path, address)
546
547     @staticmethod
548     def remove_all_ipv6_addresses(node, interface):
549         """Remove all IPv6 addresses from interface.
550
551         :param node: Honeycomb node.
552         :param interface: The name of interface.
553         :type node: dict
554         :type interface: str
555         :return: Content of response.
556         :rtype: bytearray
557         """
558
559         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6",
560                 "address")
561         return InterfaceKeywords._set_interface_properties(
562             node, interface, path, None)
563
564     @staticmethod
565     def add_first_ipv6_neighbor(node, interface, ip_addr, link_layer_address):
566         """Add the first IPv6 neighbour.
567
568         If there are any other neighbours configured, they will be removed.
569
570         :param node: Honeycomb node.
571         :param interface: The name of interface.
572         :param ip_addr: IPv6 address of neighbour to be set.
573         :param link_layer_address: Link layer address.
574         :type node: dict
575         :type interface: str
576         :type ip_addr: str
577         :type link_layer_address: str
578         :return: Content of response.
579         :rtype: bytearray
580         """
581
582         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6")
583         neighbor = {"neighbor": [{"ip": ip_addr,
584                                   "link-layer-address": link_layer_address}, ]}
585         return InterfaceKeywords._set_interface_properties(
586             node, interface, path, neighbor)
587
588     @staticmethod
589     def add_ipv6_neighbor(node, interface, ip_addr, link_layer_address):
590         """Add the IPv6 neighbour.
591
592         :param node: Honeycomb node.
593         :param interface: The name of interface.
594         :param ip_addr: IPv6 address of neighbour to be set.
595         :param link_layer_address: Link layer address.
596         :type node: dict
597         :type interface: str
598         :type ip_addr: str
599         :type link_layer_address: str
600         :return: Content of response.
601         :rtype: bytearray
602         """
603
604         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6",
605                 "neighbor")
606         neighbor = [{"ip": ip_addr, "link-layer-address": link_layer_address}, ]
607         return InterfaceKeywords._set_interface_properties(
608             node, interface, path, neighbor)
609
610     @staticmethod
611     def remove_all_ipv6_neighbors(node, interface):
612         """Remove all IPv6 neighbours.
613
614         :param node: Honeycomb node.
615         :param interface: The name of interface.
616         :type node: dict
617         :type interface: str
618         :return: Content of response.
619         :rtype: bytearray
620         """
621
622         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6",
623                 "neighbor")
624         return InterfaceKeywords._set_interface_properties(
625             node, interface, path, None)
626
627     @staticmethod
628     def configure_interface_ethernet(node, interface, param, value):
629         """Configure the ethernet parameters of interface.
630
631         :param node: Honeycomb node.
632         :param interface: The name of interface.
633         :param param: Parameter to configure (set, change, remove)
634         :param value: The value of parameter. If None, the parameter will be
635         removed.
636         :type node: dict
637         :type interface: str
638         :type param: str
639         :type value: str
640         :return: Content of response.
641         :rtype: bytearray
642         :raises HoneycombError: If the parameter is not valid.
643         """
644
645         if param not in InterfaceKeywords.ETH_PARAMS:
646             raise HoneycombError("The parameter {0} is invalid.".format(param))
647         path = ("interfaces", ("interface", "name", interface), "v3po:ethernet",
648                 param)
649         return InterfaceKeywords._set_interface_properties(
650             node, interface, path, value)
651
652     @staticmethod
653     def configure_interface_routing(node, interface, param, value):
654         """Configure the routing parameters of interface.
655
656         :param node: Honeycomb node.
657         :param interface: The name of interface.
658         :param param: Parameter to configure (set, change, remove)
659         :param value: The value of parameter. If None, the parameter will be
660         removed.
661         :type node: dict
662         :type interface: str
663         :type param: str
664         :type value: str
665         :return: Content of response.
666         :rtype: bytearray
667         :raises HoneycombError: If the parameter is not valid.
668         """
669
670         if param not in InterfaceKeywords.ROUTING_PARAMS:
671             raise HoneycombError("The parameter {0} is invalid.".format(param))
672
673         path = ("interfaces", ("interface", "name", interface), "v3po:routing",
674                 param)
675         return InterfaceKeywords._set_interface_properties(
676             node, interface, path, value)
677
678     @staticmethod
679     def create_vxlan_interface(node, interface, **kwargs):
680         """Create a new VxLAN interface.
681
682         :param node: Honeycomb node.
683         :param interface: The name of interface.
684         :param kwargs: Parameters and their values. The accepted parameters are
685         defined in InterfaceKeywords.VXLAN_PARAMS.
686         :type node: dict
687         :type interface: str
688         :type kwargs: dict
689         :return: Content of response.
690         :rtype: bytearray
691         :raises HoneycombError: If the parameter is not valid.
692         """
693
694         new_vx_lan = {
695             "name": interface,
696             "type": "v3po:vxlan-tunnel",
697             "v3po:vxlan": {}
698         }
699         for param, value in kwargs.items():
700             if param not in InterfaceKeywords.VXLAN_PARAMS:
701                 raise HoneycombError("The parameter {0} is invalid.".
702                                      format(param))
703             new_vx_lan["v3po:vxlan"][param] = value
704
705         path = ("interfaces", "interface")
706         vx_lan_structure = [new_vx_lan, ]
707         return InterfaceKeywords._set_interface_properties(
708             node, interface, path, vx_lan_structure)
709
710     @staticmethod
711     def delete_interface(node, interface):
712         """Delete an interface.
713
714         :param node: Honeycomb node.
715         :param interface: The name of interface.
716         :type node: dict
717         :type interface: str
718         :return: Content of response.
719         :rtype: bytearray
720         :raises HoneycombError: If it is not possible to get information about
721         interfaces or it is not possible to delete the interface.
722         """
723
724         path = ("interfaces", ("interface", "name", interface))
725
726         status_code, resp = HcUtil.\
727             get_honeycomb_data(node, "config_vpp_interfaces")
728         if status_code != HTTPCodes.OK:
729             raise HoneycombError(
730                 "Not possible to get configuration information about the "
731                 "interfaces. Status code: {0}.".format(status_code))
732
733         new_data = HcUtil.remove_item(resp, path)
734         status_code, resp = HcUtil.\
735             put_honeycomb_data(node, "config_vpp_interfaces", new_data)
736         if status_code != HTTPCodes.OK:
737             raise HoneycombError("Not possible to remove interface {0}. "
738                                  "Status code: {1}.".
739                                  format(interface, status_code))
740         return resp
741
742     @staticmethod
743     def configure_interface_vxlan(node, interface, **kwargs):
744         """Configure VxLAN on the interface.
745
746         The keyword configures VxLAN parameters on the given interface. The type
747         of interface must be set to "v3po:vxlan-tunnel".
748         The new VxLAN parameters overwrite the current configuration. If a
749         parameter in new configuration is missing, it is removed from VxLAN
750         configuration.
751         If the dictionary kwargs is empty, VxLAN configuration is removed.
752
753         :param node: Honeycomb node.
754         :param interface: The name of interface.
755         :param kwargs: Parameters and their values. The accepted parameters are
756         defined in InterfaceKeywords.VXLAN_PARAMS.
757         :type node: dict
758         :type interface: str
759         :type kwargs: dict
760         :return: Content of response.
761         :rtype: bytearray
762         :raises HoneycombError: If the parameter is not valid.
763         """
764
765         vx_lan_structure = dict()
766         for param, value in kwargs.items():
767             if param not in InterfaceKeywords.VXLAN_PARAMS:
768                 raise HoneycombError("The parameter {0} is invalid.".
769                                      format(param))
770             vx_lan_structure[param] = value
771
772         path = ("interfaces", ("interface", "name", interface), "v3po:vxlan")
773         return InterfaceKeywords._set_interface_properties(
774             node, interface, path, vx_lan_structure)
775
776     @staticmethod
777     def configure_interface_l2(node, interface, param, value):
778         """Configure the L2 parameters of interface.
779
780         :param node: Honeycomb node.
781         :param interface: The name of interface.
782         :param param: Parameter to configure (set, change, remove)
783         :param value: The value of parameter. If None, the parameter will be
784         removed.
785         :type node: dict
786         :type interface: str
787         :type param: str
788         :type value: str
789         :return: Content of response.
790         :rtype: bytearray
791         :raises HoneycombError: If the parameter is not valid.
792         """
793
794         if param not in InterfaceKeywords.L2_PARAMS:
795             raise HoneycombError("The parameter {0} is invalid.".format(param))
796         path = ("interfaces", ("interface", "name", interface), "v3po:l2",
797                 param)
798         return InterfaceKeywords._set_interface_properties(
799             node, interface, path, value)
800
801     @staticmethod
802     def create_tap_interface(node, interface, **kwargs):
803         """Create a new TAP interface.
804
805         :param node: Honeycomb node.
806         :param interface: The name of interface.
807         :param kwargs: Parameters and their values. The accepted parameters are
808         defined in InterfaceKeywords.TAP_PARAMS.
809         :type node: dict
810         :type interface: str
811         :type kwargs: dict
812         :return: Content of response.
813         :rtype: bytearray
814         :raises HoneycombError: If the parameter is not valid.
815         """
816
817         new_tap = {
818             "name": interface,
819             "type": "v3po:tap",
820             "v3po:tap": {}
821         }
822         for param, value in kwargs.items():
823             if param not in InterfaceKeywords.TAP_PARAMS:
824                 raise HoneycombError("The parameter {0} is invalid.".
825                                      format(param))
826             new_tap["v3po:tap"][param] = value
827
828         path = ("interfaces", "interface")
829         new_tap_structure = [new_tap, ]
830         return InterfaceKeywords._set_interface_properties(
831             node, interface, path, new_tap_structure)
832
833     @staticmethod
834     def configure_interface_tap(node, interface, **kwargs):
835         """Configure TAP on the interface.
836
837         The keyword configures TAP parameters on the given interface. The type
838         of interface must be set to "v3po:tap".
839         The new TAP parameters overwrite the current configuration. If a
840         parameter in new configuration is missing, it is removed from TAP
841         configuration.
842         If the dictionary kwargs is empty, TAP configuration is removed.
843
844         :param node: Honeycomb node.
845         :param interface: The name of interface.
846         :param kwargs: Parameters and their values. The accepted parameters are
847         defined in InterfaceKeywords.TAP_PARAMS.
848         :type node: dict
849         :type interface: str
850         :type kwargs: dict
851         :return: Content of response.
852         :rtype: bytearray
853         :raises HoneycombError: If the parameter is not valid.
854         """
855
856         tap_structure = dict()
857         for param, value in kwargs.items():
858             if param not in InterfaceKeywords.TAP_PARAMS:
859                 raise HoneycombError("The parameter {0} is invalid.".
860                                      format(param))
861             tap_structure[param] = value
862
863         path = ("interfaces", ("interface", "name", interface), "v3po:tap")
864         return InterfaceKeywords._set_interface_properties(
865             node, interface, path, tap_structure)
866
867     @staticmethod
868     def configure_interface_vhost_user(node, interface, **kwargs):
869         """Configure vhost-user on the interface.
870
871         The keyword configures vhost-user parameters on the given interface.
872         The type of interface must be set to "v3po:vhost-user".
873         The new vhost-user parameters overwrite the current configuration. If a
874         parameter in new configuration is missing, it is removed from vhost-user
875         configuration.
876         If the dictionary kwargs is empty, vhost-user configuration is removed.
877
878         :param node: Honeycomb node.
879         :param interface: The name of interface.
880         :param kwargs: Parameters and their values. The accepted parameters are
881         defined in InterfaceKeywords.VHOST_USER_PARAMS.
882         :type node: dict
883         :type interface: str
884         :type kwargs: dict
885         :return: Content of response.
886         :rtype: bytearray
887         :raises HoneycombError: If the parameter is not valid.
888         """
889
890         vhost_structure = dict()
891         for param, value in kwargs.items():
892             if param not in InterfaceKeywords.VHOST_USER_PARAMS:
893                 raise HoneycombError("The parameter {0} is invalid.".
894                                      format(param))
895             vhost_structure[param] = value
896
897         path = ("interfaces", ("interface", "name", interface),
898                 "v3po:vhost-user")
899         return InterfaceKeywords._set_interface_properties(
900             node, interface, path, vhost_structure)
901
902     @staticmethod
903     def create_vhost_user_interface(node, interface, **kwargs):
904         """Create a new vhost-user interface.
905
906         :param node: Honeycomb node.
907         :param interface: The name of interface.
908         :param kwargs: Parameters and their values. The accepted parameters are
909         defined in InterfaceKeywords.VHOST_USER_PARAMS.
910         :type node: dict
911         :type interface: str
912         :type kwargs: dict
913         :return: Content of response.
914         :rtype: bytearray
915         :raises HoneycombError: If the parameter is not valid.
916         """
917
918         new_vhost = {
919             "name": interface,
920             "type": "v3po:vhost-user",
921             "v3po:vhost-user": {}
922         }
923         for param, value in kwargs.items():
924             if param not in InterfaceKeywords.VHOST_USER_PARAMS:
925                 raise HoneycombError("The parameter {0} is invalid.".
926                                      format(param))
927             new_vhost["v3po:vhost-user"][param] = value
928
929         path = ("interfaces", "interface")
930         new_vhost_structure = [new_vhost, ]
931         return InterfaceKeywords._set_interface_properties(
932             node, interface, path, new_vhost_structure)