Example #1
0
def juniper_parse_sh_route(text, prependas):
    def split_ases(ases):
        return str.split(ases)

    DEFAULT_PARAMS = {"recuse": False, "reconly": False, "aggr": None}

    res = []

    bgp_start = False
    params = dict(DEFAULT_PARAMS)
    for l in str.splitlines(text):
        ulgmodel.debug("JUNIPER PARSE SHOW ROUTE: l=" + str(l))
        if juniper_bgp_path_active_regex.match(l):
            ulgmodel.debug("JUNIPER PARSE SHOW ROUTE: ACTIVE PATH")
            bgp_start = True
            params["recuse"] = True
            continue

        if juniper_bgp_path_regex.match(l):
            ulgmodel.debug("JUNIPER PARSE SHOW ROUTE: NON-ACTIVE PATH")
            bgp_start = True
            continue

        m = juniper_bgp_path_content.match(l)
        if m and bgp_start:
            ulgmodel.debug("JUNIPER PARSE SHOW ROUTE: path=" + str(m.group(1)))
            ases = [ulgmodel.annotateAS("AS" + str(asn)) for asn in [prependas] + split_ases(m.group(1))]
            res.append((ases, params))
            params = dict(DEFAULT_PARAMS)
            bgp_start = False
            continue

    ulgmodel.debug("JUNIPER PARSE SHOW ROUTE: res=" + str(res))
    return res
Example #2
0
def bird_parse_sh_route_all(text, prependas):
    def split_ases(ases):
        return str.split(ases)

    DEFAULT_PARAMS = {'recuse': False, 'reconly': False, 'aggr': None}

    res = []
    params = dict(DEFAULT_PARAMS)
    for l in str.splitlines(text):
        m = bird_sh_route_all_nexthop_regexp.match(l)
        if (m):
            params['peer'] = m.group(2)
            if (bird_sh_route_all_used_regexp.match(l)):
                params['recuse'] = True

        m = bird_sh_route_all_ases_regexp.match(l)
        if (m):
            ases = [
                ulgmodel.annotateAS("AS" + str(asn))
                for asn in [prependas] + split_ases(m.group(2))
            ]
            res.append((ases, params))
            params = dict(DEFAULT_PARAMS)
            continue

    return res
Example #3
0
def cisco_parse_sh_bgp_uni(lines,prependas):
	def split_ases(ases):
		if ases == 'Local':
			return []
		else:
			return str.split(ases)

	def get_info(info):
		res = {'recuse':False, 'reconly':False, 'aggr':None}

		for g in info.split(','):
#			if(regex_sh_bgp_uni_recuse.match(g)):
#				res['recuse'] = True
			if(regex_sh_bgp_uni_reconly.match(g)):
				res['reconly'] = True

			m = regex_sh_bgp_uni_aggr.match(g)
			if(m):
				res['aggr'] = m.group(1)

		return res

	paths = []
	table_prestarted = False
	table_started = False
	for l in str.splitlines(lines):
		if not table_started:
			if table_prestarted:
				# if prestarted and a line not containing only numbers of
				# update groups, start immediately
				if not re.match('^[0-9\s]+$',l):
					table_started = True

			# if not prestarted and match occures, wait for next line
			if(regex_sh_bgp_uni_table_start.match(l)):
				table_prestarted = True


		if table_started:
			m = regex_sh_bgp_uni_asline.match(l)
			if(m):
				ases = [ulgmodel.annotateAS("AS"+str(asn)) for asn in [prependas] + split_ases(m.group(2))]
				infotext = m.group(3)
				if(infotext):
					paths.append((ases,get_info(infotext)))
				else:
					paths.append((ases,{'recuse':False, 'reconly':False, 'aggr':None}))
				continue

			m = regex_sh_bgp_uni_peerline.match(l)
			if(m):
				paths[-1][1]['peer'] = m.group(1)
				continue

			m = regex_sh_bgp_uni_origline_best.match(l)
			if(m):
				paths[-1][1]['recuse'] = True

	return paths
Example #4
0
def cisco_parse_sh_bgp_uni(lines,prependas):
	def split_ases(ases):
		return str.split(ases)

	def get_info(info):
		res = {'recuse':False, 'reconly':False, 'aggr':None}

		for g in info.split(','):
			if(regex_sh_bgp_uni_recuse.match(g)):
				res['recuse'] = True
			if(regex_sh_bgp_uni_reconly.match(g)):
				res['reconly'] = True

			m = regex_sh_bgp_uni_aggr.match(g)
			if(m):
				res['aggr'] = m.group(1)

		return res

	paths = []
	table_prestarted = False
	table_started = False
	for l in str.splitlines(lines):
		if(table_started):
			m = regex_sh_bgp_uni_asline.match(l)
			if(m):
				ases = [ulgmodel.annotateAS("AS"+str(asn)) for asn in [prependas] + split_ases(m.group(2))]
				infotext = m.group(3)
				if(infotext):
					paths.append((ases,get_info(infotext)))
				else:
					paths.append((ases,{'recuse':False, 'reconly':False, 'aggr':None}))
				continue

			m = regex_sh_bgp_uni_peerline.match(l)
			if(m):
				paths[-1][1]['peer'] = m.group(1)
				continue

			m = regex_sh_bgp_uni_origline_best.match(l)
			if(m):
				paths[-1][1]['recuse'] = True
		else:
			if(table_prestarted):
				table_started = True
			if(regex_sh_bgp_uni_table_start.match(l)):
				table_prestarted = True

	return paths
