CORD-2899 send all relavant neutron information to vtn onos app

Change-Id: I23d472dddb01fcfc0c5ef1c7c516b02e74bf1e8e
diff --git a/xos/synchronizer/steps/sync_vtn_service.py b/xos/synchronizer/steps/sync_vtn_service.py
index e4d4b4f..0874978 100644
--- a/xos/synchronizer/steps/sync_vtn_service.py
+++ b/xos/synchronizer/steps/sync_vtn_service.py
@@ -22,10 +22,13 @@
 from synchronizers.vtn.vtnnetport import VTNNetwork, VTNPort
 from synchronizers.new_base.syncstep import SyncStep
 from synchronizers.new_base.modelaccessor import *
-from xos.logger import Logger, logging
 from requests.auth import HTTPBasicAuth
 
-logger = Logger(level=logging.INFO)
+from xosconfig import Config
+from multistructlog import create_logger
+
+log = create_logger(Config().get('logging'))
+
 
 # XXX should save and load this
 glo_saved_networks = {}
@@ -47,14 +50,14 @@
                 continue
 
             # TODO: Rather than checking model name, check for the right interface
-            # NOTE: Deferred until new Tosca engine is in place.
+            # NOTE: Deferred until service interfaces are revisited
 
             #if not link.provider_service_interface:
-            #    logger.warning("Link %s does not have a provider_service_interface. Skipping" % link)
+            #    log.warning("Link %s does not have a provider_service_interface. Skipping" % link)
             #    continue
             #
             #if link.provider_service_interface.interface_type.name != "onos_app_interface":
-            #    logger.warning("Link %s provider_service_interface type is not equal to onos_app_interface" % link)
+            #    log.warning("Link %s provider_service_interface type is not equal to onos_app_interface" % link)
             #    continue
 
             # cast from ServiceInstance to ONOSApp
@@ -104,48 +107,55 @@
             network = VTNNetwork(network)
 
             if not network.id:
+                log.info("Skipping network because it has no id")
                 continue
 
-            if (network.type=="PRIVATE") and (not network.providerNetworks):
-                logger.info("Skipping network %s because it has no relevant state" % network.id)
+            if (not network.subnet):
+                log.info("Skipping network %s because it has no subnet" % network.id)
+                continue
+
+            if (not network.segmentation_id):
+                log.info("Skipping network %s because it has no segmentation id" % network.id)
                 continue
 
             valid_ids.append(network.id)
 
-            if (glo_saved_networks.get(network.id, None) != network.to_dict()):
+            # clean the providerNetworks list to what the VTN App expects
+            providerNetworks = [{"id": x["id"], "bidirectional": x["bidirectional"]} for x in network.providerNetworks]
+
+            # This is the data we will be sending ONOS
+            data = {"ServiceNetwork": {"id": network.id,
+                                       "name": network.name,
+                                       "type": network.type,
+                                       "segment_id": network.segmentation_id,
+                                       "subnet": network.subnet,
+                                       "service_ip": network.gateway,
+                                       "providerNetworks": providerNetworks}}
+
+            if (glo_saved_networks.get(network.id, None) != data):
                 (exists, url, method, req_func) = self.get_method(onos_auth, "http://%s:%d/onos/cordvtn/serviceNetworks" % (onos_hostname, onos_port), network.id)
 
-                logger.info("%sing VTN API for network %s" % (method, network.id))
-
-                logger.info("URL: %s" % url)
-
-                # clean the providerNetworks list
-                providerNetworks = [{"id": x["id"], "bidirectional": x["bidirectional"]} for x in network.providerNetworks]
-
-                data = {"ServiceNetwork": {"id": network.id,
-                        "type": network.type,
-                        "providerNetworks": providerNetworks} }
-                logger.info("DATA: %s" % str(data))
+                log.info("%sing VTN API for network %s" % (method, network.id), url=url, data=data)
 
                 r=req_func(url, json=data, auth=onos_auth )
                 if (r.status_code in [200,201]):
-                    glo_saved_networks[network.id] = network.to_dict()
+                    glo_saved_networks[network.id] = data
                 else:
-                    logger.error("Received error from vtn service (%d)" % r.status_code)
+                    log.error("Received error from vtn service (%d)" % r.status_code)
 
 
         for network_id in glo_saved_networks.keys():
             if network_id not in valid_ids:
-                logger.info("DELETEing VTN API for network %s" % network_id)
+                log.info("DELETEing VTN API for network %s" % network_id)
 
                 url = "http://%s:%d/onos/cordvtn/serviceNetworks/%s" % (onos_hostname, onos_port, network_id)
