Example #1
0
        def callback():
            try:
                descriptions, command = extract_neighbors(line)
                peers = match_neighbors(reactor.peers, descriptions)
                if not peers:
                    self.log_failure(
                        'no neighbor matching the command : %s' % command)
                    reactor.processes.answer(service, 'error')
                    yield True
                    return

                with open(command, "rb") as datafile:
                    rawdata = datafile.read()

                assert rawdata
                for peer in peers:
                    log.info("send-raw-data: %d bytes to %s", len(rawdata),
                             str(peer))
                    peer.proto.connection.writer(rawdata)

                reactor.processes.answer_done(service)
            except Exception as ex:
                self.log_failure('issue with send-raw-data: ' + str(ex))
                reactor.processes.answer(service, 'error')
                yield True
Example #2
0
def announce_refresh (self, reactor, service, command):
	def callback (self, command, peers):
		refresh = self.api_refresh(command)
		if not refresh:
			self.log_failure("Command could not parse route-refresh command : %s" % command)
			reactor.processes.answer(service,'error')
			yield True
			return

		reactor.configuration.inject_refresh(peers,refresh)
		self.log_message("Sent to %s : %s" % (', '.join(peers if peers else []) if peers is not None else 'all peers',refresh.extensive()))

		yield False
		reactor.processes.answer_done(service)

	try:
		descriptions,command = extract_neighbors(command)
		peers = match_neighbors(reactor.peers,descriptions)
		if not peers:
			self.log_failure('no neighbor matching the command : %s' % command)
			reactor.processes.answer(service,'error')
			return False
		reactor.asynchronous.schedule(service,command,callback(self,command,peers))
		return True
	except ValueError:
		self.log_failure('issue parsing the command')
		reactor.processes.answer(service,'error')
		return False
	except IndexError:
		self.log_failure('issue parsing the command')
		reactor.processes.answer(service,'error')
		return False
Example #3
0
def clear_adj_rib(self, reactor, service, line):
    def callback(self, peers, direction):
        self.log_message("clearing adjb-rib-%s for %s" %
                         (direction, ', '.join(peers if peers else [])
                          if peers is not None else 'all peers'))
        for peer_name in peers:
            if direction == 'out':
                reactor.neighbor_rib_out_withdraw(peer_name)
            else:
                reactor.neighbor_rib_in_clear(peer_name)
            yield False

        reactor.processes.answer_done(service)

    try:
        descriptions, command = extract_neighbors(line)
        peers = match_neighbors(reactor.peers(), descriptions)
        if not peers:
            self.log_failure('no neighbor matching the command : %s' % command,
                             'warning')
            reactor.processes.answer_error(service)
            return False
        words = line.split()
        direction = 'in' if 'adj-rib-in' in words or 'in' in words else 'out'
        reactor.asynchronous.schedule(service, command,
                                      callback(self, peers, direction))
        return True
    except ValueError:
        self.log_failure('issue parsing the command')
        reactor.processes.answer_error(service)
        return False
    except IndexError:
        self.log_failure('issue parsing the command')
        reactor.processes.answer_error(service)
        return False
Example #4
0
def flush_adj_rib_out (self, reactor, service, line):
	def callback (self, peers):
		self.log_message("Flushing adjb-rib out for %s" % ', '.join(peers if peers else []) if peers is not None else 'all peers')
		for peer_name in peers:
			peer = reactor.peers.get(peer_name, None)
			if not peer:
				continue
			yield False

		reactor.processes.answer_done(service)

	try:
		descriptions,command = extract_neighbors(line)
		peers = match_neighbors(reactor.peers,descriptions)
		if not peers:
			self.log_failure('no neighbor matching the command : %s' % command,'warning')
			reactor.processes.answer(service,Answer.error)
			return False
		reactor.async.schedule(service,command,callback(self,peers))
		return True
	except ValueError:
		self.log_failure('issue parsing the command')
		reactor.processes.answer(service, Answer.error)
		return False
	except IndexError:
		self.log_failure('issue parsing the command')
		reactor.processes.answer(service, Answer.error)
		return False
