Skip to content

Commit

Permalink
communities meta moved into config builder
Browse files Browse the repository at this point in the history
  • Loading branch information
pierky committed Feb 6, 2017
1 parent d602155 commit bfc7ac2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
9 changes: 9 additions & 0 deletions pierky/arouteserver/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ def enrich_config_peeringdb(self, client):
)
)

def enrich_config_communities(self):
for comm_name in ConfigParserGeneral.COMMUNITIES_SCHEMA:
comm = ConfigParserGeneral.COMMUNITIES_SCHEMA[comm_name]
self.cfg_general["communities"][comm_name]["type"] = comm["type"]
self.cfg_general["communities"][comm_name]["peer_as"] = comm.get("peer_as", False)

def enrich_config(self):
errors = False

Expand Down Expand Up @@ -389,6 +395,9 @@ def enrich_config(self):
if str(e):
logging.error(str(e))

# Communities meta-data useful in J2 templates
self.enrich_config_communities()

if errors:
raise BuilderError()

Expand Down
62 changes: 29 additions & 33 deletions pierky/arouteserver/config/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ class ConfigParserGeneral(ConfigParserBase):

ROOT = "cfg"

COMMUNITIES_SCHEMA = {
"origin_present_in_as_set": { "type": "outbound" },
"origin_not_present_in_as_set": { "type": "outbound" },
"prefix_present_in_as_set": { "type": "outbound" },
"prefix_not_present_in_as_set": { "type": "outbound" },
"roa_valid": { "type": "outbound" },
"roa_invalid": { "type": "outbound" },
"roa_unknown": { "type": "outbound" },

"blackholing": { "type": "inbound" },
"do_not_announce_to_any": { "type": "inbound" },
"do_not_announce_to_peer": { "type": "inbound", "peer_as": True },
"announce_to_peer": { "type": "inbound", "peer_as": True },
"prepend_once_to_any": { "type": "inbound" },
"prepend_twice_to_any": { "type": "inbound" },
"prepend_thrice_to_any": { "type": "inbound" },
}

def parse(self):
"""
Contents of cfg dict is updated/normalized by validators.
Expand Down Expand Up @@ -110,28 +128,8 @@ def parse(self):
else:
rs_as_macro = None

communities = {
"origin_present_in_as_set": { "type": "outbound" },
"origin_not_present_in_as_set": { "type": "outbound" },
"prefix_present_in_as_set": { "type": "outbound" },
"prefix_not_present_in_as_set": { "type": "outbound" },
"roa_valid": { "type": "outbound" },
"roa_invalid": { "type": "outbound" },
"roa_unknown": { "type": "outbound" },

"blackholing": { "type": "inbound" },
"do_not_announce_to_any": { "type": "inbound" },
"do_not_announce_to_peer": { "type": "inbound", "peer_as": True },
"announce_to_peer": { "type": "inbound", "peer_as": True },
"prepend_once_to_any": { "type": "inbound" },
"prepend_twice_to_any": { "type": "inbound" },
"prepend_thrice_to_any": { "type": "inbound" },
}
inbound_communities = []
outbound_communities = []

for comm in communities:
peer_as = communities[comm].get("peer_as", False)
for comm in self.COMMUNITIES_SCHEMA:
peer_as = self.COMMUNITIES_SCHEMA[comm].get("peer_as", False)

schema["cfg"]["communities"][comm] = {
"std": ValidatorCommunityStd(rs_as_macro, mandatory=False,
Expand All @@ -141,12 +139,6 @@ def parse(self):
"ext": ValidatorCommunityExt(rs_as_macro, mandatory=False,
peer_as_macro_needed=peer_as),
}
if communities[comm]["type"] == "outbound":
outbound_communities.append(comm)
else:
inbound_communities.append(comm)
inbound_communities = sorted(inbound_communities)
outbound_communities = sorted(outbound_communities)

try:
ConfigParserBase.validate(schema, self.cfg)
Expand All @@ -156,11 +148,6 @@ def parse(self):
logging.error(str(e))
raise ConfigError()

# Set community type and peer_as macro
for comm in self.cfg["cfg"]["communities"]:
self.cfg["cfg"]["communities"][comm]["type"] = communities[comm]["type"]
self.cfg["cfg"]["communities"][comm]["peer_as"] = communities[comm].get("peer_as", False)

# Warning: missing global black list.
if not self.cfg["cfg"]["filtering"].get("global_black_list_pref"):
logging.warning("The 'filtering.global_black_list_pref' option is "
Expand Down Expand Up @@ -257,6 +244,15 @@ def communities_overlap(communities, comm1_tag, comm2_tag,
if part1 != part2:
break

outbound_communities = sorted(
[c for c in self.COMMUNITIES_SCHEMA
if self.COMMUNITIES_SCHEMA[c]["type"] == "outbound"]
)
inbound_communities = sorted(
[c for c in self.COMMUNITIES_SCHEMA
if self.COMMUNITIES_SCHEMA[c]["type"] == "inbound"]
)

for comm1_tag in inbound_communities:
for comm2_tag in outbound_communities:
if comm1_tag == comm2_tag:
Expand Down

0 comments on commit bfc7ac2

Please sign in to comment.