logging.exception("API error.")
return ex.message, 500, CORS_HEADER
+class NetworkLAN(Resource):
+ """
+ Add or remove VNF interfaces to an existing LAN, by manipulating the vlan tag of the connected datacenter interface
+ :param vnf_name: VNF name of the source of the link
+ :param vnf_interface: VNF interface name of the source of the link
+ :param vlan_tag: vlan tag (integer > 0) or thsi interface
+ """
+ global net
+
+ def put(self):
+ logging.debug("REST CALL: network LAN add")
+
+ try:
+
+ data = request.json
+ if data is None:
+ data = request.args
+ if data is None:
+ data = {}
+
+ vnf_name = data.get("vnf_name")
+ vnf_interface = data.get("vnf_interface")
+ vlan_tag = data.get("vlan_tag")
+
+ vnf_list = [{'name':vnf_name, 'interface':vnf_interface}]
+
+ c = net.setLAN(vnf_list, vlan=vlan_tag, action='add')
+ # return setChain response
+ return str(c), 200, CORS_HEADER
+
+ except Exception as ex:
+ logging.exception("API error.")
+ return ex.message, 500, CORS_HEADER
+
+ def delete(self):
+ logging.debug("REST CALL: network LAN remove")
+
+ try:
+
+ data = request.json
+ if data is None:
+ data = request.args
+ if data is None:
+ data = {}
+
+ vnf_name = data.get("vnf_name")
+ vnf_interface = data.get("vnf_interface")
+ vlan_tag = data.get("vlan_tag")
+
+ vnf_list = [{'name': vnf_name, 'interface': vnf_interface}]
+
+ c = net.setLAN(vnf_list, vlan=vlan_tag, action='delete')
+ # return setChain response
+ return str(c), 200, CORS_HEADER
+
+ except Exception as ex:
+ logging.exception("API error.")
+ return ex.message, 500, CORS_HEADER
class DrawD3jsgraph(Resource):
# need to import total module to set its global variable net
import network
-from network import NetworkAction, DrawD3jsgraph
+from network import NetworkAction, NetworkLAN, DrawD3jsgraph
import monitor
from monitor import MonitorInterfaceAction, MonitorFlowAction, MonitorLinkAction, MonitorSkewAction, MonitorTerminal
# network related actions (setup chaining between VNFs)
self.api.add_resource(NetworkAction,
"/restapi/network")
+ self.api.add_resource(NetworkLAN,
+ "/restapi/networkLAN")
self.api.add_resource(DrawD3jsgraph,
"/restapi/network/d3jsgraph")
params=params)
print(self._nice_print(response.text))
+ def addLAN(self, args):
+ params = self._create_dict(
+ vnf_name=self._parse_vnf_name(args.get("source")),
+ vnf_interface=self._parse_vnf_interface(args.get("source")),
+ vlan_tag=args.get("vlan"))
+
+ response = put("{0}/restapi/networkLAN".format(args.get("endpoint")),
+ params=params)
+ print(self._nice_print(response.text))
+
+ def removeLAN(self, args):
+ params = self._create_dict(
+ vnf_src_name=self._parse_vnf_name(args.get("source")),
+ vnf_src_interface=self._parse_vnf_interface(args.get("source")),
+ vlan=args.get("vlan"))
+
+ response = delete("{0}/restapi/networkLAN".format(args.get("endpoint")),
+ params=params)
+ print(self._nice_print(response.text))
+
def _parse_vnf_name(self, vnf_name_str):
vnf_name = vnf_name_str.split(':')[0]
return vnf_name
parser = argparse.ArgumentParser(description='son-emu-cli network')
parser.add_argument(
"command",
- choices=['add', 'remove'],
+ choices=['add', 'remove', 'addLAN', 'removeLAN'],
help="Action to be executed.")
parser.add_argument(
"--datacenter", "-d", dest="datacenter",
help="Data center to in which the network action should be initiated")
parser.add_argument(
"--source", "-src", dest="source",
- help="vnf name of the source of the chain")
+ help="vnf name:interface of the source of the chain")
parser.add_argument(
"--destination", "-dst", dest="destination",
- help="vnf name of the destination of the chain")
+ help="vnf name:interface of the destination of the chain")
parser.add_argument(
"--weight", "-w", dest="weight",
help="weight edge attribute to calculate the path")
parser.add_argument(
"--cookie", "-c", dest="cookie", default="10",
help="cookie for this flow, as easy to use identifier (eg. per tenant/service)")
+parser.add_argument(
+ "--vlan", "-vl", dest="vlan",
+ help="vlan tag to be used with the specified LAN interface")
parser.add_argument(
"--endpoint", "-e", dest="endpoint",
default="http://127.0.0.1:5001",