Beispiel #1
0
	def parse_api_vpls (self,command,peers,action):
		tokens = formated(command).split(' ')[1:]
		if len(tokens) < 4:
			return False
		if tokens[0] != 'vpls':
			return False
		changes = []
		if 'self' in command:
			for peer,nexthop in peers.iteritems():
				scope = [{}]
				self._nexthopself = nexthop
				if not self._single_l2vpn_vpls(scope,tokens[1:]):
					self._nexthopself = None
					return False
				for change in scope[0]['announce']:
					changes.append((peer,change))
			self._nexthopself = None
		else:
			scope = [{}]
			if not self._single_l2vpn_vpls(scope,tokens[1:]):
				return False
			for peer in peers:
				for change in scope[0]['announce']:
					changes.append((peer,change))
		if action == 'withdraw':
			for (peer,change) in changes:
				change.nlri.action = OUT.withdraw
		return changes
Beispiel #2
0
	def received (self):
		consumed_data = False

		for process in list(self._process):
			try:
				proc = self._process[process]
				# proc.poll returns None if the process is still fine
				# -[signal], like -15, if the process was terminated
				if proc.poll() is not None and self.reactor.respawn:
					raise ValueError('child died')
				r,_,_ = select.select([proc.stdout,],[],[],0)
				if r:
					try:
						while True:
							line = proc.stdout.next().rstrip()
							consumed_data = True
							self.logger.processes("Command from process %s : %s " % (process,line))
							yield (process,formated(line))
					except IOError,e:
						if not e.errno or e.errno in error.fatal:
							# if the program exists we can get an IOError with errno code zero !
							self.logger.processes("Issue with the process' PIPE, terminating it and restarting it")
							self._terminate(process)
							self._start(process)
						elif e.errno in error.block:
							# we often see errno.EINTR: call interrupted and
							# we most likely have data, we will try to read them a the next loop iteration
							pass
						else:
							self.logger.processes("unexpected errno received from forked process (%s)" % errstr(e))
					except StopIteration:
						if not consumed_data:
							self.logger.processes("The process died, trying to respawn it")
							self._terminate(process)
							self._start(process)
Beispiel #3
0
 def parse_api_vpls(self, command, peers, action):
     tokens = formated(command).split(' ')[1:]
     if len(tokens) < 4:
         return False
     if tokens[0] != 'vpls':
         return False
     changes = []
     if 'self' in command:
         for peer, nexthop in peers.iteritems():
             scope = [{}]
             self._nexthopself = nexthop
             if not self._single_l2vpn_vpls(scope, tokens[1:]):
                 self._nexthopself = None
                 return False
             for change in scope[0]['announce']:
                 changes.append((peer, change))
         self._nexthopself = None
     else:
         scope = [{}]
         if not self._single_l2vpn_vpls(scope, tokens[1:]):
             return False
         for peer in peers:
             for change in scope[0]['announce']:
                 changes.append((peer, change))
     if action == 'withdraw':
         for (peer, change) in changes:
             change.nlri.action = OUT.withdraw
     return changes
Beispiel #4
0
	def parse_api_refresh (self,command):
		tokens = formated(command).split(' ')[2:]
		if len(tokens) != 2:
			return False
		afi = AFI.value(tokens.pop(0))
		safi = SAFI.value(tokens.pop(0))
		if afi is None or safi is None:
			return False
		return RouteRefresh(afi,safi)
Beispiel #5
0
 def parse_api_refresh(self, command):
     tokens = formated(command).split(' ')[2:]
     if len(tokens) != 2:
         return False
     afi = AFI.value(tokens.pop(0))
     safi = SAFI.value(tokens.pop(0))
     if afi is None or safi is None:
         return False
     return RouteRefresh(afi, safi)
