Example #1
0
	def addSliver (self, sliver):
		fspecs = sliver.getFlowspecs()
		
		for fs in fspecs:
			#add macs old style
			for mac in fs.getMACs():
				self._macs.add(mac)
			#add intervalized macs (new style)
			newInterval = True
			previntmac = None
			for mac in sorted(fs.getMACs()):
				intmac = mac_to_int(mac)
				if newInterval == True:	#new interval encountered
					MACstart = intmac
					MACstop = intmac
				else:
					if previntmac != None: 
						if (intmac - previntmac) == 1:	#still within the interval
							MACstop = intmac
							newInterval = False
						else:	#register the interval
							self._macivtree.addIVal(self._macivtree.root, MACstart, MACstop, sliver.getURN())
							newInterval = True
				previntmac = intmac
				
				#add dltypes old style
				for dltype in fs.getEtherTypes():
					if ((dltype == "0x806") or (dltype == "0x800")):
						continue
					self._ethertypes.add(dltype)
				
				#add vlans old style
				for vlanid in fs.getVLANs():
					self._vlans.add(vlanid)
				#add intervalized vlans (new style)
				newInterval = True
				previntvlanid = None
				for vlanid in sorted(fs.getVLANs()):
					intvlanid = int(vlanid)
					if newInterval == True:	#new interval encountered
						VLANstart = intvlanid
						VLANstop = intvlanid
					else:
						if previntvlanid != None: 
							if (intvlanid - previntvlanid) == 1:	#still within the interval
								VLANstop = intvlanid
								newInterval = False
							else:	#register the interval
								self._vlanivtree.addIVal(self._vlanivtree.root, VLANstart, VLANstop, sliver.getURN())
								newInterval = True
					previntvlanid = intvlanid
				
				#add IP subnets old style
				for subnet in fs.getIPSubnets():
					net = IP(subnet)
					self._subnets.add(net)
				#add intervalized IP subnets
				for IPSub in fs.getIPSubnets():
					IPsubparsed = self.parseSubnet(IPSub)
					IPSubLen = IP(IPSubparsed).len()
					IPstart = int(IP(IPSubparsed[0]).strDec())
					IPstop = IPstart + IPSubLen - 1
					self._subnetivtree.addIVal(self._subnetivtree.root, IPstart, IPstop, sliver.getURN())
					
				#add NW protos old style
				for nwprot in fs.getNWProtos():
					self._nwprotos.add(nwprot)
					
				#add TP ports old style
				for tpp in fs.getTPPorts():
					self._tpports.add(tpp)
				#add intervalized TP ports (new style)
				newInterval = True
				previnttpport = None
				for tpport in sorted(fs.getTPPorts()):
					inttpport = int(tpport)
					if newInterval == True:	#new interval encountered
						TPPortstart = inttpport
						TPPortstop = inttpport
					else:
						if previnttpport != None: 
							if (inttpport - prevtpport) == 1:	#still within the interval
								TPPortstop = tpport
								newInterval = False
							else:	#register the interval
								self._tpportivtree.addIVal(self._tpportivtree.root, TPPortstart, TPPortstop, sliver.getURN())
								newInterval = True
					previnttpport = inttpport