Example #5
0
def announce_eor(self, reactor, service, command):
    def callback(self, command, peers):
        family = self.api_eor(command)
        if not family:
            self.log_failure("Command could not parse eor : %s" % command)
            reactor.processes.answer(service, 'error')
            yield True
            return

        reactor.configuration.inject_eor(peers, family)
        self.log_message("Sent to %s : %s" %
                         (', '.join(peers if peers else []) if peers
                          is not None else 'all peers', family.extensive()))
        yield False

        reactor.processes.answer_done(service)

    try:
        descriptions, command = extract_neighbors(command)
        peers = match_neighbors(reactor.peers, descriptions)
        if not peers:
            self.log_failure('no neighbor matching the command : %s' % command)
            reactor.processes.answer(service, 'error')
            return False
        reactor.asynchronous.schedule(service, command,
                                      callback(self, command, peers))
        return True
    except ValueError:
        self.log_failure('issue parsing the command')
        reactor.processes.answer(service, 'error')
        return False
    except IndexError:
        self.log_failure('issue parsing the command')
        reactor.processes.answer(service, 'error')
        return False
Example #6
0
def flush_adj_rib_out (self, reactor, service, line):
	def callback (self, peers):
		self.log_message("Flushing adjb-rib out for %s" % ', '.join(peers if peers else []) if peers is not None else 'all peers')
		for peer_name in peers:
			peer = reactor.peers.get(peer_name, None)
			if not peer:
				continue
			yield False

		reactor.processes.answer_done(service)

	try:
		descriptions,command = extract_neighbors(line)
		peers = match_neighbors(reactor.peers,descriptions)
		if not peers:
			self.log_failure('no neighbor matching the command : %s' % command,'warning')
			reactor.processes.answer(service,Answer.error)
			return False
		reactor.asynchronous.schedule(service, command, callback(self, peers))
		return True
	except ValueError:
		self.log_failure('issue parsing the command')
		reactor.processes.answer(service, Answer.error)
		return False
	except IndexError:
		self.log_failure('issue parsing the command')
		reactor.processes.answer(service, Answer.error)
		return False