Beispiel #6
0
    def parse_api_operational(self, command):
        tokens = formated(command).split(' ', 2)
        scope = [{}]

        if len(tokens) != 3:
            return False

        operational = tokens[0].lower()
        what = tokens[1].lower()

        if operational != 'operational':
            return False

        if what == 'asm':
            if not self._single_operational(Advisory.ASM, scope,
                                            ['afi', 'safi', 'advisory'],
                                            tokens[2]):
                return False
        elif what == 'adm':
            if not self._single_operational(Advisory.ADM, scope,
                                            ['afi', 'safi', 'advisory'],
                                            tokens[2]):
                return False
        elif what == 'rpcq':
            if not self._single_operational(
                    Query.RPCQ, scope, ['afi', 'safi', 'sequence'], tokens[2]):
                return False
        elif what == 'rpcp':
            if not self._single_operational(
                    Response.RPCP, scope,
                ['afi', 'safi', 'sequence', 'counter'], tokens[2]):
                return False
        elif what == 'apcq':
            if not self._single_operational(
                    Query.APCQ, scope, ['afi', 'safi', 'sequence'], tokens[2]):
                return False
        elif what == 'apcp':
            if not self._single_operational(
                    Response.APCP, scope,
                ['afi', 'safi', 'sequence', 'counter'], tokens[2]):
                return False
        elif what == 'lpcq':
            if not self._single_operational(
                    Query.LPCQ, scope, ['afi', 'safi', 'sequence'], tokens[2]):
                return False
        elif what == 'lpcp':
            if not self._single_operational(
                    Response.LPCP, scope,
                ['afi', 'safi', 'sequence', 'counter'], tokens[2]):
                return False
        else:
            return False

        operational = scope[0]['operational'][0]
        return operational
Beispiel #7
0
	def parse_api_flow (self,command,action):
		self._tokens = self._tokenise(' '.join(formated(command).split(' ')[2:]).split('\\n'))
		scope = [{}]
		if not self._dispatch(scope,'flow',['route',],[],['root']):
			return False
		if not self._check_flow_route(scope):
			return False
		changes = scope[0]['announce']
		if action == 'withdraw':
			for change in changes:
				change.nlri.action = OUT.withdraw
		return changes
Beispiel #8
0
 def parse_api_flow(self, command, action):
     self._tokens = self._tokenise(' '.join(
         formated(command).split(' ')[2:]).split('\\n'))
     scope = [{}]
     if not self._dispatch(scope, 'flow', [
             'route',
     ], [], ['root']):
         return False
     if not self._check_flow_route(scope):
         return False
     changes = scope[0]['announce']
     if action == 'withdraw':
         for change in changes:
             change.nlri.action = OUT.withdraw
     return changes
Beispiel #9
0
    def received(self):
        consumed_data = False

        for process in list(self._process):
            try:
                proc = self._process[process]
                # proc.poll returns None if the process is still fine
                # -[signal], like -15, if the process was terminated
                if proc.poll() is not None and self.reactor.respawn:
                    raise ValueError('child died')
                r, _, _ = select.select([
                    proc.stdout,
                ], [], [], 0)
                if r:
                    try:
                        while True:
                            line = proc.stdout.next().rstrip()
                            consumed_data = True
                            self.logger.processes(
                                "Command from process %s : %s " %
                                (process, line))
                            yield (process, formated(line))
                    except IOError, e:
                        if not e.errno or e.errno in error.fatal:
                            # if the program exists we can get an IOError with errno code zero !
                            self.logger.processes(
                                "Issue with the process' PIPE, terminating it and restarting it"
                            )
                            self._terminate(process)
                            self._start(process)
                        elif e.errno in error.block:
                            # we often see errno.EINTR: call interrupted and
                            # we most likely have data, we will try to read them a the next loop iteration
                            pass
                        else:
                            self.logger.processes(
                                "unexpected errno received from forked process (%s)"
                                % errstr(e))
                    except StopIteration:
                        if not consumed_data:
                            self.logger.processes(
                                "The process died, trying to respawn it")
                            self._terminate(process)
                            self._start(process)
Beispiel #10
0
	def parse_api_eor (self,command):
		tokens = formated(command).split(' ')[2:]
		lt = len(tokens)

		if not lt:
			return Family(1,1)

		if lt !=2:
			return False

		afi = AFI.fromString(tokens[0])
		if afi == AFI.undefined:
			return False

		safi = SAFI.fromString(tokens[1])
		if safi == SAFI.undefined:
			return False

		return Family(afi,safi)