Example #2
0
	def validateSliver (self, sliver):
		if not ConfigDB.getConfigItemByKey("geni.openflow.analysis-engine").getValue():
			return

		fspecs = sliver.getFlowspecs()
		uncovered_fs = []
		for fs in fspecs:
			covered = False
			
			if fs.hasVLANs():
				#check VLAN clash
				covered = True
				newInterval = True
				previntvlanid = None
				for vlanid in sorted(fs.getVLANs()):
					intvlanid = int(vlanid)
					if newInterval == True:	#new interval encountered
						VLANstart = intvlanid
						VLANstop = intvlanid
					else:
						if previntvlanid != None: 
							if (intvlanid - previntvlanid) == 1:	#still within the interval
								VLANstop = intvlanid
								newInterval = False
							else:	#find overlap if exists
								ovList = self._vlanivtree.findOverlapIVal(self._vlanivtree.root, VLANstart, VLANstop, [])
								if ovList != []:
									raise IValVLANConflict(VLANstart, VLANstop)
								newInterval = True
					previntvlanid = intvlanid
			
			#check MAC clash
			newInterval = True
			previntmac = None
			for mac in sorted(fs.getMACs()):
				covered = True
				intmac = mac_to_int(mac)
				if newInterval == True:	#new interval encountered
					MACstart = intmac
					MACstop = intmac
				else:
					if previntmac != None: 
						if (intmac - previntmac) == 1:	#still within the interval
							MACstop = intmac
							newInterval = False
						else:	#find overlap if exists
							ovList = self._macivtree.findOverlapIVal(self._macivtree.root, MACstart, MACstop, [])
							if ovList != []:
								raise IvalMACConflict(MACstart, MACstop)
							newInterval = True
				previntmac = intmac
				
			#check dl type clash
			for dltype in fs.getEtherTypes():
				covered = True
				if dltype == "0x806" or dltype == "0x800":
					continue
				if dltype in self._ethertypes:
					raise EtherTypeConflict(dltype)
				
			#check IP subnet clash
			for IPSub in fs.getIPSubnets():
				covered = True
				IPsubparsed = self.parseSubnet(IPSub)
				IPSubLen = IP(IPSubparsed).len()
				IPstart = int(IP(IPSubparsed[0]).strDec())
				IPstop = IPstart + IPSubLen - 1
				ovList = self._subnetivtree.findOverlapIVal(self._subnetivtree.root, IPstart, IPstop, [])
				if ovList != []:
					raise IvalIPSubnetConflict(IP(IPsub))
					
			#check TP port clash
			newInterval = True
			previnttpport = None
			for tpport in sorted(fs.getTPPorts()):
				covered = True
				inttpport = int(tpport)
				if newInterval == True:	#new interval encountered
					TPPortstart = inttpport
					TPPortstop = inttpport
				else:
					if previnttpport != None: 
						if (inttpport - prevtpport) == 1:	#still within the interval
							TPPortstop = tpport
							newInterval = False
						else:	#find overlap if exists
							ovList = self._tpportivtree.findOverlapIVal(self._tpportivtree.root, TPPortstart, TPPortstop, [])
							if ovList != []:
								raise IvalTPPortConflict(TPPortstart, TPPortstop)
							newInterval = True
				previnttpport = inttpport
					
			has_dps = False
			dps = fs.getDatapaths()
			if not dps:
				raise NoDatapaths(fs)

			pl = PortAlyzer(self._portgroups)
			pl.validate(dps)
		
			if not covered:
				uncovered_fs.append(fs)

		if uncovered_fs:
			raise UncoveredFlowspecs(uncovered_fs)
