Beispiel #1
0
    def parse_granted_flowspaces(gfs):
        gfs_list=[]
        for fs in gfs:
            fs_dict = dict(
                flowspace=dict(),
                openflow=dict()
            )
            fs_dict['openflow']=[]
            fs_dict['flowspace']=dict(
                                     mac_src_s=int_to_mac(fs.mac_src_s),
                                     mac_src_e=int_to_mac(fs.mac_src_e),
                                     mac_dst_s=int_to_mac(fs.mac_dst_s),
                                     mac_dst_e=int_to_mac(fs.mac_dst_e),
                                     eth_type_s=fs.eth_type_s,
                                     eth_type_e=fs.eth_type_e,
                                     vlan_id_s=fs.vlan_id_s,
                                     vlan_id_e=fs.vlan_id_e,
                                     ip_src_s=int_to_dotted_ip(fs.ip_src_s),
                                     ip_dst_s=int_to_dotted_ip(fs.ip_dst_s),
                                     ip_src_e=int_to_dotted_ip(fs.ip_src_e),
                                     ip_dst_e=int_to_dotted_ip(fs.ip_dst_e),
                                     ip_proto_s=fs.ip_proto_s,
                                     ip_proto_e=fs.ip_proto_e,
                                     tp_src_s=fs.tp_src_s,
                                     tp_dst_s=fs.tp_dst_s,
                                     tp_src_e=fs.tp_src_e,
                                     tp_dst_e=fs.tp_dst_e,
                                 )

            openflow_dict=dict(
                                    dpid=fs.dpid,
                                    direction=fs.direction,
                                    port_number_s=fs.port_number_s,
                                    port_number_e=fs.port_number_e,
                              )
            existing_fs = False
            for prev_dict in gfs_list:
                if fs_dict['flowspace'] == prev_dict['flowspace']:
                    prev_dict['openflow'].append(openflow_dict)
                    existing_fs = True
                    break
            if not existing_fs:
                fs_dict['openflow'].append(openflow_dict)
                gfs_list.append(fs_dict)
        print "----------------------------------------------------"
        import pprint
        pprint.pprint(gfs_list)
        return gfs_list
def cidr_ip_to_range(cidr_ip): 
    ip, mask = cidr_ip['value'].split('/')
    ip_int = dotted_ip_to_int(ip)
    addresses = (2**(32-int(mask)))-1
    final_ip_int = ip_int + addresses
    dotted_ip = int_to_dotted_ip(final_ip_int)
    return ip,dotted_ip
Beispiel #3
0
 def cidr_ip_to_range(cidr_ip):
     ip, mask = cidr_ip.split('/')
     ip_int = dotted_ip_to_int(ip)
     addresses = (2**(32-int(mask)))-1
     final_ip_int = ip_int + addresses
     dotted_ip = int_to_dotted_ip(final_ip_int)
     return ip_int,final_ip_int
    def parse_granted_flowspaces(gfs):
        gfs_list=[]
        for fs in gfs:
            fs_dict = dict(
                flowspace=dict(),
                openflow=dict()
            )
            fs_dict['openflow']=[]
            fs_dict['flowspace']=dict(
                                     mac_src_s=int_to_mac(fs.mac_src_s),
                                     mac_src_e=int_to_mac(fs.mac_src_e),
                                     mac_dst_s=int_to_mac(fs.mac_dst_s),
                                     mac_dst_e=int_to_mac(fs.mac_dst_e),
                                     eth_type_s=fs.eth_type_s,
                                     eth_type_e=fs.eth_type_e,
                                     vlan_id_s=fs.vlan_id_s,
                                     vlan_id_e=fs.vlan_id_e,
                                     ip_src_s=int_to_dotted_ip(fs.ip_src_s),
                                     ip_dst_s=int_to_dotted_ip(fs.ip_dst_s),
                                     ip_src_e=int_to_dotted_ip(fs.ip_src_e),
                                     ip_dst_e=int_to_dotted_ip(fs.ip_dst_e),
                                     ip_proto_s=fs.ip_proto_s,
                                     ip_proto_e=fs.ip_proto_e,
                                     tp_src_s=fs.tp_src_s,
                                     tp_dst_s=fs.tp_dst_s,
                                     tp_src_e=fs.tp_src_e,
                                     tp_dst_e=fs.tp_dst_e,
                                 )

            openflow_dict=dict(
                                    dpid=fs.dpid,
                                    direction=fs.direction,
                                    port_number_s=fs.port_number_s,
                                    port_number_e=fs.port_number_e,
                              )
            existing_fs = False
            for prev_dict in gfs_list:
                if fs_dict['flowspace'] == prev_dict['flowspace']:
                    prev_dict['openflow'].append(openflow_dict)
                    existing_fs = True
                    break
            if not existing_fs:
                fs_dict['openflow'].append(openflow_dict)
                gfs_list.append(fs_dict)

        return gfs_list
