Exemple #1
0
    def CreateSlice(self, urn_req = None):
        self.logger.info("Called CreateSlice URN REQ %r" % urn_req)
        slice_gid = None

        if urn_req and self.slices.has_key(urn_req):
            # If the Slice has expired, treat this as
            # a request to renew
            slice_cred = self.slices[urn_req]
            if slice_cred.expiration <= datetime.datetime.utcnow():
                # Need to renew this slice
                self.logger.info("CreateSlice on %r found existing cred that expired at %r - will renew", urn_req, slice_cred.expiration)
                slice_gid = slice_cred.get_gid_object()
            else:
                self.logger.debug("Slice cred is still valid at %r until %r - return it", datetime.datetime.utcnow(), slice_cred.expiration)
                return slice_cred.save_to_string()
        
        # First ensure we have a slice_urn
        if urn_req:
            # FIXME: Validate urn_req has the right form
            # to be issued by this CH
            if not urn_util.is_valid_urn(urn_req):
                # FIXME: make sure it isnt empty, etc...
                urn = urn_util.publicid_to_urn(urn_req)
            else:
                urn = urn_req
        else:
            # Generate a unique URN for the slice
            # based on this CH location and a UUID

            # Where was the slice created?
            (ipaddr, port) = self._server.socket._sock.getsockname()
            # FIXME: Get public_id start from a properties file
            # Create a unique name for the slice based on uuid
            slice_name = uuid.uuid4().__str__()[4:12]
            public_id = 'IDN %s slice %s//%s:%d' % (SLICE_AUTHORITY, slice_name,
                                                                   ipaddr,
                                                                   port)
            # this func adds the urn:publicid:
            # and converts spaces to +'s, and // to :
            urn = urn_util.publicid_to_urn(public_id)

        # Now create a GID for the slice (signed credential)
        if slice_gid is None:
            try:
                slice_gid = cert_util.create_cert(urn, self.keyfile, self.certfile)[0]
            except Exception, exc:
                self.logger.error("Cant create slice gid for slice urn %s: %s", urn, traceback.format_exc())
                raise Exception("Failed to create slice %s. Cant create slice gid" % urn, exc)
Exemple #2
0
    def test_external_rspec(self):
        self.test_create_aggregates()
        adv_rspec = rspec_mod.get_resources(None, None)

        d1 = rspec_mod.parse_external_rspec(adv_rspec)

        # replace all the urn prefixes with external ones
        test_prefix = publicid_to_urn(
            "IDN %s//%s" % ("test//test", settings.OPENFLOW_GCF_BASE_SUFFIX))
        adv_rspec2 = adv_rspec.replace(rspec_mod.OPENFLOW_GAPI_RSC_URN_PREFIX,
                                       test_prefix)

        d2 = rspec_mod.parse_external_rspec(adv_rspec2)

        self.assertEqual(d1, d2)
    def test_external_rspec(self):
        self.test_create_aggregates()
        adv_rspec = rspec_mod.get_resources(None, None)
        
        d1 = rspec_mod.parse_external_rspec(adv_rspec)
        
        # replace all the urn prefixes with external ones
        test_prefix = publicid_to_urn(
            "IDN %s//%s" % ("test//test", settings.OPENFLOW_GCF_BASE_SUFFIX)
        )
        adv_rspec2 = adv_rspec.replace(
            rspec_mod.OPENFLOW_GAPI_RSC_URN_PREFIX, test_prefix)

        d2 = rspec_mod.parse_external_rspec(adv_rspec2)
        
        self.assertEqual(d1, d2)
PORT_TAG = "port"

VERSION = "version"

CURRENT_ADV_VERSION = "2"

URN = "urn"
SRC_URN = "src_urn"
DST_URN = "dst_urn"

LOCATION = "location"
NAME = "name"
FLOWVISOR_URL = "flowvisor_url"

OPENFLOW_GAPI_RSC_URN_PREFIX = publicid_to_urn(
    "IDN %s//%s" % (settings.GCF_BASE_NAME, settings.OPENFLOW_GCF_BASE_SUFFIX)
)

SWITCH_URN_REGEX = r"^%s\+switch:(?P<dpid>[\d:a-fA-F]+)$" % \
    OPENFLOW_GAPI_RSC_URN_PREFIX.replace("+", r"\+")
