+class EmulatorExtSAP(object):
+ """
+ Emulator specific class that defines an external service access point (SAP) for the service.
+ Inherits from Containernet's OVSBridge class.
+ Represents a single OVS switch connected to a (logical)
+ data center.
+ We can add emulator specific helper functions to it.
+ """
+
+ def __init__(self, sap_name, sap_net, datacenter, **kwargs):
+
+ self.datacenter = datacenter # pointer to current DC
+ self.net = self.datacenter.net
+ self.name = sap_name
+
+ LOG.debug("Starting ext SAP instance %r in data center %r" %
+ (sap_name, str(self.datacenter)))
+
+ # create SAP as separate OVS switch with an assigned ip address
+ self.ip = str(sap_net[1]) + '/' + str(sap_net.prefixlen)
+ self.subnet = sap_net
+ # allow connection to the external internet through the host
+ params = dict(NAT=True)
+ self.switch = self.net.addExtSAP(sap_name, self.ip, dpid=hex(
+ self._get_next_extSAP_dpid())[2:], **params)
+ self.switch.start()
+
+ def _get_next_extSAP_dpid(self):
+ global EXTSAPDPID_BASE
+ EXTSAPDPID_BASE += 1
+ return EXTSAPDPID_BASE
+
+ def getNetworkStatus(self):
+ """
+ Helper method to receive information about the virtual networks
+ this compute instance is connected to.
+ """
+ # get all links and find dc switch interface
+ networkStatusList = []
+ for i in self.switch.intfList():
+ vnf_name = self.name
+ vnf_interface = str(i)
+ if vnf_interface == 'lo':
+ continue
+ dc_port_name = self.datacenter.net.find_connected_dc_interface(
+ vnf_name, vnf_interface)
+ # format list of tuples (name, Ip, MAC, isUp, status, dc_portname)
+ intf_dict = {'intf_name': str(i), 'ip': self.ip, 'netmask': i.prefixLen, 'mac': i.MAC(
+ ), 'up': i.isUp(), 'status': i.status(), 'dc_portname': dc_port_name}
+ networkStatusList.append(intf_dict)
+
+ return networkStatusList
+
+ def getStatus(self):
+ return {
+ "name": self.switch.name,
+ "datacenter": self.datacenter.name,
+ "network": self.getNetworkStatus()
+ }
+
+