Beispiel #5
0
 def __unicode__(self):
     expression = ""
     try:
         if (self.mac_src_s  == self.mac_src_e):
             expression = expression + ("MAC Source Addr: %s, " % (int_to_mac(self.mac_src_s)))
         elif (self.mac_src_s > 0 or self.mac_src_e < 0xFFFFFFFFFFFF):
             expression = expression + ("MAC Source Addr: %s-%s, " % (int_to_mac(self.mac_src_s), int_to_mac(self.mac_src_e)))
         if (self.mac_dst_s  == self.mac_dst_e):
             expression = expression + ("MAC Destination Addr: %s, " % (int_to_mac(self.mac_dst_s)))
         elif (self.mac_dst_s > 0 or self.mac_dst_e < 0xFFFFFFFFFFFF): 
             expression = expression + ("MAC Destination Addr: %s-%s, " % (int_to_mac(self.mac_dst_s), int_to_mac(self.mac_dst_e))) 
         if (self.eth_type_s == self.eth_type_e): 
             expression = expression + ("Eth Type: 0x%x, " % (self.eth_type_s)) 
         elif (self.eth_type_s > 0 or self.eth_type_e < 0xFFFF): 
             expression = expression + ("Eth Type: 0x%x-0x%x, " % (self.eth_type_s,self.eth_type_e)) 
         if (self.vlan_id_s == self.vlan_id_e): 
             expression = expression + ("VLAN id: %d, " % (self.vlan_id_s)) 
         elif (self.vlan_id_s > 0 or self.vlan_id_e < 0xFFF): 
             expression = expression + ("VLAN id: %d-%d, " % (self.vlan_id_s,self.vlan_id_e)) 
         if (self.ip_src_s == self.ip_src_e):    
             expression = expression + ("IP Source Addr: %s, " % (int_to_dotted_ip(self.ip_src_s)))
         elif (self.ip_src_s > 0 or self.ip_src_e < 0xFFFFFFFF):    
             expression = expression + ("IP Source Addr: %s-%s, " % (int_to_dotted_ip(self.ip_src_s), int_to_dotted_ip(self.ip_src_e)))
         if (self.ip_dst_s == self.ip_dst_e):    
             expression = expression + ("IP Destination Addr: %s, " % (int_to_dotted_ip(self.ip_dst_s)))
         elif (self.ip_dst_s > 0 or self.ip_dst_e < 0xFFFFFFFF):    
             expression = expression + ("IP Destination Addr: %s-%s, " % (int_to_dotted_ip(self.ip_dst_s), int_to_dotted_ip(self.ip_dst_e)))
         if (self.ip_proto_s == self.ip_proto_e):    
             expression = expression + ("IP Protocol Number: %s, " % (self.ip_proto_s)) 
         elif (self.ip_proto_s > 0 or self.ip_proto_e < 0xFF):    
             expression = expression + ("IP Protocol Number: %s-%s, " % (self.ip_proto_s, self.ip_proto_e)) 
         if (self.tp_src_s == self.tp_src_e):    
             expression = expression + ("Transport Source Port: %s, " % (self.tp_src_s))
         elif (self.tp_src_s > 0 or self.tp_src_e < 0xFFFF):    
             expression = expression + ("Transport Source Port: %s-%s, " % (self.tp_src_s, self.tp_src_e))
         if (self.tp_dst_s == self.tp_dst_e):    
             expression = expression + ("Transport Destination Port: %s, " % (self.tp_dst_s))
         if (self.tp_dst_s > 0 or self.tp_dst_e < 0xFFFF):    
             expression = expression + ("Transport Destination Port: %s-%s, " % (self.tp_dst_s, self.tp_dst_e))
         if expression == "":
             expression = "All"
     except Exception as e:
         expression = self.stringify()
     return expression
