1. Modified testOfOverlay and odl-gbp to support multiple contracts 56/12956/4
authorKeith Burns (alagalah) <alagalah@gmail.com>
Wed, 19 Nov 2014 17:50:46 +0000 (09:50 -0800)
committerKeith Burns (alagalah) <alagalah@gmail.com>
Wed, 19 Nov 2014 18:16:53 +0000 (10:16 -0800)
2. Added use-cases directory for use-case config files
3. Cleaned up comments

Change-Id: I54e9a4693ad7cb5de28c74ab59954e24eed03a3c
Signed-off-by: Keith Burns (alagalah) <alagalah@gmail.com>
util/dockerTestOfOverlay/infrastructure_config.py
util/dockerTestOfOverlay/infrastructure_launch.py
util/dockerTestOfOverlay/odl_gbp.py
util/dockerTestOfOverlay/policy_config.py
util/dockerTestOfOverlay/testOfOverlay.py
util/use-cases/2-client-1-provider/infrastructure_config.py [new file with mode: 0644]
util/use-cases/2-client-1-provider/policy_config.py [new file with mode: 0644]

index b4c3ede2fdd8fa62781e9e34cd60dceb25a01fd8..6365866b17906d0210d0b93974ab1c47e68a0faf 100644 (file)
@@ -1,9 +1,9 @@
 # Config for switches, tunnelIP is the local IP address.
 switches = [{'name': 's1',
-             'tunnelIp': '192.168.56.30',
+             'tunnelIp': '192.168.56.31',
              'dpid': '1'},
             {'name': 's2',
-             'tunnelIp': '192.168.56.32',
+             'tunnelIp': '192.168.56.33',
              'dpid': '2'}]
 
 defaultContainerImage='alagalah/odlpoc_ovs230'
index 2fcb31ee00a857d4081f8e1e62f67a994091be22..bf6ae3039f48e7317a025389d435efbbe542f146 100644 (file)
@@ -32,7 +32,7 @@ def addTunnel(sw, sourceIp=None):
     ifaceName = '{}_vxlan0'.format(sw)
     cmd = ['ovs-vsctl', 'add-port', sw, ifaceName,
            '--', 'set', 'Interface', ifaceName,
-           'type=vxlan', 
+           'type=vxlan',
            'options:remote_ip=flow',
            'options:key=flow']
     if sourceIp is not None:
index afc82aa9acaa54f6f1b17c6ac8c78fce258c9247..ddc03d17a3e0407f03e6cc6569ed8430be448edd 100644 (file)
@@ -1,6 +1,7 @@
 
 import requests,json
 import uuid
+import sys
 from requests.auth import HTTPBasicAuth
 
 USERNAME='admin'
@@ -131,12 +132,10 @@ def get_node_config(sw, tun_ip):
     nodes.append(data)
     return data
 
-def get_contract(tenantId, pgroupIds, cgroupIds, contract):
-#TODO: This assumes a single provider/consumer per contract. Should be able to process list, just
-# note entirely sure if everything should be repeated, or just IDs ??? For now, assuming single
+def get_contract(tenantId, pgroupId, cgroupId, contract):
     tenant = get_tenant(tenantId)
-    pgroup = get_epg(tenantId, pgroupIds[0])
-    cgroup = get_epg(tenantId, cgroupIds[0])
+    pgroup = get_epg(tenantId, pgroupId)
+    cgroup = get_epg(tenantId, cgroupId)
 
     if not contract.has_key('id'):
         contract['id']=str(uuid.uuid4())
@@ -145,16 +144,33 @@ def get_contract(tenantId, pgroupIds, cgroupIds, contract):
     data=dict(contract)
     del data['name']
 
-    tenant["contract"].append(data)
-    cgroup["consumer-named-selector"].append({
-        "name": "{}-{}-{}".format(pgroupIds[0], cgroupIds[0], data['id']),
-        "contract": [data['id']]
-    })
-    pgroup["provider-named-selector"].append({
-        "name": "{}-{}-{}".format(pgroupIds[0], cgroupIds[0], data['id']),
-        "contract": [data['id']]
-    })
-
+    if not tenant["contract"]:
+        tenant["contract"].append(data)
+    else:
+        contractExists=False
+        for tenantContract in tenant["contract"]:
+            if tenantContract["id"] == data["id"]: contractExists=True
+        if not contractExists:
+            tenant["contract"].append(data)
+    name="{}-{}-{}".format(pgroupId, cgroupId, data['id'])
+    if not cgroup["consumer-named-selector"]:
+        cgroup["consumer-named-selector"].append({"name": name, "contract": [data['id']]})
+    else:
+        contractExists=False
+        for consumerContract in cgroup["consumer-named-selector"]:
+            if consumerContract["contract"][0] == data["id"]:
+                contractExists=True
+        if not contractExists:
+            cgroup["consumer-named-selector"].append({"name": name,"contract": [data['id']]})
+    if not pgroup["provider-named-selector"]:
+        pgroup["provider-named-selector"].append({"name": name,"contract": [data['id']]})
+    else:
+        contractExists=False
+        for providerContract in pgroup["provider-named-selector"]:
+            if providerContract["contract"][0] == data["id"]:
+                contractExists=True
+        if not contractExists:
+            pgroup["provider-named-selector"].append({"name": name,"contract": [data['id']]})
     return data
 
 def post(url, data):