Beispiel #11
0
    def parse_api_eor(self, command):
        tokens = formated(command).split(' ')[2:]
        lt = len(tokens)

        if not lt:
            return Family(1, 1)

        if lt != 2:
            return False

        afi = AFI.fromString(tokens[0])
        if afi == AFI.undefined:
            return False

        safi = SAFI.fromString(tokens[1])
        if safi == SAFI.undefined:
            return False

        return Family(afi, safi)
Beispiel #12
0
	def parse_api_operational (self,command):
		tokens = formated(command).split(' ',2)
		scope = [{}]

		if len(tokens) != 3:
			return False

		operational = tokens[0].lower()
		what = tokens[1].lower()

		if operational != 'operational':
			return False

		if what == 'asm':
			if not self._single_operational(Advisory.ASM,scope,['afi','safi','advisory'],tokens[2]):
				return False
		elif what == 'adm':
			if not self._single_operational(Advisory.ADM,scope,['afi','safi','advisory'],tokens[2]):
				return False
		elif what == 'rpcq':
			if not self._single_operational(Query.RPCQ,scope,['afi','safi','sequence'],tokens[2]):
				return False
		elif what == 'rpcp':
			if not self._single_operational(Response.RPCP,scope,['afi','safi','sequence','counter'],tokens[2]):
				return False
		elif what == 'apcq':
			if not self._single_operational(Query.APCQ,scope,['afi','safi','sequence'],tokens[2]):
				return False
		elif what == 'apcp':
			if not self._single_operational(Response.APCP,scope,['afi','safi','sequence','counter'],tokens[2]):
				return False
		elif what == 'lpcq':
			if not self._single_operational(Query.LPCQ,scope,['afi','safi','sequence'],tokens[2]):
				return False
		elif what == 'lpcp':
			if not self._single_operational(Response.LPCP,scope,['afi','safi','sequence','counter'],tokens[2]):
				return False
		else:
			return False

		operational = scope[0]['operational'][0]
		return operational
Beispiel #13
0
	def parse_api_route (self,command,peers,action):
		tokens = formated(command).split(' ')[1:]
		lt = len(tokens)

		if lt < 1: return False

		message = tokens[0]

		if message not in ('route',):
			return False

		if lt == 2 and action == 'withdraw' and 'next-hop' not in tokens:
			tokens.extend(['next-hop','0.0.0.0'])

		changes = []
		if 'self' in command:
			for peer,nexthop in peers.iteritems():
				scope = [{}]
				self._nexthopself = nexthop
				if not self._single_static_route(scope,tokens[1:]):
					self._nexthopself = None
					return False
				for change in scope[0]['announce']:
					changes.append((peer,change))
			self._nexthopself = None
		else:
			scope = [{}]
			if not self._single_static_route(scope,tokens[1:]):
				return False
			for peer in peers:
				for change in scope[0]['announce']:
					changes.append((peer,change))

		if action == 'withdraw':
			for (peer,change) in changes:
				change.nlri.action = OUT.withdraw
		return changes
Beispiel #14
0
    def parse_api_route(self, command, peers, action):
        tokens = formated(command).split(' ')[1:]
        lt = len(tokens)

        if lt < 1: return False

        message = tokens[0]

        if message not in ('route', ):
            return False

        if lt == 2 and action == 'withdraw' and 'next-hop' not in tokens:
            tokens.extend(['next-hop', '0.0.0.0'])

        changes = []
        if 'self' in command:
            for peer, nexthop in peers.iteritems():
                scope = [{}]
                self._nexthopself = nexthop
                if not self._single_static_route(scope, tokens[1:]):
                    self._nexthopself = None
                    return False
                for change in scope[0]['announce']:
                    changes.append((peer, change))
            self._nexthopself = None
        else:
            scope = [{}]
            if not self._single_static_route(scope, tokens[1:]):
                return False
            for peer in peers:
                for change in scope[0]['announce']:
                    changes.append((peer, change))

        if action == 'withdraw':
            for (peer, change) in changes:
                change.nlri.action = OUT.withdraw
        return changes