use of org.batfish.common.BatfishException in project batfish by batfish.
the class CiscoControlPlaneExtractor method exitAggregate_address_rb_stanza.
@Override
public void exitAggregate_address_rb_stanza(Aggregate_address_rb_stanzaContext ctx) {
BgpProcess proc = currentVrf().getBgpProcess();
// Intentional identity comparison
if (_currentPeerGroup == proc.getMasterBgpPeerGroup()) {
boolean summaryOnly = ctx.summary_only != null;
boolean asSet = ctx.as_set != null;
if (ctx.network != null || ctx.prefix != null) {
// ipv4
Prefix prefix;
if (ctx.network != null) {
Ip network = toIp(ctx.network);
Ip subnet = toIp(ctx.subnet);
int prefixLength = subnet.numSubnetBits();
prefix = new Prefix(network, prefixLength);
} else {
// ctx.prefix != null
prefix = Prefix.parse(ctx.prefix.getText());
}
BgpAggregateIpv4Network net = new BgpAggregateIpv4Network(prefix);
net.setAsSet(asSet);
net.setSummaryOnly(summaryOnly);
if (ctx.mapname != null) {
String mapName = ctx.mapname.getText();
int mapLine = ctx.mapname.getStart().getLine();
net.setAttributeMap(mapName);
net.setAttributeMapLine(mapLine);
}
proc.getAggregateNetworks().put(prefix, net);
} else if (ctx.ipv6_prefix != null) {
// ipv6
Prefix6 prefix6 = new Prefix6(ctx.ipv6_prefix.getText());
BgpAggregateIpv6Network net = new BgpAggregateIpv6Network(prefix6);
net.setAsSet(asSet);
net.setSummaryOnly(summaryOnly);
if (ctx.mapname != null) {
String mapName = ctx.mapname.getText();
int mapLine = ctx.mapname.getStart().getLine();
net.setAttributeMap(mapName);
net.setAttributeMapLine(mapLine);
}
proc.getAggregateIpv6Networks().put(prefix6, net);
}
} else if (_currentIpPeerGroup != null || _currentIpv6PeerGroup != null || _currentDynamicIpPeerGroup != null || _currentDynamicIpv6PeerGroup != null || _currentNamedPeerGroup != null) {
throw new BatfishException("unexpected occurrence in peer group/neighbor context");
} else if (ctx.mapname != null) {
String map = ctx.mapname.getText();
int line = ctx.mapname.getStart().getLine();
_configuration.getBgpVrfAggregateAddressRouteMaps().add(map);
_configuration.referenceStructure(CiscoStructureType.ROUTE_MAP, map, CiscoStructureUsage.BGP_VRF_AGGREGATE_ROUTE_MAP, line);
}
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class CiscoControlPlaneExtractor method enterAaa_authentication_login_list.
@Override
public void enterAaa_authentication_login_list(Aaa_authentication_login_listContext ctx) {
AaaAuthenticationLogin login = _configuration.getCf().getAaa().getAuthentication().getLogin();
String name;
if (ctx.DEFAULT() != null) {
name = AaaAuthenticationLogin.DEFAULT_LIST_NAME;
} else if (ctx.variable() != null) {
name = ctx.variable().getText();
} else {
throw new BatfishException("Unsupported mode");
}
_currentAaaAuthenticationLoginList = login.getLists().computeIfAbsent(name, k -> new AaaAuthenticationLoginList());
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class CiscoControlPlaneExtractor method exitUse_session_group_bgp_tail.
@Override
public void exitUse_session_group_bgp_tail(Use_session_group_bgp_tailContext ctx) {
BgpProcess proc = currentVrf().getBgpProcess();
String groupName = ctx.name.getText();
int line = ctx.name.getStart().getLine();
if (_currentIpPeerGroup != null) {
_currentIpPeerGroup.setPeerSession(groupName);
_currentIpPeerGroup.setPeerSessionLine(line);
} else if (_currentNamedPeerGroup != null) {
_currentNamedPeerGroup.setPeerSession(groupName);
_currentNamedPeerGroup.setPeerSessionLine(line);
} else if (_currentPeerGroup == proc.getMasterBgpPeerGroup()) {
// Intentional identity comparison above
throw new BatfishException("Invalid peer context for inheritance");
} else {
todo(ctx, F_BGP_INHERIT_PEER_SESSION_OTHER);
}
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class ApplyPathApplicator method enterPoplt_apply_path.
@Override
public void enterPoplt_apply_path(Poplt_apply_pathContext ctx) {
HierarchyPath applyPathPath = new HierarchyPath();
String pathQuoted = ctx.path.getText();
String pathWithoutQuotes = pathQuoted.substring(1, pathQuoted.length() - 1);
String[] pathComponents = pathWithoutQuotes.split("\\s+");
for (String pathComponent : pathComponents) {
boolean isWildcard = pathComponent.charAt(0) == '<';
if (isWildcard) {
applyPathPath.addWildcardNode(pathComponent);
} else {
applyPathPath.addNode(pathComponent);
}
}
int insertionIndex = _newConfigurationLines.indexOf(_currentSetLine);
List<ParseTree> newLines = null;
try {
newLines = _hierarchy.getApplyPathLines(_currentPath, applyPathPath, _configurationContext);
} catch (BatfishException e) {
_w.redFlag("Could not apply path: " + pathQuoted + ": make sure path is terminated by wildcard (e.g. <*>) representing ip(v6) " + "addresses or prefixes");
}
if (newLines != null) {
_newConfigurationLines.addAll(insertionIndex + 1, newLines);
}
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class ConfigurationBuilder method toComplexPolicyStatement.
private String toComplexPolicyStatement(Policy_expressionContext expr) {
if (expr.pe_nested() != null) {
return toComplexPolicyStatement(expr.pe_nested().policy_expression());
} else if (expr.variable() != null) {
String name = expr.variable().getText();
return name;
} else if (expr.pe_conjunction() != null) {
Set<String> conjuncts = new LinkedHashSet<>();
for (Policy_expressionContext conjunctCtx : expr.pe_conjunction().policy_expression()) {
String conjunctName = toComplexPolicyStatement(conjunctCtx);
conjuncts.add(conjunctName);
}
String conjunctionPolicyName = "~CONJUNCTION_POLICY_" + _conjunctionPolicyIndex + "~";
_conjunctionPolicyIndex++;
PolicyStatement conjunctionPolicy = new PolicyStatement(conjunctionPolicyName, -1);
PsTerm conjunctionPolicyTerm = conjunctionPolicy.getDefaultTerm();
PsFromPolicyStatementConjunction from = new PsFromPolicyStatementConjunction(conjuncts);
conjunctionPolicyTerm.getFroms().add(from);
conjunctionPolicyTerm.getThens().add(PsThenAccept.INSTANCE);
_configuration.getPolicyStatements().put(conjunctionPolicyName, conjunctionPolicy);
return conjunctionPolicyName;
} else if (expr.pe_disjunction() != null) {
Set<String> disjuncts = new LinkedHashSet<>();
for (Policy_expressionContext disjunctCtx : expr.pe_disjunction().policy_expression()) {
String disjunctName = toComplexPolicyStatement(disjunctCtx);
disjuncts.add(disjunctName);
}
String disjunctionPolicyName = "~DISJUNCTION_POLICY_" + _disjunctionPolicyIndex + "~";
_disjunctionPolicyIndex++;
PolicyStatement disjunctionPolicy = new PolicyStatement(disjunctionPolicyName, -1);
PsTerm disjunctionPolicyTerm = disjunctionPolicy.getDefaultTerm();
for (String disjunct : disjuncts) {
PsFromPolicyStatement from = new PsFromPolicyStatement(disjunct);
disjunctionPolicyTerm.getFroms().add(from);
}
disjunctionPolicyTerm.getThens().add(PsThenAccept.INSTANCE);
_configuration.getPolicyStatements().put(disjunctionPolicyName, disjunctionPolicy);
return disjunctionPolicyName;
} else {
throw new BatfishException("Invalid policy expression");
}
}
Aggregations