index 1c12b5f20934543bc643204aee85f9ad9ee056c7..31436a973fd66b0205bea23ecffdf5f41eb8e945 100644 (file)
@@ -3,15 +3,15 @@ L2BD='7b796915-adf4-4356-b5ca-de005ac410c1'
 # Only one tenant supported at this time.
 tenants = [
            {'name':'GBPPOC',
-            'id':'f5c7d344-d1c7-4208-8531-2c2693657e12', #Optional, if you leave this out will be generated
-            'subject-feature-instances': 
-            {'classifier-instance': 
+            'id':'f5c7d344-d1c7-4208-8531-2c2693657e12',
+            'subject-feature-instances':
+            {'classifier-instance':
                 [
                 {'name': 'http-dest',
                 'classifier-definition-id': '4250ab32-e8b8-445a-aebb-e1bd2cdd291f',
                 'parameter-value': [
                     {'name': 'type',
-                     'string-value': 'TCP'}, 
+                     'string-value': 'TCP'},
                     {'name': 'destport',
                      'int-value': '80'}
                 ]},
@@ -19,7 +19,7 @@ tenants = [
                 'classifier-definition-id': '4250ab32-e8b8-445a-aebb-e1bd2cdd291f',
                 'parameter-value': [
                     {'name': 'type',
-                     'string-value': 'TCP'}, 
+                     'string-value': 'TCP'},
                     {'name': 'sourceport',
                      'int-value': '80'}
                 ]},
@@ -62,7 +62,7 @@ contracts = [
               'clause': [
                 {'name': 'allow-http-clause',
                  'subject-refs': [
-                    'allow-http-subject', 
+                    'allow-http-subject',
                     'allow-icmp-subject'
                     ]
                  }
@@ -72,14 +72,11 @@ endpointGroups = [
                    {'name':'client',
                     'providesContracts' : [], #List of contract names provided
                     'consumesContracts' : ['pingall+web'],
-                    'id' : '1eaf9a67-a171-42a8-9282-71cf702f61dd', #Optional, if you leave this out will be generated
+                    'id' : '1eaf9a67-a171-42a8-9282-71cf702f61dd',
                     },
                   {'name':'webserver',
                     'providesContracts' : ['pingall+web'], #List of contract names provided
                     'consumesContracts' : [],
-                    'id' : 'e593f05d-96be-47ad-acd5-ba81465680d5', #Optional, if you leave this out will be generated
+                    'id' : 'e593f05d-96be-47ad-acd5-ba81465680d5',
                    }
                   ]
-
-
-
index ed2312fbf19bf9c767520ae23e64ad19bec43b8a..3d3d8337bf21810ce6429ee0d034983618d24a93 100755 (executable)
@@ -104,11 +104,12 @@ if __name__ == '__main__':
                 contractConsumerEpgIDs.append(endpointGroup['id'])
             if contract['name'] in endpointGroup['providesContracts']:
                 contractProviderEpgIDs.append(endpointGroup['id'])
-
-        odl_gbp.get_contract(tenant['id'], 
-                      contractProviderEpgIDs,
-                      contractConsumerEpgIDs, 
-                      contract)
+        for contractProviderEpgID in contractProviderEpgIDs:
+            for contractConsumerEpgID in contractConsumerEpgIDs:
+                odl_gbp.get_contract(tenant['id'],
+                              contractProviderEpgID,
+                              contractConsumerEpgID,
+                              contract)
 
     # POST to the controller to register tenants
     if args.policy:
diff --git a/util/use-cases/2-client-1-provider/infrastructure_config.py b/util/use-cases/2-client-1-provider/infrastructure_config.py
new file mode 100644 (file)
index 0000000..24ff164
--- /dev/null
@@ -0,0 +1,85 @@
+# Config for switches, tunnelIP is the local IP address.
+switches = [{'name': 's1',
+             'tunnelIp': '192.168.56.31',
+             'dpid': '1'},
+            {'name': 's2',
+             'tunnelIp': '192.168.56.33',
+             'dpid': '2'}]
+
+defaultContainerImage='alagalah/odlpoc_ovs230'
+
+#Note that tenant name and endpointGroup name come from policy_config.py
+
+hosts = [          {'name': 'h35_2',
+          'mac': '00:00:00:00:35:02',
+          'ip': '10.0.35.2/24',
+          'switch': 's1',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'client1'},
+         {'name': 'h35_3',
+          'ip': '10.0.35.3/24',
+          'mac': '00:00:00:00:35:03',
+          'switch': 's1',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'client1'},
+         {'name': 'h36_2',
+          'ip': '10.0.36.2/24',
+          'mac': '00:00:00:00:36:02',
+          'switch': 's1',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'webserver'},
+         {'name': 'h36_3',
+          'ip': '10.0.36.3/24',
+          'mac': '00:00:00:00:36:03',
+          'switch': 's1',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'webserver'},
+         {'name': 'h37_2',
+          'ip': '10.0.37.2/24',
+          'mac': '00:00:00:00:37:02',
+          'switch': 's1',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'client2'},
+         {'name': 'h37_3',
+          'ip': '10.0.37.3/24',
+          'mac': '00:00:00:00:37:03',
+          'switch': 's1',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'client2'},
+          {'name': 'h35_4',
+          'mac': '00:00:00:00:35:04',
+          'ip': '10.0.35.4/24',
+          'switch': 's2',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'client1'},
+         {'name': 'h35_5',
+          'ip': '10.0.35.5/24',
+          'mac': '00:00:00:00:35:05',
+          'switch': 's2',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'client1'},
+         {'name': 'h36_4',
+          'ip': '10.0.36.4/24',
+          'mac': '00:00:00:00:36:04',
+          'switch': 's2',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'webserver'},
+         {'name': 'h36_5',
+          'ip': '10.0.36.5/24',
+          'mac': '00:00:00:00:36:05',
+          'switch': 's2',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'webserver'},
+         {'name': 'h37_4',
+          'ip': '10.0.37.4/24',
+          'mac': '00:00:00:00:37:04',
+          'switch': 's2',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'client2'},
+         {'name': 'h37_5',
+          'ip': '10.0.37.5/24',
+          'mac': '00:00:00:00:37:05',
+          'switch': 's2',
+          'tenant': 'GBPPOC',
+          'endpointGroup': 'client2'}
+       ]
diff --git a/util/use-cases/2-client-1-provider/policy_config.py b/util/use-cases/2-client-1-provider/policy_config.py
new file mode 100644 (file)
index 0000000..eea0215
--- /dev/null
@@ -0,0 +1,87 @@
+L3CTX='cbe0cc07-b8ff-451d-8171-9eef002a8e80'
+L2BD='7b796915-adf4-4356-b5ca-de005ac410c1'
+# Only one tenant supported at this time.
+tenants = [
+           {'name':'GBPPOC',
+            'id':'f5c7d344-d1c7-4208-8531-2c2693657e12',
+            'subject-feature-instances':
+            {'classifier-instance':
+                [
+                {'name': 'http-dest',
+                'classifier-definition-id': '4250ab32-e8b8-445a-aebb-e1bd2cdd291f',
+                'parameter-value': [
+                    {'name': 'type',
+                     'string-value': 'TCP'},
+                    {'name': 'destport',
+                     'int-value': '80'}
+                ]},
+                {'name': 'http-src',
+                'classifier-definition-id': '4250ab32-e8b8-445a-aebb-e1bd2cdd291f',
+                'parameter-value': [
+                    {'name': 'type',
+                     'string-value': 'TCP'},
+                    {'name': 'sourceport',
+                     'int-value': '80'}
+                ]},
+                {'name': 'icmp',
+                'classifier-definition-id': '79c6fdb2-1e1a-4832-af57-c65baf5c2335',
+                'parameter-value': [
+                    {'name': 'proto',
+                     'int-value': '1'}
+                                    ]
+                 }
+                 ]
+             }
+            }
+           ]
+
+contracts = [
+             {'name':'pingall+web',
+              'id':'22282cca-9a13-4d0c-a67e-a933ebb0b0ae',
+              'subject': [
+                {'name': 'allow-http-subject',
+                 'rule': [
+                    {'name': 'allow-http-rule',
+                     'classifier-ref': [
+                        {'name': 'http-dest',
+                         'direction': 'in'},
+                        {'name': 'http-src',
+                         'direction': 'out'}
+                          ]
+                     }
+                          ]
+                 },
+                {'name': 'allow-icmp-subject',
+                 'rule': [
+                    {'name': 'allow-icmp-rule',
+                     'classifier-ref': [
+                        {'name': 'icmp'}
+                                                  ]}
+                          ]
+                 }],
+              'clause': [
+                {'name': 'allow-http-clause',
+                 'subject-refs': [
+                    'allow-http-subject',
+                    'allow-icmp-subject'
+                    ]
+                 }
+                        ]
+              }]
+endpointGroups = [
+                   {'name':'client1',
+                    'providesContracts' : [], #List of contract names provided
+                    'consumesContracts' : ['pingall+web'],
+                    'id' : '1eaf9a67-a171-42a8-9282-71cf702f61dd',
+                    },
+                   {'name':'client2',
+                    'providesContracts' : [], #List of contract names provided
+                    'consumesContracts' : ['pingall+web'],
+                    'id' : '6c787c-156a-49ed-8546-547bdccf283c',
+                    },
+                  {'name':'webserver',
+                    'providesContracts' : ['pingall+web'], #List of contract names provided
+                    'consumesContracts' : [],
+                    'id' : 'e593f05d-96be-47ad-acd5-ba81465680d5',
+                   }
+                  ]