Beispiel #6
0
    def create_of_sliver(slice_urn, project_name, project_description,
                         slice_name, slice_description, controller_url,
                         owner_email, owner_password, switch_slivers,
                         **kwargs):
        e = Experiment.objects.filter(slice_urn=slice_urn)
        if (e.count() > 0):
            old_e = e[0]
            old_fv_name = old_e.slice_id
            update_exp = True
            old_exp_fs = ExperimentFLowSpace.objects.filter(exp=old_e)
        else:
            update_exp = False

        e = Experiment()
        slice_id = uuid.uuid4()
        e.slice_id = slice_id
        e.project_name = project_name
        e.project_desc = project_description
        e.slice_name = slice_name
        e.slice_desc = slice_description
        e.controller_url = controller_url
        e.owner_email = owner_email
        e.owner_password = owner_password
        e.slice_urn = slice_urn
        e.save()
        all_efs = []
        for sliver in switch_slivers:
            if "datapath_id" in sliver:
                dpid = sliver['datapath_id']
            else:
                dpid = "00:" * 8
                dpid = dpid[:-1]

            if len(sliver['flowspace']) == 0:
                # HACK:
                efs = ExperimentFLowSpace()
                efs.exp = e
                efs.dpid = dpid
                efs.direction = 2
                all_efs.append(efs)
            else:
                for sfs in sliver['flowspace']:
                    efs = ExperimentFLowSpace()
                    efs.exp = e
                    efs.dpid = dpid
                    if "direction" in sfs:
                        efs.direction = get_direction(sfs['direction'])
                    else:
                        efs.direction = 2

                    fs = convert_star(sfs)
                    for attr_name,(to_str, from_str, width, om_name, of_name) in \
                    om_ch_translate.attr_funcs.items():
                        ch_start = "%s_start" % (attr_name)
                        ch_end = "%s_end" % (attr_name)
                        om_start = "%s_s" % (om_name)
                        om_end = "%s_e" % (om_name)

                        if not fs[ch_start]:
                            continue

                        if (ch_start or ch_end) in [
                                "nw_dst_start", "nw_dst_end", "nw_src_start",
                                "nw_src_end"
                        ]:
                            fs[ch_start] = int_to_dotted_ip(fs[ch_start])
                            fs[ch_end] = int_to_dotted_ip(fs[ch_end])

                        try:
                            setattr(efs, om_start, from_str(fs[ch_start]))
                        except:
                            setattr(efs, om_start,
                                    from_str(int(fs[ch_start], 16)))
                        try:
                            setattr(efs, om_end, from_str(fs[ch_end]))
                        except:
                            setattr(efs, om_end, from_str(int(fs[ch_end], 16)))
                    all_efs.append(efs)

        fv = FVServerProxy.objects.all()[0]
        if (update_exp):
            # delete previous experiment from FV
            try:
                fv_success = fv.proxy.api.deleteSlice(old_fv_name)
                old_exp_fs.delete()
                old_e.delete()
            except Exception, exc:
                import traceback
                traceback.print_exc()
                if "slice does not exist" in str(exc):
                    fv_success = True
                    old_exp_fs.delete()
                    old_e.delete()
                else:
                    e.delete()
                    print exc
                    raise Exception(
                        parseFVexception(
                            exc,
                            "While trying to update experiment, FV raised exception on the delete previous experiment step: "
                        ))

            if (not fv_success):
                e.delete()
                raise Exception(
                    "While trying to update experiment, FV returned False on the delete previous experiment step"
                )
