示例#1
0
    def setrevmask(self, revmask):
	# flip a cisco reverse mask to a standard mask. XXX.
	rmask = IPTools.ip2int(revmask)
	mask = 0xFFFFFFFFL - rmask
	self.cmask=IPTools.ip2str(mask)

	self.setcslashmask(revmask)
示例#2
0
    def setcdest(self,dest):
 	self.cdest=dest
	# break into interface and ip
	if IPTools.checkip(dest):
	    self.cdest_ip.append(dest)		# an ip
	else:
	    self.cdest_if=dest		# should be interface
示例#3
0
    def setcslashmask(self, mask):
	self.cslashmask=IPTools.mask2cidr(mask)
示例#4
0
    def addroute(self, object):
	"""Check to see if this routeobj belongs with this interface
	   It can then be tied to this Interface object
	"""
	if not isinstance(object, Route):
	    return

	isdn=0

	if self.crouter != object.crouter:
	    return

	# Destination is interface or gateway.
	# Check ISDN type 
	# DEBUG
	#print "obj.cdest=",object.cdest, "gw=",self.cgw, "int=",self.cinterface
	
	for gw in self.cgw:
	    isdn=1
	    if object.cdest==gw:
		if self.cstate=="shutdown":
	    	    object.attributes.append(Const.INTERFACE_SHUTDOWN)
	        self.croutes.append(object)

	    #print "%s %s DOWN" % (self.crouter, self.cinterface)
#	else:
#	    print "%s %s UP" % (self.crouter, self.cinterface)

	# Check other permcons links if a gateway on a route is part of ip block
	# on an interface.

	#print "Debug addroute(): obj.cdest [%s] <-> self.cinterface [%s]" % (object.cdest,self.cinterface)

	# For a destination IP
	if not isdn and IPTools.checkip(object.cdest):
	    if type(self.cip)==(""):
		self.cip=[self.cip]
	    if type(self.cip_cidr)==(""):
		self.cip_cidr=[self.cip_cidr]
	    i=0
	    for ip in self.cip:
		 ipcidr = ip+'/'+ str(self.cip_cidr[i])
		 net = IPTools.findnet(ipcidr)

	    	 bits =  IPTools.mask2int(self.cip_cidr)
	    	 lowip = IPTools.ip2int(net)
	    	 highip= IPTools.ip2int(net) + bits	
	
	         testip = IPTools.ip2int(object.cdest)	

	         if testip>=lowip and testip<=highip:
	            self.croutes.append(object)
		    if self.cstate=="shutdown":
	    	        object.attributes.append(Const.INTERFACE_SHUTDOWN)
		 i=i+1

	# For a route with an interface as destination 
	elif object.cdest==self.cinterface:
	        #print "Debug addroute(): obj.cdest [%s] <-> self.cinterface [%s]" % (object.cdest,self.cinterface)
		if self.cstate=="shutdown":
	    	    object.attributes.append(Const.INTERFACE_SHUTDOWN)

		for i in range(0, len(self.cip)):
		    ipcidr=self.cip[i] + "/" + str(self.cip_cidr[i])

		    net = IPTools.findnet(ipcidr) + "/" + str(self.cip_cidr[i])

		    object.cdest_net.append(net)
		    ip=None
	    	    if self.cmask[i]=="255.255.255.252":
			parts=string.split(self.cip[i],'.')
			if len(parts)==4:
			    if ( (int(parts[3])-1) % 4) ==0:
		    	        byte4=int(parts[3]) + 1
			    else:		    
		    	        byte4=int(parts[3]) - 1
	            	    ipcidr=("%s.%s.%s.%s" % (parts[0], parts[1], parts[2], byte4))

		            #object.cdest_ip.append(ipcidr)
		            ip=ipcidr

		    object.cdest_ip.append(ip)	

	            #print " ** ** addroute() net=", object.cdest_net[-1], "ip=",object.cdest_ip[-1]
	        self.croutes.append(object)
	return
示例#5
0
    def setccidr(self, mask):
	self.cip_cidr.append(IPTools.mask2cidr(mask))