Example #5
0
def bird_parse_sh_route_all(text,prependas):
    def split_ases(ases):
		return str.split(ases)

    DEFAULT_PARAMS = {'recuse':False, 'reconly':False, 'aggr':None}

    res = []
    params = dict(DEFAULT_PARAMS)
    for l in str.splitlines(text):
        m = bird_sh_route_all_nexthop_regexp.match(l)
        if(m):
            params['peer'] = m.group(2)
            if(bird_sh_route_all_used_regexp.match(l)):
                params['recuse'] = True

        m = bird_sh_route_all_ases_regexp.match(l)
        if(m):
            ases = [ulgmodel.annotateAS("AS"+str(asn)) for asn in [prependas] + split_ases(m.group(2))]
            res.append((ases,params))
            params = dict(DEFAULT_PARAMS)
            continue

    return res
Example #6
0
def juniper_parse_sh_route(text, prependas):
    def split_ases(ases):
        return str.split(ases)

    DEFAULT_PARAMS = {'recuse': False, 'reconly': False, 'aggr': None}

    res = []

    bgp_start = False
    params = dict(DEFAULT_PARAMS)
    for l in str.splitlines(text):
        ulgmodel.debug("JUNIPER PARSE SHOW ROUTE: l=" + str(l))
        if (juniper_bgp_path_active_regex.match(l)):
            ulgmodel.debug("JUNIPER PARSE SHOW ROUTE: ACTIVE PATH")
            bgp_start = True
            params['recuse'] = True
            continue

        if (juniper_bgp_path_regex.match(l)):
            ulgmodel.debug("JUNIPER PARSE SHOW ROUTE: NON-ACTIVE PATH")
            bgp_start = True
            continue

        m = juniper_bgp_path_content.match(l)
        if (m and bgp_start):
            ulgmodel.debug("JUNIPER PARSE SHOW ROUTE: path=" + str(m.group(1)))
            ases = [
                ulgmodel.annotateAS("AS" + str(asn))
                for asn in [prependas] + split_ases(m.group(1))
            ]
            res.append((ases, params))
            params = dict(DEFAULT_PARAMS)
            bgp_start = False
            continue

    ulgmodel.debug("JUNIPER PARSE SHOW ROUTE: res=" + str(res))
    return res
Example #7
0
def cisco_parse_sh_bgp_uni(lines, prependas):
    def split_ases(ases):
        if ases == 'Local':
            return []
        else:
            return str.split(ases)

    def get_info(info):
        res = {'recuse': False, 'reconly': False, 'aggr': None}

        for g in info.split(','):
            #			if(regex_sh_bgp_uni_recuse.match(g)):
            #				res['recuse'] = True
            if (regex_sh_bgp_uni_reconly.match(g)):
                res['reconly'] = True

            m = regex_sh_bgp_uni_aggr.match(g)
            if (m):
                res['aggr'] = m.group(1)

        return res

    paths = []
    table_prestarted = False
    table_started = False
    for l in str.splitlines(lines):
        if not table_started:
            if table_prestarted:
                # if prestarted and a line not containing only numbers of
                # update groups, start immediately
                if not re.match('^[0-9\s]+$', l):
                    table_started = True

            # if not prestarted and match occures, wait for next line
            if (regex_sh_bgp_uni_table_start.match(l)):
                table_prestarted = True

        if table_started:
            m = regex_sh_bgp_uni_asline.match(l)
            if (m):
                ases = [
                    ulgmodel.annotateAS("AS" + str(asn))
                    for asn in [prependas] + split_ases(m.group(2))
                ]
                infotext = m.group(3)
                if (infotext):
                    paths.append((ases, get_info(infotext)))
                else:
                    paths.append((ases, {
                        'recuse': False,
                        'reconly': False,
                        'aggr': None
                    }))
                continue

            m = regex_sh_bgp_uni_peerline.match(l)
            if (m):
                paths[-1][1]['peer'] = m.group(1)
                continue

            m = regex_sh_bgp_uni_origline_best.match(l)
            if (m):
                paths[-1][1]['recuse'] = True

    return paths