Example #3
0
	def _buildIValTrees(self, slivers): #dl type and NW proto not needed to ne handled by a tree structure
		MACTree = MACIValTree([])
		VLANTree = VLANIValTree([])
		IPSubnetTree = IPSubnetIValTree([])
		TPPortTree = TPPortIValTree([])
		
		for sliv in slivers:
			fspecs = sliv.getFlowspecs()
			for fs in fspecs:
					
				#build MAC tree from pool of MACS
				newInterval = True
				previntmac = None
				for mac in sorted(fs.getMACs()):
					intmac = mac_to_int(mac)
					if newInterval == True:	#new interval encountered
						MACstart = intmac
						MACstop = intmac
					else:
						if previntmac != None: 
							if (intmac - previntmac) == 1:	#still within the interval
								MACstop = intmac
								newInterval = False
							else:	#register the interval
								MACTree.addIVal(MACTree.root, MACstart, MACstop, sliv.getURN())
								newInterval = True
					previntmac = intmac
				
				#build VLAN tree from pool of VLANs
				newInterval = True
				previntvlanid = None
				for vlanid in sorted(fs.getVLANs()):
					intvlanid = int(vlanid)
					if newInterval == True:	#new interval encountered
						VLANstart = intvlanid
						VLANstop = intvlanid
					else:
						if previntvlanid != None: 
							if (intvlanid - previntvlanid) == 1:	#still within the interval
								VLANstop = intvlanid
								newInterval = False
							else:	#register the interval
								VLANTree.addIVal(VLANTree.root, VLANstart, VLANstop, sliv.getURN())
								newInterval = True
					previntvlanid = intvlanid
					
				#build IP address tree from pool of IP subnets (first make them intervals)
				for IPSub in fs.getIPSubnets():
					IPSubparsed = self.parseSubnet(IPSub)
					IPSubLen = IP(IPSubparsed).len()
					IPstart = int(IP(IPSubparsed[0]).strDec())
					IPstop = IPstart + IPSubLen - 1
					IPSubnetTree.addIVal(IPSubnetTree.root, IPstart, IPstop, sliv.getURN())
				
				#build TP port tree from pool of TP ports
				newInterval = True
				previnttpport = None
				for tpport in sorted(fs.getTPPorts()):
					inttpport = int(tpport)
					if newInterval == True:	#new interval encountered
						TPPortstart = inttpport
						TPPortstop = inttpport
					else:
						if previnttpport != None: 
							if (inttpport - prevtpport) == 1:	#still within the interval
								TPPortstop = tpport
								newInterval = False
							else:	#register the interval
								TPPortTree.addIVal(TPPortTree.root, TPPortstart, TPPortstop, sliv.getURN())
								newInterval = True
					previnttpport = inttpport
		
		self._macivtree = MACTree	 
		self._vlanivtree = VLANTree
		self._subnetivtree = IPSubnetTree
		self._tpportivtree = TPPortTree
    def addSliver(self, sliver):
        fspecs = sliver.getFlowspecs()

        for fs in fspecs:
            #add macs old style
            for mac in fs.getMACs():
                self._macs.add(mac)
            #add intervalized macs (new style)
            newInterval = True
            previntmac = None
            for mac in sorted(fs.getMACs()):
                intmac = mac_to_int(mac)
                if newInterval == True:  #new interval encountered
                    MACstart = intmac
                    MACstop = intmac
                else:
                    if previntmac != None:
                        if (intmac -
                                previntmac) == 1:  #still within the interval
                            MACstop = intmac
                            newInterval = False
                        else:  #register the interval
                            self._macivtree.addIVal(self._macivtree.root,
                                                    MACstart, MACstop,
                                                    sliver.getURN())
                            newInterval = True
                previntmac = intmac

                #add dltypes old style
                for dltype in fs.getEtherTypes():
                    if ((dltype == "0x806") or (dltype == "0x800")):
                        continue
                    self._ethertypes.add(dltype)

                #add vlans old style
                for vlanid in fs.getVLANs():
                    self._vlans.add(vlanid)
                #add intervalized vlans (new style)
                newInterval = True
                previntvlanid = None
                for vlanid in sorted(fs.getVLANs()):
                    intvlanid = int(vlanid)
                    if newInterval == True:  #new interval encountered
                        VLANstart = intvlanid
                        VLANstop = intvlanid
                    else:
                        if previntvlanid != None:
                            if (intvlanid - previntvlanid
                                ) == 1:  #still within the interval
                                VLANstop = intvlanid
                                newInterval = False
                            else:  #register the interval
                                self._vlanivtree.addIVal(
                                    self._vlanivtree.root, VLANstart, VLANstop,
                                    sliver.getURN())
                                newInterval = True
                    previntvlanid = intvlanid

                #add IP subnets old style
                for subnet in fs.getIPSubnets():
                    net = IP(subnet)
                    self._subnets.add(net)
                #add intervalized IP subnets
                for IPSub in fs.getIPSubnets():
                    IPsubparsed = self.parseSubnet(IPSub)
                    IPSubLen = IP(IPSubparsed).len()
                    IPstart = int(IP(IPSubparsed[0]).strDec())
                    IPstop = IPstart + IPSubLen - 1
                    self._subnetivtree.addIVal(self._subnetivtree.root,
                                               IPstart, IPstop,
                                               sliver.getURN())

                #add NW protos old style
                for nwprot in fs.getNWProtos():
                    self._nwprotos.add(nwprot)

                #add TP ports old style
                for tpp in fs.getTPPorts():
                    self._tpports.add(tpp)
                #add intervalized TP ports (new style)
                newInterval = True
                previnttpport = None
                for tpport in sorted(fs.getTPPorts()):
                    inttpport = int(tpport)
                    if newInterval == True:  #new interval encountered
                        TPPortstart = inttpport
                        TPPortstop = inttpport
                    else:
                        if previnttpport != None:
                            if (inttpport - prevtpport
                                ) == 1:  #still within the interval
                                TPPortstop = tpport
                                newInterval = False
                            else:  #register the interval
                                self._tpportivtree.addIVal(
                                    self._tpportivtree.root, TPPortstart,
                                    TPPortstop, sliver.getURN())
                                newInterval = True
                    previnttpport = inttpport
    def validateSliver(self, sliver):
        if not ConfigDB.getConfigItemByKey(
                "geni.openflow.analysis-engine").getValue():
            return

        fspecs = sliver.getFlowspecs()
        uncovered_fs = []
        for fs in fspecs:
            covered = False

            if fs.hasVLANs():
                #check VLAN clash
                covered = True
                newInterval = True
                previntvlanid = None
                for vlanid in sorted(fs.getVLANs()):
                    intvlanid = int(vlanid)
                    if newInterval == True:  #new interval encountered
                        VLANstart = intvlanid
                        VLANstop = intvlanid
                    else:
                        if previntvlanid != None:
                            if (intvlanid - previntvlanid
                                ) == 1:  #still within the interval
                                VLANstop = intvlanid
                                newInterval = False
                            else:  #find overlap if exists
                                ovList = self._vlanivtree.findOverlapIVal(
                                    self._vlanivtree.root, VLANstart, VLANstop,
                                    [])
                                if ovList != []:
                                    raise IValVLANConflict(VLANstart, VLANstop)
                                newInterval = True
                    previntvlanid = intvlanid

            #check MAC clash
            newInterval = True
            previntmac = None
            for mac in sorted(fs.getMACs()):
                covered = True
                intmac = mac_to_int(mac)
                if newInterval == True:  #new interval encountered
                    MACstart = intmac
                    MACstop = intmac
                else:
                    if previntmac != None:
                        if (intmac -
                                previntmac) == 1:  #still within the interval
                            MACstop = intmac
                            newInterval = False
                        else:  #find overlap if exists
                            ovList = self._macivtree.findOverlapIVal(
                                self._macivtree.root, MACstart, MACstop, [])
                            if ovList != []:
                                raise IvalMACConflict(MACstart, MACstop)
                            newInterval = True
                previntmac = intmac

            #check dl type clash
            for dltype in fs.getEtherTypes():
                covered = True
                if dltype == "0x806" or dltype == "0x800":
                    continue
                if dltype in self._ethertypes:
                    raise EtherTypeConflict(dltype)

            #check IP subnet clash
            for IPSub in fs.getIPSubnets():
                covered = True
                IPsubparsed = self.parseSubnet(IPSub)
                IPSubLen = IP(IPSubparsed).len()
                IPstart = int(IP(IPSubparsed[0]).strDec())
                IPstop = IPstart + IPSubLen - 1
                ovList = self._subnetivtree.findOverlapIVal(
                    self._subnetivtree.root, IPstart, IPstop, [])
                if ovList != []:
                    raise IvalIPSubnetConflict(IP(IPsub))

            #check TP port clash
            newInterval = True
            previnttpport = None
            for tpport in sorted(fs.getTPPorts()):
                covered = True
                inttpport = int(tpport)
                if newInterval == True:  #new interval encountered
                    TPPortstart = inttpport
                    TPPortstop = inttpport
                else:
                    if previnttpport != None:
                        if (inttpport -
                                prevtpport) == 1:  #still within the interval
                            TPPortstop = tpport
                            newInterval = False
                        else:  #find overlap if exists
                            ovList = self._tpportivtree.findOverlapIVal(
                                self._tpportivtree.root, TPPortstart,
                                TPPortstop, [])
                            if ovList != []:
                                raise IvalTPPortConflict(
                                    TPPortstart, TPPortstop)
                            newInterval = True
                previnttpport = inttpport

            has_dps = False
            dps = fs.getDatapaths()
            if not dps:
                raise NoDatapaths(fs)

            pl = PortAlyzer(self._portgroups)
            pl.validate(dps)

            if not covered:
                uncovered_fs.append(fs)

        if uncovered_fs:
            raise UncoveredFlowspecs(uncovered_fs)
    def _buildIValTrees(
        self, slivers
    ):  #dl type and NW proto not needed to ne handled by a tree structure
        MACTree = MACIValTree([])
        VLANTree = VLANIValTree([])
        IPSubnetTree = IPSubnetIValTree([])
        TPPortTree = TPPortIValTree([])

        for sliv in slivers:
            fspecs = sliv.getFlowspecs()
            for fs in fspecs:

                #build MAC tree from pool of MACS
                newInterval = True
                previntmac = None
                for mac in sorted(fs.getMACs()):
                    intmac = mac_to_int(mac)
                    if newInterval == True:  #new interval encountered
                        MACstart = intmac
                        MACstop = intmac
                    else:
                        if previntmac != None:
                            if (intmac - previntmac
                                ) == 1:  #still within the interval
                                MACstop = intmac
                                newInterval = False
                            else:  #register the interval
                                MACTree.addIVal(MACTree.root, MACstart,
                                                MACstop, sliv.getURN())
                                newInterval = True
                    previntmac = intmac

                #build VLAN tree from pool of VLANs
                newInterval = True
                previntvlanid = None
                for vlanid in sorted(fs.getVLANs()):
                    intvlanid = int(vlanid)
                    if newInterval == True:  #new interval encountered
                        VLANstart = intvlanid
                        VLANstop = intvlanid
                    else:
                        if previntvlanid != None:
                            if (intvlanid - previntvlanid
                                ) == 1:  #still within the interval
                                VLANstop = intvlanid
                                newInterval = False
                            else:  #register the interval
                                VLANTree.addIVal(VLANTree.root, VLANstart,
                                                 VLANstop, sliv.getURN())
                                newInterval = True
                    previntvlanid = intvlanid

                #build IP address tree from pool of IP subnets (first make them intervals)
                for IPSub in fs.getIPSubnets():
                    IPSubparsed = self.parseSubnet(IPSub)
                    IPSubLen = IP(IPSubparsed).len()
                    IPstart = int(IP(IPSubparsed[0]).strDec())
                    IPstop = IPstart + IPSubLen - 1
                    IPSubnetTree.addIVal(IPSubnetTree.root, IPstart, IPstop,
                                         sliv.getURN())

                #build TP port tree from pool of TP ports
                newInterval = True
                previnttpport = None
                for tpport in sorted(fs.getTPPorts()):
                    inttpport = int(tpport)
                    if newInterval == True:  #new interval encountered
                        TPPortstart = inttpport
                        TPPortstop = inttpport
                    else:
                        if previnttpport != None:
                            if (inttpport - prevtpport
                                ) == 1:  #still within the interval
                                TPPortstop = tpport
                                newInterval = False
                            else:  #register the interval
                                TPPortTree.addIVal(TPPortTree.root,
                                                   TPPortstart, TPPortstop,
                                                   sliv.getURN())
                                newInterval = True
                    previnttpport = inttpport

        self._macivtree = MACTree
        self._vlanivtree = VLANTree
        self._subnetivtree = IPSubnetTree
        self._tpportivtree = TPPortTree