Beispiel #7
0
 def __unicode__(self):
     expression = ""
     if (self.mac_src_s == self.mac_src_e):
         expression = expression + ("MAC Source Addr: %s, " %
                                    (int_to_mac(self.mac_src_s)))
     elif (self.mac_src_s > 0 or self.mac_src_e < 0xFFFFFFFFFFFF):
         expression = expression + (
             "MAC Source Addr: %s-%s, " %
             (int_to_mac(self.mac_src_s), int_to_mac(self.mac_src_e)))
     if (self.mac_dst_s == self.mac_dst_e):
         expression = expression + ("MAC Destination Addr: %s, " %
                                    (int_to_mac(self.mac_dst_s)))
     elif (self.mac_dst_s > 0 or self.mac_dst_e < 0xFFFFFFFFFFFF):
         expression = expression + (
             "MAC Destination Addr: %s-%s, " %
             (int_to_mac(self.mac_dst_s), int_to_mac(self.mac_dst_e)))
     if (self.eth_type_s == self.eth_type_e):
         expression = expression + ("Eth Type: 0x%x, " % (self.eth_type_s))
     elif (self.eth_type_s > 0 or self.eth_type_e < 0xFFFF):
         expression = expression + ("Eth Type: 0x%x-0x%x, " %
                                    (self.eth_type_s, self.eth_type_e))
     if (self.vlan_id_s == self.vlan_id_e):
         expression = expression + ("VLAN id: %d, " % (self.vlan_id_s))
     elif (self.vlan_id_s > 0 or self.vlan_id_e < 0xFFF):
         expression = expression + ("VLAN id: %d-%d, " %
                                    (self.vlan_id_s, self.vlan_id_e))
     if (self.ip_src_s == self.ip_src_e):
         expression = expression + ("IP Source Addr: %s, " %
                                    (int_to_dotted_ip(self.ip_src_s)))
     elif (self.ip_src_s > 0 or self.ip_src_e < 0xFFFFFFFF):
         expression = expression + ("IP Source Addr: %s-%s, " %
                                    (int_to_dotted_ip(self.ip_src_s),
                                     int_to_dotted_ip(self.ip_src_e)))
     if (self.ip_dst_s == self.ip_dst_e):
         expression = expression + ("IP Destination Addr: %s, " %
                                    (int_to_dotted_ip(self.ip_dst_s)))
     elif (self.ip_dst_s > 0 or self.ip_dst_e < 0xFFFFFFFF):
         expression = expression + ("IP Destination Addr: %s-%s, " %
                                    (int_to_dotted_ip(self.ip_dst_s),
                                     int_to_dotted_ip(self.ip_dst_e)))
     if (self.ip_proto_s == self.ip_proto_e):
         expression = expression + ("IP Protocol Number: %s, " %
                                    (self.ip_proto_s))
     elif (self.ip_proto_s > 0 or self.ip_proto_e < 0xFF):
         expression = expression + ("IP Protocol Number: %s-%s, " %
                                    (self.ip_proto_s, self.ip_proto_e))
     if (self.tp_src_s == self.tp_src_e):
         expression = expression + ("Transport Source Port: %s, " %
                                    (self.tp_src_s))
     elif (self.tp_src_s > 0 or self.tp_src_e < 0xFFFF):
         expression = expression + ("Transport Source Port: %s-%s, " %
                                    (self.tp_src_s, self.tp_src_e))
     if (self.tp_dst_s == self.tp_dst_e):
         expression = expression + ("Transport Destination Port: %s, " %
                                    (self.tp_dst_s))
     if (self.tp_dst_s > 0 or self.tp_dst_e < 0xFFFF):
         expression = expression + ("Transport Destination Port: %s-%s, " %
                                    (self.tp_dst_s, self.tp_dst_e))
     if expression == "":
         expression = "All"
     return expression