Example #7
0
	def callback ():
		try:
			descriptions,command = extract_neighbors(line)
			peers = match_neighbors(reactor.peers,descriptions)
			if not peers:
				self.log_failure('no neighbor matching the command : %s' % command)
				reactor.processes.answer(service,'error')
				yield True
				return

			changes = self.api_route(command)
			if not changes:
				self.log_failure('command could not parse route in : %s' % command)
				reactor.processes.answer(service,'error')
				yield True
				return

			for change in changes:
				if not ParseStaticRoute.check(change):
					self.log_message('invalid route for %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
					continue
				change.nlri.action = OUT.ANNOUNCE
				reactor.configuration.inject_change(peers,change)
				self.log_message('route added to %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
				yield False

			reactor.processes.answer_done(service)
		except ValueError:
			self.log_failure('issue parsing the route')
			reactor.processes.answer(service,'error')
			yield True
		except IndexError:
			self.log_failure('issue parsing the route')
			reactor.processes.answer(service,'error')
			yield True
Example #8
0
	def callback ():
		try:
			descriptions,command = extract_neighbors(line)
			peers = match_neighbors(reactor.peers,descriptions)
			if not peers:
				self.log_failure('no neighbor matching the command : %s' % command)
				reactor.processes.answer(service,'error')
				yield True
				return

			changes = self.api_flow(command)

			if not changes:
				self.log_failure('command could not parse flow in : %s' % command)
				reactor.processes.answer(service,'error')
				yield True
				return

			for change in changes:
				change.nlri.action = OUT.WITHDRAW
				if reactor.configuration.inject_change(peers,change):
					self.log_message('flow removed from %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
				else:
					self.log_failure('flow not found on %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
				yield False

			reactor.processes.answer_done(service)
		except ValueError:
			self.log_failure('issue parsing the flow')
			reactor.processes.answer(service,'error')
			yield True
		except IndexError:
			self.log_failure('issue parsing the flow')
			reactor.processes.answer(service,'error')
			yield True
Example #9
0
def flush_adj_rib_out(self, reactor, service, line):
    def callback(self, peers):
        self.log_message("flushing adjb-rib out for %s" %
                         ', '.join(peers if peers else [])
                         if peers is not None else 'all peers')
        for peer_name in peers:
            reactor.neighbor_rib_resend(peer_name)
            yield False

        reactor.processes.answer_done(service)

    try:
        descriptions, command = extract_neighbors(line)
        peers = match_neighbors(reactor.established_peers(), descriptions)
        if not peers:
            self.log_failure('no neighbor matching the command : %s' % command,
                             'warning')
            reactor.processes.answer_error(service)
            return False
        reactor.asynchronous.schedule(service, command, callback(self, peers))
        return True
    except ValueError:
        self.log_failure('issue parsing the command')
        reactor.processes.answer_error(service)
        return False
    except IndexError:
        self.log_failure('issue parsing the command')
        reactor.processes.answer_error(service)
        return False
Example #10
0
def clear_adj_rib (self, reactor, service, line):
	def callback (self, peers, direction):
		self.log_message("clearing adjb-rib-%s for %s" % (direction,', '.join(peers if peers else []) if peers is not None else 'all peers'))
		for peer_name in peers:
			peer = reactor.peers.get(peer_name, None)
			if not peer:
				continue
			if direction == 'out':
				peer.neighbor.rib.outgoing.clear()
			else:
				peer.neighbor.rib.incoming.clear()
			yield False

		reactor.processes.answer_done(service)

	try:
		descriptions,command = extract_neighbors(line)
		peers = match_neighbors(reactor.peers,descriptions)
		if not peers:
			self.log_failure('no neighbor matching the command : %s' % command,'warning')
			reactor.processes.answer(service, Answer.error)
			return False
		words = line.split()
		direction = 'in' if 'adj-rib-in' in words or 'in' in words else 'out'
		reactor.asynchronous.schedule(service, command, callback(self, peers, direction))
		return True
	except ValueError:
		self.log_failure('issue parsing the command')
		reactor.processes.answer(service, Answer.error)
		return False
	except IndexError:
		self.log_failure('issue parsing the command')
		reactor.processes.answer(service, Answer.error)
		return False
Example #11
0
    def callback():
        try:
            descriptions, command = extract_neighbors(line)
            peers = match_neighbors(descriptions)
            if not peers:
                self.log_failure(
                    'no neighbor matching the command : %s' % command,
                    'warning')
                reactor.processes.answer(service, 'error')
                yield True
                return

            changes = self.api_route(command)
            if not changes:
                self.log_failure(
                    'command could not parse route in : %s' % command,
                    'warning')
                reactor.processes.answer(service, 'error')
                yield True
                return

            for change in changes:
                # Change the action to withdraw before checking the route
                change.nlri.action = OUT.WITHDRAW
                # NextHop is a mandatory field (but we do not require in)
                if change.nlri.nexthop is NoNextHop:
                    change.nlri.nexthop = NextHop('0.0.0.0')

                if not ParseStaticRoute.check(change):
                    self.log_message(
                        'invalid route for %s : %s' %
                        (', '.join(peers) if peers else 'all peers',
                         change.extensive()))
                    continue
                if reactor.configuration.inject_change(peers, change):
                    self.log_message(
                        'route removed from %s : %s' %
                        (', '.join(peers) if peers else 'all peers',
                         change.extensive()))
                    yield False
                else:
                    self.log_failure(
                        'route not found on %s : %s' %
                        (', '.join(peers) if peers else 'all peers',
                         change.extensive()))
                    yield False

            reactor.schedule_rib_check()
            reactor.processes.answer_done(service)
        except ValueError:
            self.log_failure('issue parsing the route')
            reactor.processes.answer(service, 'error')
            yield True
        except IndexError:
            self.log_failure('issue parsing the route')
            reactor.processes.answer(service, 'error')
            yield True
Example #12
0
def announce_operational(self, reactor, service, command):
    def callback(self, command, peers):
        operational = self.api_operational(command)
        if not operational:
            self.log_failure(
                "Command could not parse operational command : %s" % command)
            reactor.processes.answer_error(service)
            yield True
            return

        reactor.configuration.inject_operational(peers, operational)
        self.log_message(
            "operational message sent to %s : %s" %
            (', '.join(peers if peers else [])
             if peers is not None else 'all peers', operational.extensive()))
        yield False
        reactor.processes.answer_done(service)

    if (command.split() + ['be', 'safe'])[2].lower() not in (
            'asm',
            'adm',
            'rpcq',
            'rpcp',
            'apcq',
            'apcp',
            'lpcq',
            'lpcp',
    ):
        reactor.processes.answer_done(service)
        return False

    try:
        descriptions, command = extract_neighbors(command)
        peers = match_neighbors(reactor.peers(), descriptions)
        if not peers:
            self.log_failure('no neighbor matching the command : %s' % command)
            reactor.processes.answer_error(service)
            return False
        reactor.asynchronous.schedule(service, command,
                                      callback(self, command, peers))
        return True
    except ValueError:
        self.log_failure('issue parsing the command')
        reactor.processes.answer_error(service)
        return False
    except IndexError:
        self.log_failure('issue parsing the command')
        reactor.processes.answer_error(service)
        return False
Example #13
0
    def callback():
        try:
            descriptions, command = extract_neighbors(line)
            peers = match_neighbors(descriptions)
            if not peers:
                self.log_failure(
                    'no neighbor matching the command : %s' % command,
                    'warning')
                reactor.processes.answer(service, 'error')
                yield True
                return

            changes = self.api_vpls(command)

            if not changes:
                self.log_failure(
                    'command could not parse vpls in : %s' % command,
                    'warning')
                reactor.processes.answer(service, 'error')
                yield True
                return

            for change in changes:
                change.nlri.action = OUT.WITHDRAW
                if reactor.configuration.inject_change(peers, change):
                    self.log_message(
                        'vpls removed from %s : %s' %
                        (', '.join(peers) if peers else 'all peers',
                         change.extensive()))
                    yield False
                else:
                    self.log_failure(
                        'vpls not found on %s : %s' %
                        (', '.join(peers) if peers else 'all peers',
                         change.extensive()))
                    yield False

            reactor.schedule_rib_check()
            reactor.processes.answer_done(service)
        except ValueError:
            self.log_failure('issue parsing the vpls')
            reactor.processes.answer(service, 'error')
            yield True
        except IndexError:
            self.log_failure('issue parsing the vpls')
            reactor.processes.answer(service, 'error')
            yield True
Example #14
0
def teardown (self, reactor, service, line):
	try:
		descriptions,line = extract_neighbors(line)
		_,code = line.split(' ',1)
		for key in reactor.peers:
			for description in descriptions:
				if match_neighbor(description,key):
					reactor.peers[key].teardown(int(code))
					self.log_message('teardown scheduled for %s' % ' '.join(description))
		reactor.processes.answer_done(service)
		return True
	except ValueError:
		reactor.processes.answer_error(service)
		return False
	except IndexError:
		reactor.processes.answer_error(service)
		return False
Example #15
0
def teardown (self, reactor, service, line):
	try:
		descriptions,line = extract_neighbors(line)
		_,code = line.split(' ',1)
		for key in reactor.peers:
			for description in descriptions:
				if match_neighbor(description,key):
					reactor.peers[key].teardown(int(code))
					self.log_message('teardown scheduled for %s' % ' '.join(description))
		reactor.processes.answer_done(service)
		return True
	except ValueError:
		reactor.processes.answer(service,'error')
		return False
	except IndexError:
		reactor.processes.answer(service,'error')
		return False
Example #16
0
    def callback():
        try:
            descriptions, command = extract_neighbors(line)
            peers = match_neighbors(descriptions)
            if not peers:
                self.log_failure(
                    'no neighbor matching the command : %s' % command,
                    'warning')
                reactor.processes.answer(service, 'error')
                yield True
                return

            changes = self.api_route(command)
            if not changes:
                self.log_failure(
                    'command could not parse route in : %s' % command,
                    'warning')
                reactor.processes.answer(service, 'error')
                yield True
                return

            for change in changes:
                if not ParseStaticRoute.check(change):
                    self.log_message(
                        'invalid route for %s : %s' %
                        (', '.join(peers) if peers else 'all peers',
                         change.extensive()))
                    continue
                change.nlri.action = OUT.ANNOUNCE
                reactor.configuration.inject_change(peers, change)
                self.log_message('route added to %s : %s' %
                                 (', '.join(peers) if peers else 'all peers',
                                  change.extensive()))
                yield False

            reactor.schedule_rib_check()
            reactor.processes.answer_done(service)
        except ValueError:
            self.log_failure('issue parsing the route')
            reactor.processes.answer(service, 'error')
            yield True
        except IndexError:
            self.log_failure('issue parsing the route')
            reactor.processes.answer(service, 'error')
            yield True
Example #17
0
	def callback ():
		try:
			descriptions,command = extract_neighbors(line)
			peers = match_neighbors(reactor.peers,descriptions)
			if not peers:
				self.log_failure('no neighbor matching the command : %s' % command)
				reactor.processes.answer(service,'error')
				yield True
				return

			changes = self.api_route(command)
			if not changes:
				self.log_failure('command could not parse route in : %s' % command)
				reactor.processes.answer(service,'error')
				yield True
				return

			for change in changes:
				# Change the action to withdraw before checking the route
				change.nlri.action = OUT.WITHDRAW
				# NextHop is a mandatory field (but we do not require in)
				if change.nlri.nexthop is NoNextHop:
					change.nlri.nexthop = NextHop('0.0.0.0')

				if not ParseStaticRoute.check(change):
					self.log_message('invalid route for %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
					continue
				if reactor.configuration.inject_change(peers,change):
					self.log_message('route removed from %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
					yield False
				else:
					self.log_failure('route not found on %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
					yield False

			reactor.processes.answer_done(service)
		except ValueError:
			self.log_failure('issue parsing the route')
			reactor.processes.answer(service,'error')
			yield True
		except IndexError:
			self.log_failure('issue parsing the route')
			reactor.processes.answer(service,'error')
			yield True
Example #18
0
def announce_refresh(self, reactor, service, command):
    def callback(self, command, peers):
        refreshes = self.api_refresh(command)
        if not refreshes:
            self.log_failure(
                "Command could not parse route-refresh command : %s" % command)
            reactor.processes.answer_error(service)
            yield True
            return

        reactor.configuration.inject_refresh(peers, refreshes)
        for refresh in refreshes:
            self.log_message(
                "Sent to %s : %s" %
                (', '.join(peers if peers else [])
                 if peers is not None else 'all peers', refresh.extensive()))

        yield False
        reactor.processes.answer_done(service)

    try:
        descriptions, command = extract_neighbors(command)
        peers = match_neighbors(reactor.established_peers(), descriptions)
        if not peers:
            self.log_failure('no neighbor matching the command : %s' % command)
            reactor.processes.answer_error(service)
            return False
        reactor.asynchronous.schedule(service, command,
                                      callback(self, command, peers))
        return True
    except ValueError:
        self.log_failure('issue parsing the command')
        reactor.processes.answer_error(service)
        return False
    except IndexError:
        self.log_failure('issue parsing the command')
        reactor.processes.answer_error(service)
        return False
Example #19
0
def announce_operational (self, reactor, service, command):
	def callback (self, command, peers):
		operational = self.api_operational(command)
		if not operational:
			self.log_failure("Command could not parse operational command : %s" % command)
			reactor.processes.answer(service,'error')
			yield True
			return

		reactor.configuration.inject_operational(peers,operational)
		self.log_message("operational message sent to %s : %s" % (
			', '.join(peers if peers else []) if peers is not None else 'all peers',operational.extensive()
			)
		)
		yield False
		reactor.processes.answer_done(service)

	if (command.split() + ['be','safe'])[2].lower() not in ('asm','adm','rpcq','rpcp','apcq','apcp','lpcq','lpcp'):
		reactor.processes.answer_done(service)
		return False

	try:
		descriptions,command = extract_neighbors(command)
		peers = match_neighbors(reactor.peers,descriptions)
		if not peers:
			self.log_failure('no neighbor matching the command : %s' % command)
			reactor.processes.answer(service,'error')
			return False
		reactor.asynchronous.schedule(service,command,callback(self,command,peers))
		return True
	except ValueError:
		self.log_failure('issue parsing the command')
		reactor.processes.answer(service,'error')
		return False
	except IndexError:
		self.log_failure('issue parsing the command')
		reactor.processes.answer(service,'error')
		return False
Example #20
0
def teardown (self, reactor, service, line):
	try:
		descriptions,line = extract_neighbors(line)
		if ' ' not in line:
			reactor.processes.answer_error(service)
			return False
		_,code = line.split(' ',1)
		if not code.isdigit():
			reactor.processes.answer_error(service)
			return False
		for key in reactor.established_peers():
			for description in descriptions:
				if match_neighbor(description,key):
					reactor.teardown_peer(key,int(code))
					self.log_message('teardown scheduled for %s' % ' '.join(description))
		reactor.processes.answer_done(service)
		return True
	except ValueError:
		reactor.processes.answer_error(service)
		return False
	except IndexError:
		reactor.processes.answer_error(service)
		return False
Example #21
0
    def callback():
        try:
            descriptions, command = extract_neighbors(line)
            peers = match_neighbors(reactor.peers, descriptions)
            if not peers:
                self.log_failure('no neighbor matching the command : %s' %
                                 command)
                reactor.processes.answer(service, 'error')
                yield True
                return

            changes = self.api_flow(command)
            if not changes:
                self.log_failure('command could not parse flow in : %s' %
                                 command)
                reactor.processes.answer(service, 'error')
                yield True
                return

            for change in changes:
                change.nlri.action = OUT.ANNOUNCE
                reactor.configuration.inject_change(peers, change)
                self.log_message('flow added to %s : %s' %
                                 (', '.join(peers) if peers else 'all peers',
                                  change.extensive()))
                yield False

            reactor.processes.answer_done(service)
        except ValueError:
            self.log_failure('issue parsing the flow')
            reactor.processes.answer(service, 'error')
            yield True
        except IndexError:
            self.log_failure('issue parsing the flow')
            reactor.processes.answer(service, 'error')
            yield True