PORT_URN_REGEX = r"%s\+port:(?P<port>\d+)$" % SWITCH_URN_REGEX[:-1]

switch_re = re.compile(SWITCH_URN_REGEX)
port_re = re.compile(PORT_URN_REGEX)

EXTERNAL_SWITCH_URN_REGEX = r"^(?P<prefix>.*)\+switch:(?P<dpid>[:a-fA-F\d]+)$"
EXTERNAL_PORT_URN_REGEX = r"%s\+port:(?P<port>\d+)$" % EXTERNAL_SWITCH_URN_REGEX[:-1]

external_switch_re = re.compile(EXTERNAL_SWITCH_URN_REGEX)
external_port_re = re.compile(EXTERNAL_PORT_URN_REGEX)
Exemple #5
0
PORT_NUM_TAG = "port_num"
PORT_TAG = "port"

VERSION = "version"

CURRENT_ADV_VERSION = "2"

URN = "urn"
SRC_URN = "src_urn"
DST_URN = "dst_urn"

LOCATION = "location"
NAME = "name"
FLOWVISOR_URL = "flowvisor_url"

OPENFLOW_GAPI_RSC_URN_PREFIX = publicid_to_urn(
    "IDN %s//%s" % (settings.GCF_BASE_NAME, settings.OPENFLOW_GCF_BASE_SUFFIX))

SWITCH_URN_REGEX = r"^%s\+switch:(?P<dpid>[\d:a-fA-F]+)$" % \
    OPENFLOW_GAPI_RSC_URN_PREFIX.replace("+", r"\+")
PORT_URN_REGEX = r"%s\+port:(?P<port>\d+)$" % SWITCH_URN_REGEX[:-1]

switch_re = re.compile(SWITCH_URN_REGEX)
port_re = re.compile(PORT_URN_REGEX)

EXTERNAL_SWITCH_URN_REGEX = r"^(?P<prefix>.*)\+switch:(?P<dpid>[:a-fA-F\d]+)$"
EXTERNAL_PORT_URN_REGEX = r"%s\+port:(?P<port>\d+)$" % EXTERNAL_SWITCH_URN_REGEX[:
                                                                                 -1]

external_switch_re = re.compile(EXTERNAL_SWITCH_URN_REGEX)
external_port_re = re.compile(EXTERNAL_PORT_URN_REGEX)
Exemple #6
0
'''
Created on Oct 6, 2010

@author: jnaous
'''
from django.db import models
from django.conf import settings
from openflow.plugin.gapi import gapi, rspec
from expedient.common.federation.geni.util.urn_util import publicid_to_urn

OTHER_BASENAME = "test//test"
OTHER_PREFIX = publicid_to_urn(
    "IDN %s//%s" % (OTHER_BASENAME, settings.OPENFLOW_GCF_BASE_SUFFIX))


class DummyOFAggregate(models.Model):
    #adv_rspec = models.XMLField()
    adv_rspec = models.TextField()
    #resv_rspec = models.XMLField(null=True, blank=True)
    resv_rspec = models.TextField(null=True, blank=True)

    def snapshot_switches(self):
        self.adv_rspec = gapi.ListResources({}, None)
        self.adv_rspec = self.adv_rspec.replace(
            rspec.OPENFLOW_GAPI_RSC_URN_PREFIX, OTHER_PREFIX)
        self.save()
'''
Created on Oct 6, 2010

@author: jnaous
'''
from django.db import models
from django.conf import settings
from openflow.plugin.gapi import gapi, rspec
from expedient.common.federation.geni.util.urn_util import publicid_to_urn

OTHER_BASENAME ="test//test"
OTHER_PREFIX = publicid_to_urn(
    "IDN %s//%s"
    % (OTHER_BASENAME, settings.OPENFLOW_GCF_BASE_SUFFIX)
)

class DummyOFAggregate(models.Model):
    #adv_rspec = models.XMLField()
    adv_rspec = models.TextField()
    #resv_rspec = models.XMLField(null=True, blank=True)
    resv_rspec = models.TextField(null=True, blank=True)
    
    def snapshot_switches(self):
        self.adv_rspec = gapi.ListResources({}, None)
        self.adv_rspec = self.adv_rspec.replace(
            rspec.OPENFLOW_GAPI_RSC_URN_PREFIX, OTHER_PREFIX)
        self.save()