Beispiel #8
0
    def create_of_sliver(slice_urn,project_name,project_description,slice_name,slice_description,controller_url,owner_email,owner_password,switch_slivers,**kwargs):
        e = Experiment.objects.filter(slice_urn=slice_urn)
        if (e.count()>0):
            old_e = e[0]
            old_fv_name = old_e.slice_id
            update_exp = True
            old_exp_fs = ExperimentFLowSpace.objects.filter(exp=old_e)
        else:
            update_exp = False
        
        e = Experiment()
        slice_id = uuid.uuid4()    
        e.slice_id = slice_id
        e.project_name = project_name
        e.project_desc = project_description
        e.slice_name = slice_name
        e.slice_desc = slice_description
        e.controller_url = controller_url
        e.owner_email = owner_email
        e.owner_password = owner_password
        e.slice_urn = slice_urn
        e.save()
        all_efs = [] 
        for sliver in switch_slivers:
            if "datapath_id" in sliver:
                dpid = sliver['datapath_id']
            else:
                dpid = "00:" * 8
                dpid = dpid[:-1]
                
            if len(sliver['flowspace'])==0:
                # HACK:
                efs = ExperimentFLowSpace()
                efs.exp  = e
                efs.dpid = dpid
                efs.direction = 2
                all_efs.append(efs)
            else:
                for sfs in sliver['flowspace']:
                    efs = ExperimentFLowSpace()
                    efs.exp  = e
                    efs.dpid = dpid
                    if "direction" in sfs:
                        efs.direction = get_direction(sfs['direction'])
                    else:
                        efs.direction = 2
                            
                    fs = convert_star(sfs)
                    for attr_name,(to_str, from_str, width, om_name, of_name) in \
                    om_ch_translate.attr_funcs.items():
                        ch_start ="%s_start"%(attr_name)
                        ch_end ="%s_end"%(attr_name)
                        om_start ="%s_s"%(om_name)
                        om_end ="%s_e"%(om_name)
                        
                        if not fs[ch_start]:
                           continue 

                        if (ch_start or ch_end) in ["nw_dst_start", "nw_dst_end", "nw_src_start", "nw_src_end"]:
                            fs[ch_start] = int_to_dotted_ip( fs[ch_start])
                            fs[ch_end] = int_to_dotted_ip( fs[ch_end])

                        try:
                            setattr(efs,om_start,from_str(fs[ch_start]))
                        except:
                            setattr(efs,om_start,from_str(int(fs[ch_start],16)))
                        try:
                            setattr(efs,om_end,from_str(fs[ch_end]))
                        except:
                            setattr(efs,om_end,from_str(int(fs[ch_end],16)))
                    all_efs.append(efs)
            
        fv = FVServerProxy.objects.all()[0]
        if (update_exp):
            # delete previous experiment from FV
            try:
                fv_success = fv.proxy.api.deleteSlice(old_fv_name)
                old_exp_fs.delete()
                old_e.delete()
            except Exception, exc:
                import traceback
                traceback.print_exc()
                if "slice does not exist" in str(exc):
                    fv_success = True
                    old_exp_fs.delete()
                    old_e.delete()
                else:
                    e.delete()
                    print exc
                    raise Exception(parseFVexception(exc,"While trying to update experiment, FV raised exception on the delete previous experiment step: "))
                    
            if (not fv_success):
                e.delete()
                raise Exception("While trying to update experiment, FV returned False on the delete previous experiment step")