Exemple #1
0
    def __new_ASPath(self, data, asn4=False):

        if len(data) == 0:
            return ASPath(asn4)

        if asn4:
            size = 4
            decoder = 'L'  # could it be 'I' as well ?
        else:
            size = 2
            decoder = 'H'
        stype = ord(data[0])
        slen = ord(data[1])
        sdata = data[2:2 + (slen * size)]

        ASPS = ASPath(asn4, stype)
        format = '!' + (decoder * slen)
        for c in unpack(format, sdata):
            ASPS.add(c)
        return ASPS
Exemple #2
0
	def __new_ASPath (self,data,asn4=False):
		
		if len(data) == 0:
			return ASPath(asn4)
		
		if asn4:
			size = 4
			decoder = 'L' # could it be 'I' as well ?
		else:
			size = 2
			decoder = 'H'
		stype = ord(data[0])
		slen = ord(data[1])
		sdata = data[2:2+(slen*size)]
		
		ASPS = ASPath(asn4,stype)
		format = '!'+(decoder*slen)
		for c in unpack(format,sdata):
			ASPS.add(c)
		return ASPS
Exemple #3
0
 def _as_path(self, asn4, asp):
     message = ''
     # if the peer does not understand ASN4, we need to build a transitive AS4_PATH
     if not asn4:
         has_asn4 = False
         aspath = ASPath(False, asp.asptype)
         as4path = AS4Path(asp.asptype)
         for segment in asp.aspsegment:
             if segment.asn4():
                 has_asn4 = True
                 aspath.add(AS_TRANS)
                 as4path.add(segment)
             else:
                 aspath.add(segment)
                 as4path.add(segment)
         message += aspath.pack()
         if has_asn4:
             message += as4path.pack()
     else:
         message += ASPath(True, asp.asptype, asp.aspsegment).pack()
     return message
	def _route_aspath (self,scope,tokens):
		aspath = ASPath()
		asn = tokens.pop(0)
		try:
			if asn == '[':
				while True:
					try:
						asn = tokens.pop(0)
					except IndexError:
						self._error = self._str_route_error
						if self.debug: raise
						return False
					if asn == ']':
						break
					aspath.add(self._newASN(asn))
			else:
				aspath.add(self._newASN(asn))
		except ValueError:
			self._error = self._str_route_error
			if self.debug: raise
			return False
		scope[-1]['routes'][-1].attributes.add(aspath)
		return True
Exemple #5
0
    def __merge_attributes(self):
        as2path = self.attributes[AttributeID.AS_PATH]
        as4path = self.attributes[AttributeID.AS4_PATH]
        newASPS = ASPath(True, as2path.asptype)
        len2 = len(as2path.aspsegment)
        len4 = len(as4path.aspsegment)

        if len2 < len4:
            for asn in as4path.aspsegment:
                newASPS.add(asn)
        else:
            for asn in as2path.aspsegment[:-len4]:
                newASPS.add(asn)
            for asn in as4path.aspsegment:
                newASPS.add(asn)

        self.attributes.remove(AttributeID.AS_PATH)
        self.attributes.remove(AttributeID.AS4_PATH)
        self.attributes.add(newASPS)
Exemple #6
0
	def __merge_attributes (self):
		as2path = self.attributes[AttributeID.AS_PATH]
		as4path = self.attributes[AttributeID.AS4_PATH]
		newASPS = ASPath(True,as2path.asptype)
		len2 = len(as2path.aspsegment)
		len4 = len(as4path.aspsegment)

		if len2 < len4:
			for asn in as4path.aspsegment:
				newASPS.add(asn)
		else:
			for asn in as2path.aspsegment[:-len4]:
				newASPS.add(asn)
			for asn in as4path.aspsegment:
				newASPS.add(asn)

		self.attributes.remove(AttributeID.AS_PATH)
		self.attributes.remove(AttributeID.AS4_PATH)
		self.attributes.add(newASPS)