-                logger.info("URL: %s" % url)
+                log.info("URL: %s" % url)
 
                 r = requests.delete(url, auth=onos_auth )
                 if (r.status_code in [200,204]):
                     del glo_saved_networks[network_id]
                 else:
-                    logger.error("Received error from vtn service (%d)" % r.status_code)
+                    log.error("Received error from vtn service (%d)" % r.status_code)
 
     def sync_service_ports(self, vtn_service):
         (onos_hostname, onos_port, onos_auth) = self.get_vtn_endpoint(vtn_service)
@@ -155,44 +165,56 @@
             port = VTNPort(port)
 
             if not port.id:
+                log.info("Skipping port because it has no id")
                 continue
 
-            if (not port.vlan_id) and (not port.floating_address_pairs):
-                logger.info("Skipping port %s because it has no relevant state" % port.id)
+            if (not port.network_id):
+                log.info("Skipping port %s because it is missing network_id" % port.id)
+                continue
+
+            if (not port.mac_address):
+                log.info("Skipping port %s because it is missing mac_address" % port.id)
+                continue
+
+            if (not port.ip_address):
+                log.info("Skipping port %s because it is missing ip_address" % port.id)
                 continue
 
             valid_ids.append(port.id)
 
-            if (glo_saved_ports.get(port.id, None) != port.to_dict()):
+            # This is the data we will be sending ONOS
+            data = {"ServicePort": {"id": port.id,
+                                    "name": port.name,
+                                    "network_id": port.network_id,
+                                    "mac_address": port.mac_address,
+                                    "ip_address": port.ip_address,
+                                    "floating_address_pairs": port.floating_address_pairs}}
+            if port.vlan_id:
+                data["ServicePort"]["vlan_id"] = port.vlan_id
+
+            if (glo_saved_ports.get(port.id, None) != data):
                 (exists, url, method, req_func) = self.get_method(onos_auth, "http://%s:%d/onos/cordvtn/servicePorts" % (onos_hostname, onos_port), port.id)
 
-                logger.info("%sing VTN API for port %s" % (method, port.id))
-
-                logger.info("URL: %s" % url)
-
-                data = {"ServicePort": {"id": port.id,
-                        "vlan_id": port.vlan_id,
-                        "floating_address_pairs": port.floating_address_pairs} }
-                logger.info("DATA: %s" % str(data))
+                log.info("%sing VTN API for port %s" % (method, port.id), url=url, data=data)
 
                 r=req_func(url, json=data, auth=onos_auth )
                 if (r.status_code in [200,201]):
-                    glo_saved_ports[port.id] = port.to_dict()
+                    glo_saved_ports[port.id] = data
                 else:
-                    logger.error("Received error from vtn service (%d)" % r.status_code)
+                    log.error("Received error from vtn service (%d)" % r.status_code)
 
         for port_id in glo_saved_ports.keys():
             if port_id not in valid_ids:
-                logger.info("DELETEing VTN API for port %s" % port_id)
+                log.info("DELETEing VTN API for port %s" % port_id)
 
                 url = "http://%s:%d/onos/cordvtn/servicePorts/%s" % (onos_hostname, onos_port, port_id)
-                logger.info("URL: %s" % url)
+                log.info("URL: %s" % url)
 
                 r = requests.delete(url, auth=onos_auth )
                 if (r.status_code in [200,204]):
                     del glo_saved_ports[port_id]
                 else:
-                    logger.error("Received error from vtn service (%d)" % r.status_code)
+                    log.error("Received error from vtn service (%d)" % r.status_code)
 
     def call(self, **args):
         global glo_saved_networks
@@ -218,7 +240,6 @@
 
         if vtn_service.vtnAPIVersion>=2:
             # version 2 means use new API
-            logger.info("Using New API")
             self.sync_service_networks(vtn_service)
             self.sync_service_ports(vtn_service)
         else:
diff --git a/xos/synchronizer/vtnnetport.py b/xos/synchronizer/vtnnetport.py
index eaa037f..7194f45 100644
--- a/xos/synchronizer/vtnnetport.py
+++ b/xos/synchronizer/vtnnetport.py
@@ -225,7 +225,7 @@
 
         if not self.is_access_network():
             # If not an access network, do not apply any tags
-            return []
+            return None
 
         if not self.xos_port.instance:
             return None
@@ -264,7 +264,10 @@
 
     @property
     def name(self):
-        return "port-%s" % self.xos_port.id
+        # In OpenStack Kilo, the tap name uses the first 11 characters of the port id. Unverified if this is true for
+        # any other OpenStack.
+        return "tap" + self.xos_port.port_id[:11]
+        #return self.xos_port.name
 
     @property
     def network_id(self):