[CORD-3184] Adding compute-nodes to fabric config

Change-Id: Ief7158e635cae5df89a3bbd6c210e625bc7bb1fc
diff --git a/.gitignore b/.gitignore
index 1163cb2..7bf4b4d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,5 @@
 .idea
-*.pyc
\ No newline at end of file
+*.pyc
+
+xos/.coverage
+xos/htmlcov
\ No newline at end of file
diff --git a/docs/README.md b/docs/README.md
index 9374bc2..20e0bee 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -52,3 +52,130 @@
             node: port#port1
             relationship: tosca.relationships.BelongsToOne
 ```
+
+## How to attach Compute Nodes to the Fabric
+
+Assuming that you have the above mentioned fabric configuration
+and you want to attach a two compute nodes to the fabric,
+assuming that that:
+
+- `node1.cord.lab` has ip `10.6.1.17` on interface `fabricbridge` and it is attached to port `17` on the switch `leaf1` (and has a route like `10.6.2.0/24 via 10.6.1.254 dev fabricbridge` or the default route is pointing to the fabric)
+- `node2.cord.lab` has ip `10.6.2.18` on interface `fabricbridge` and it is attached to port `18` on the switch `leaf1` (and has a route like `10.6.1.0/24 via 10.6.2.254 dev fabricbridge` or the default route is pointing to the fabric)
+
+you can use the following TOSCA recipe to:
+
+- add the Nodes to XOS
+- add the two Ports to the Switch
+- associate each Node to a Port
+
+```yaml
+tosca_definitions_version: tosca_simple_yaml_1_0
+description: Set up Fabric service and attach it to ONOS (note that onos-service needs to be loaded)
+imports:
+  - custom_types/node.yaml
+  - custom_types/nodetoswitchport.yaml
+  - custom_types/switch.yaml
+  - custom_types/switchport.yaml
+  - custom_types/deployment.yaml
+  - custom_types/site.yaml
+  - custom_types/sitedeployment.yaml
+
+topology_template:
+  node_templates:
+
+    # nodes
+    node#node1:
+        type: tosca.nodes.Node
+        properties:
+            dataPlaneIntf: fabricbridge
+            dataPlaneIp: 10.6.1.17/24
+            name: node1.cord.lab
+        requirements:
+            - site_deployment:
+                node: site_deployment
+                relationship: tosca.relationships.BelongsToOne
+    
+    node#node2:
+        type: tosca.nodes.Node
+        properties:
+            dataPlaneIntf: fabricbridge
+            dataPlaneIp: 10.6.2.18/24
+            name: node2.cord.lab
+        requirements:
+            - site_deployment:
+                node: site_deployment
+                relationship: tosca.relationships.BelongsToOne
+
+    # ports (defined in the above recipe)
+    switch#leaf1:
+      type: tosca.nodes.Switch
+      properties:
+        name: leaf1
+        must-exist: true
+    
+    port#port17:
+      type: tosca.nodes.SwitchPort
+      properties:
+        portId: 17
+      requirements:
+        - switch:
+            node: switch#leaf1
+            relationship: tosca.relationships.BelongsToOne
+    
+    port#port18:
+      type: tosca.nodes.SwitchPort
+      properties:
+        portId: 18
+      requirements:
+        - switch:
+            node: switch#leaf1
+            relationship: tosca.relationships.BelongsToOne
+
+    # attaching nodes to ports
+    node1_to_port17:
+        type: tosca.nodes.NodeToSwitchPort
+        requirements:
+            - port:
+                node: port#port17
+                relationship: tosca.relationships.BelongsToOne
+            - node:
+                node: node#node1
+                relationship: tosca.relationships.BelongsToOne
+    
+    node2_to_port18:
+        type: tosca.nodes.NodeToSwitchPort
+        requirements:
+            - port:
+                node: port#port18
+                relationship: tosca.relationships.BelongsToOne
+            - node:
+                node: node#node2
+                relationship: tosca.relationships.BelongsToOne
+
+    # extra setup required by XOS (note that this needs to be customized to your installation)
+    mySite:
+      type: tosca.nodes.Site
+      properties:
+          name: mySite
+          login_base: opencord
+          abbreviated_name: ms
+          site_url: http://opencord.org/
+          hosts_nodes: true
+
+    myDeployment:
+      type: tosca.nodes.Deployment
+      properties:
+        name: myDeployment
+
+    site_deployment:
+      type: tosca.nodes.SiteDeployment
+      requirements:
+        - site:
+            node: mySite
+            relationship: tosca.relationships.BelongsToOne
+        - deployment:
+            node: myDeployment
+            relationship: tosca.relationships.BelongsToOne
+```
+
+This will cause the correct fabric configuration to be generated and pushed to the fabric.
diff --git a/samples/fabric.yaml b/samples/fabric-config.yaml
similarity index 95%
rename from samples/fabric.yaml
rename to samples/fabric-config.yaml
index f61a3b7..63ba218 100644
--- a/samples/fabric.yaml
+++ b/samples/fabric-config.yaml
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# curl -H "xos-username: admin@opencord.org" -H "xos-password: letmein" -X POST --data-binary @fabric.yaml http://192.168.99.100:30007/run
+# curl -H "xos-username: admin@opencord.org" -H "xos-password: letmein" -X POST --data-binary @fabric-config.yaml http://192.168.99.100:30007/run
 
 tosca_definitions_version: tosca_simple_yaml_1_0
 imports:
diff --git a/samples/nodes.yaml b/samples/nodes.yaml
new file mode 100644
index 0000000..578410a
--- /dev/null
+++ b/samples/nodes.yaml
@@ -0,0 +1,126 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# curl -H "xos-username: admin@opencord.org" -H "xos-password: letmein" -X POST --data-binary @nodes.yaml http://192.168.99.100:30007/run
+
+tosca_definitions_version: tosca_simple_yaml_1_0
+description: Set up Fabric service and attach it to ONOS (note that onos-service needs to be loaded)
+imports:
+  - custom_types/node.yaml
+  - custom_types/nodetoswitchport.yaml
+  - custom_types/switch.yaml
+  - custom_types/switchport.yaml
+  - custom_types/deployment.yaml
+  - custom_types/site.yaml
+  - custom_types/sitedeployment.yaml
+
+topology_template:
+  node_templates:
+
+    # nodes
+    node#node1:
+        type: tosca.nodes.Node
+        properties:
+            dataPlaneIntf: fabricbridge
+            dataPlaneIp: 10.6.1.1/24
+            name: node1.cord.lab
+        requirements:
+            - site_deployment:
+                node: site_deployment
+                relationship: tosca.relationships.BelongsToOne
+
+
+    node#node2:
+        type: tosca.nodes.Node
+        properties:
+            dataPlaneIntf: fabricbridge
+            dataPlaneIp: 10.6.1.2/24
+            name: node2.cord.lab
+        requirements:
+            - site_deployment:
+                node: site_deployment
+                relationship: tosca.relationships.BelongsToOne
+
+    # ports (defined in fabric-config.yaml)
+    switch#leaf1:
+      type: tosca.nodes.Switch
+      properties:
+        name: leaf1
+        must-exist: true
+    
+    port#port1:
+      type: tosca.nodes.SwitchPort
+      properties:
+        portId: 1
+        must-exist: true
+      requirements:
+        - switch:
+            node: switch#leaf1
+            relationship: tosca.relationships.BelongsToOne
+    
+    port#port2:
+      type: tosca.nodes.SwitchPort
+      properties:
+        portId: 2
+        must-exist: true
+      requirements:
+        - switch:
+            node: switch#leaf1
+            relationship: tosca.relationships.BelongsToOne
+
+    # attaching nodes to ports
+    node1_to_port1:
+        type: tosca.nodes.NodeToSwitchPort
+        requirements:
+            - port:
+                node: port#port1
+                relationship: tosca.relationships.BelongsToOne
+            - node:
+                node: node#node1
+                relationship: tosca.relationships.BelongsToOne
+    
+    node2_to_port2:
+        type: tosca.nodes.NodeToSwitchPort
+        requirements:
+            - port:
+                node: port#port2
+                relationship: tosca.relationships.BelongsToOne
+            - node:
+                node: node#node2
+                relationship: tosca.relationships.BelongsToOne
+
+    # extra setup required by XOS
+    mySite:
+      type: tosca.nodes.Site
+      properties:
+          name: mySite
+          login_base: opencord
+          abbreviated_name: ms
+          site_url: http://opencord.org/
+          hosts_nodes: true
+
+    myDeployment:
+      type: tosca.nodes.Deployment
+      properties:
+        name: myDeployment
+
+    site_deployment:
+      type: tosca.nodes.SiteDeployment
+      requirements:
+        - site:
+            node: mySite
+            relationship: tosca.relationships.BelongsToOne
+        - deployment:
+            node: myDeployment
+            relationship: tosca.relationships.BelongsToOne
\ No newline at end of file
diff --git a/samples/service.yaml b/samples/service.yaml
new file mode 100644
index 0000000..5944808
--- /dev/null
+++ b/samples/service.yaml
@@ -0,0 +1,51 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# curl -H "xos-username: admin@opencord.org" -H "xos-password: letmein" -X POST --data-binary @service.yaml http://192.168.99.100:30007/run
+
+tosca_definitions_version: tosca_simple_yaml_1_0
+description: Set up Fabric service and attach it to ONOS (note that onos-service needs to be loaded)
+imports:
+  - custom_types/fabricservice.yaml
+  - custom_types/onosservice.yaml
+  - custom_types/servicedependency.yaml
+
+topology_template:
+  node_templates:
+
+    service#ONOS_Fabric:
+      type: tosca.nodes.ONOSService
+      properties:
+          name: ONOS_Fabric
+          kind: platform
+          rest_hostname: onos-fabric-ui
+          rest_port: 8181
+
+    service#fabric:
+      type: tosca.nodes.FabricService
+      properties:
+        name: fabric
+        kind: platform
+
+    service_dependency#onos-fabric_fabric:
+      type: tosca.nodes.ServiceDependency
+      properties:
+        connect_method: None
+      requirements:
+        - subscriber_service:
+            node: service#ONOS_Fabric
+            relationship: tosca.relationships.BelongsToOne
+        - provider_service:
+            node: service#fabric
+            relationship: tosca.relationships.BelongsToOne
\ No newline at end of file
diff --git a/xos/synchronizer/config.yaml b/xos/synchronizer/config.yaml
index 43b075c..c845316 100644
--- a/xos/synchronizer/config.yaml
+++ b/xos/synchronizer/config.yaml
@@ -20,6 +20,7 @@
 steps_dir: "/opt/xos/synchronizers/fabric/steps"
 sys_dir: "/opt/xos/synchronizers/fabric/sys"
 models_dir: "/opt/xos/synchronizers/fabric/models"
+model_policies_dir: "/opt/xos/synchronizers/fabric/model_policies"
 logging:
   version: 1
   handlers:
diff --git a/xos/synchronizer/model_policies/model_policy_compute_nodes.py b/xos/synchronizer/model_policies/model_policy_compute_nodes.py
new file mode 100644
index 0000000..91efd40
--- /dev/null
+++ b/xos/synchronizer/model_policies/model_policy_compute_nodes.py
@@ -0,0 +1,100 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import ipaddress
+import random
+from synchronizers.new_base.modelaccessor import NodeToSwitchPort, PortInterface, model_accessor
+from synchronizers.new_base.policy import Policy
+
+from xosconfig import Config
+from multistructlog import create_logger
+
+from helpers import Helpers
+
+log = create_logger(Config().get('logging'))
+
+class ComputeNodePolicy(Policy):
+    model_name = "NodeToSwitchPort"
+
+    @staticmethod
+    def getLastAddress(network):
+        return str(network.network_address + network.num_addresses - 2) + "/" + str(network.prefixlen)
+        # return ipaddress.ip_interface(network.network_address + network.num_addresses - 2)
+
+    @staticmethod
+    def getPortCidrByIp(ip):
+        interface = ipaddress.ip_interface(ip)
+        network = ipaddress.ip_network(interface.network)
+        cidr = ComputeNodePolicy.getLastAddress(network)
+        return cidr
+
+    @staticmethod
+    def generateVlan(used_vlans):
+        availabel_tags = range(16, 4093)
+        valid_tags = list(set(availabel_tags) - set(used_vlans))
+        if len(valid_tags) == 0:
+            raise Exception("No VLANs left")
+        return random.choice(valid_tags)
+
+    @staticmethod
+    def getVlanByCidr(subnet):
+        # vlanUntagged is unique per subnet
+        same_subnet_ifaces = PortInterface.objects.filter(ips=str(subnet))
+
+        if len(same_subnet_ifaces) > 0:
+            return same_subnet_ifaces[0].vlanUntagged
+        else:
+            PortInterface.objects.all()
+            used_vlans = list(set([i.vlanUntagged for i in same_subnet_ifaces]))
+            log.info("MODEL_POLICY: used vlans", vlans=used_vlans, subnet=subnet)
+            return ComputeNodePolicy.generateVlan(used_vlans)
+
+    def handle_create(self, node_to_port):
+        return self.handle_update(node_to_port)
+
+    def handle_update(self, node_to_port):
+        log.info("MODEL_POLICY: NodeToSwitchPort %s handle update" % node_to_port.id, node=node_to_port.node, port=node_to_port.port, switch=node_to_port.port.switch)
+
+        compute_node = node_to_port.node
+
+        cidr = ComputeNodePolicy.getPortCidrByIp(compute_node.dataPlaneIp)
+
+        # check if an interface already exists
+        try:
+            PortInterface.objects.get(
+                port_id=node_to_port.port.id,
+                name=compute_node.dataPlaneIntf,
+                ips=str(cidr)
+            )
+        except IndexError:
+
+            vlan = self.getVlanByCidr(cidr)
+
+            log.info("MODEL_POLICY: choosen vlan", vlan=vlan, cidr=cidr)
+
+            interface = PortInterface(
+                port_id=node_to_port.port.id,
+                name=compute_node.dataPlaneIntf,
+                ips=str(cidr),
+                vlanUntagged=vlan
+            )
+
+            interface.save()
+        
+        # TODO if the model is updated I need to remove the old interface, how?
+
+
+    def handle_delete(self, node_to_port):
+        pass
diff --git a/xos/synchronizer/model_policies/test_model_policy_compute_node.py b/xos/synchronizer/model_policies/test_model_policy_compute_node.py
new file mode 100644
index 0000000..4586a71
--- /dev/null
+++ b/xos/synchronizer/model_policies/test_model_policy_compute_node.py
@@ -0,0 +1,198 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import unittest
+import ipaddress
+from mock import patch, call, Mock, PropertyMock
+
+import os, sys
+
+test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+service_dir=os.path.join(test_path, "../../../..")
+xos_dir=os.path.join(test_path, "../../..")
+if not os.path.exists(os.path.join(test_path, "new_base")):
+    xos_dir=os.path.join(test_path, "../../../../../../orchestration/xos/xos")
+    services_dir=os.path.join(xos_dir, "../../xos_services")
+
+# While transitioning from static to dynamic load, the path to find neighboring xproto files has changed. So check
+# both possible locations...
+def get_models_fn(service_name, xproto_name):
+    name = os.path.join(service_name, "xos", xproto_name)
+    if os.path.exists(os.path.join(services_dir, name)):
+        return name
+    else:
+        name = os.path.join(service_name, "xos", "synchronizer", "models", xproto_name)
+        if os.path.exists(os.path.join(services_dir, name)):
+            return name
+    raise Exception("Unable to find service=%s xproto=%s" % (service_name, xproto_name))
+
+class TestComputeNodePolicy(unittest.TestCase):
+    def setUp(self):
+        global ComputeNodePolicy, MockObjectList
+
+        self.sys_path_save = sys.path
+        sys.path.append(xos_dir)
+        sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
+
+        config = os.path.join(test_path, "../test_config.yaml")
+        from xosconfig import Config
+        Config.clear()
+        Config.init(config, 'synchronizer-config-schema.yaml')
+
+        from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
+        build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("fabric", "fabric.xproto")])
+
+        import synchronizers.new_base.modelaccessor
+
+        from model_policy_compute_nodes import ComputeNodePolicy, model_accessor
+
+        from mock_modelaccessor import MockObjectList
+
+        # import all class names to globals
+        for (k, v) in model_accessor.all_model_classes.items():
+            globals()[k] = v
+
+        # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to creation of
+        # tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world.
+        model_accessor.reset_all_object_stores()
+
+        self.policy = ComputeNodePolicy
+        self.model = Mock()
+
+    def tearDown(self):
+        sys.path = self.sys_path_save
+
+    def test_getLastAddress(self):
+
+        dataPlaneIp = unicode("10.6.1.2/24", "utf-8")
+        interface = ipaddress.ip_interface(dataPlaneIp)
+        subnet = ipaddress.ip_network(interface.network)
+        last_ip = self.policy.getLastAddress(subnet)
+        self.assertEqual(str(last_ip), "10.6.1.254/24")
+
+    def test_generateVlan(self):
+
+        used_vlans = range(16, 4093)
+        used_vlans.remove(1000)
+
+        vlan = self.policy.generateVlan(used_vlans)
+
+        self.assertEqual(vlan, 1000)
+
+    def test_generateVlanFail(self):
+
+        used_vlans = range(16, 4093)
+
+        with self.assertRaises(Exception) as e:
+            self.policy.generateVlan(used_vlans)
+
+        self.assertEqual(e.exception.message, "No VLANs left")
+
+    def test_getVlanByCidr_same_subnet(self):
+
+        mock_pi_ip = unicode("10.6.1.2/24", "utf-8")
+        
+        mock_pi = Mock()
+        mock_pi.vlanUntagged = 1234
+        mock_pi.ips = str(self.policy.getPortCidrByIp(mock_pi_ip))
+
+        test_ip = unicode("10.6.1.1/24", "utf-8")
+        test_subnet = self.policy.getPortCidrByIp(test_ip)
+
+        with patch.object(PortInterface.objects, "get_items") as get_pi:
+
+            get_pi.return_value = [mock_pi]
+            vlan = self.policy.getVlanByCidr(test_subnet)
+
+            self.assertEqual(vlan, mock_pi.vlanUntagged)
+
+    def test_getVlanByCidr_different_subnet(self):
+
+        mock_pi_ip = unicode("10.6.1.2/24", "utf-8")
+        mock_pi = Mock()
+        mock_pi.vlanUntagged = 1234
+        mock_pi.ips = str(self.policy.getPortCidrByIp(mock_pi_ip))
+
+        test_ip = unicode("192.168.1.1/24", "utf-8")
+        test_subnet = self.policy.getPortCidrByIp(test_ip)
+
+        with patch.object(PortInterface.objects, "get_items") as get_pi:
+
+            get_pi.return_value = [mock_pi]
+            vlan = self.policy.getVlanByCidr(test_subnet)
+
+            self.assertNotEqual(vlan, mock_pi.vlanUntagged)
+
+    def test_handle_create(self):
+
+        policy = self.policy()
+        with patch.object(policy, "handle_update") as handle_update:
+            policy.handle_create(self.model)
+            handle_update.assert_called_with(self.model)
+
+    def test_handle_update_do_nothing(self):
+
+        mock_pi_ip = unicode("10.6.1.2/24", "utf-8")
+        mock_pi = Mock()
+        mock_pi.port_id = 1
+        mock_pi.name = "test_interface"
+        mock_pi.ips = str(self.policy.getPortCidrByIp(mock_pi_ip))
+
+        policy = self.policy()
+
+        self.model.port.id = 1
+        self.model.node.dataPlaneIntf = "test_interface"
+
+        with patch.object(PortInterface.objects, "get_items") as get_pi, \
+            patch.object(self.policy, "getPortCidrByIp") as get_subnet, \
+            patch.object(PortInterface, 'save') as mock_save:
+
+            get_pi.return_value = [mock_pi]
+            get_subnet.return_value = mock_pi.ips
+
+            policy.handle_update(self.model)
+
+            mock_save.assert_not_called()
+
+    def test_handle_update(self):
+
+        policy = self.policy()
+
+        self.model.port.id = 1
+        self.model.node.dataPlaneIntf = "test_interface"
+        self.model.node.dataPlaneIp = unicode("10.6.1.2/24", "utf-8")
+
+        with patch.object(PortInterface.objects, "get_items") as get_pi, \
+            patch.object(self.policy, "getVlanByCidr") as get_vlan, \
+            patch.object(PortInterface, "save", autospec=True) as mock_save:
+
+            get_pi.return_value = []
+            get_vlan.return_value = "1234"
+
+            policy.handle_update(self.model)
+
+            self.assertEqual(mock_save.call_count, 1)
+            pi = mock_save.call_args[0][0]
+
+            self.assertEqual(pi.name, self.model.node.dataPlaneIntf)
+            self.assertEqual(pi.port_id, self.model.port.id)
+            self.assertEqual(pi.vlanUntagged, "1234")
+            self.assertEqual(pi.ips, "10.6.1.254/24")
+
+
+if __name__ == '__main__':
+    unittest.main()
+
diff --git a/xos/synchronizer/models/fabric.xproto b/xos/synchronizer/models/fabric.xproto
index 71ad3ee..95c4539 100644
--- a/xos/synchronizer/models/fabric.xproto
+++ b/xos/synchronizer/models/fabric.xproto
@@ -32,6 +32,14 @@
 
     required manytoone port->SwitchPort:interfaces = 1 [help_text = "The fabric switch port the interface belongs to", db_index = True, null = False, blank = False];
     required string name = 2 [help_text = "The unique name of the fabric switch port", max_length = 254, null = False, db_index = False, blank = False];
-    required string ips = 3 [help_text = "The interface IP address (xxx.yyy.www.zzz/nm)", max_length = 20, null = False, db_index = False, blank = False];
+    required string ips = 3 [help_text = "The interface IP address (xxx.yyy.www.zzz/nm)", max_length = 20, null = False, db_index = False, blank = False, unique_with = "port"];
     optional int32 vlanUntagged = 4 [help_text = "The optional untagged VLAN ID for the interface", max_length = 20, null = True, db_index = False, blank = True];
+}
+
+message NodeToSwitchPort(XOSBase) {
+    option verbose_name = "Node to switch port";
+    option description = "Compute Node connection to a Fabric switch port";
+
+    required manytoone port->SwitchPort:node_to_switch_ports = 1 [help_text = "The fabric switch port the node is connected to", db_index = True, null = False, blank = False, tosca_key=True];
+    required manytoone node->Node:node_to_switch_ports = 2 [help_text = "The ComputeNode this port is connected to", db_index = True, null = False, blank = False, tosca_key=True];
 }
\ No newline at end of file
diff --git a/xos/unittest.cfg b/xos/unittest.cfg
index 48ea867..ed0e14f 100644
--- a/xos/unittest.cfg
+++ b/xos/unittest.cfg
@@ -2,3 +2,9 @@
 plugins=nose2-plugins.exclude
 code-directories=synchronizer
                  steps
+                 model_policies
+[coverage]
+always-on = True
+coverage = synchronizer
+coverage-report = term
+coverage-report = html
\ No newline at end of file