use of org.batfish.common.BatfishException in project batfish by batfish.
the class Batfish method initBgpAdvertisements.
@Override
public void initBgpAdvertisements(Map<String, Configuration> configurations) {
Set<BgpAdvertisement> globalBgpAdvertisements = getDataPlanePlugin().getAdvertisements();
for (Configuration node : configurations.values()) {
node.initBgpAdvertisements();
for (Vrf vrf : node.getVrfs().values()) {
vrf.initBgpAdvertisements();
}
}
for (BgpAdvertisement bgpAdvertisement : globalBgpAdvertisements) {
BgpAdvertisementType type = bgpAdvertisement.getType();
String srcVrf = bgpAdvertisement.getSrcVrf();
String dstVrf = bgpAdvertisement.getDstVrf();
switch(type) {
case EBGP_ORIGINATED:
{
String originationNodeName = bgpAdvertisement.getSrcNode();
Configuration originationNode = configurations.get(originationNodeName);
if (originationNode != null) {
originationNode.getBgpAdvertisements().add(bgpAdvertisement);
originationNode.getOriginatedAdvertisements().add(bgpAdvertisement);
originationNode.getOriginatedEbgpAdvertisements().add(bgpAdvertisement);
Vrf originationVrf = originationNode.getVrfs().get(srcVrf);
originationVrf.getBgpAdvertisements().add(bgpAdvertisement);
originationVrf.getOriginatedAdvertisements().add(bgpAdvertisement);
originationVrf.getOriginatedEbgpAdvertisements().add(bgpAdvertisement);
} else {
throw new BatfishException("Originated bgp advertisement refers to missing node: \"" + originationNodeName + "\"");
}
break;
}
case IBGP_ORIGINATED:
{
String originationNodeName = bgpAdvertisement.getSrcNode();
Configuration originationNode = configurations.get(originationNodeName);
if (originationNode != null) {
originationNode.getBgpAdvertisements().add(bgpAdvertisement);
originationNode.getOriginatedAdvertisements().add(bgpAdvertisement);
originationNode.getOriginatedIbgpAdvertisements().add(bgpAdvertisement);
Vrf originationVrf = originationNode.getVrfs().get(srcVrf);
originationVrf.getBgpAdvertisements().add(bgpAdvertisement);
originationVrf.getOriginatedAdvertisements().add(bgpAdvertisement);
originationVrf.getOriginatedIbgpAdvertisements().add(bgpAdvertisement);
} else {
throw new BatfishException("Originated bgp advertisement refers to missing node: \"" + originationNodeName + "\"");
}
break;
}
case EBGP_RECEIVED:
{
String recevingNodeName = bgpAdvertisement.getDstNode();
Configuration receivingNode = configurations.get(recevingNodeName);
if (receivingNode != null) {
receivingNode.getBgpAdvertisements().add(bgpAdvertisement);
receivingNode.getReceivedAdvertisements().add(bgpAdvertisement);
receivingNode.getReceivedEbgpAdvertisements().add(bgpAdvertisement);
Vrf receivingVrf = receivingNode.getVrfs().get(dstVrf);
receivingVrf.getBgpAdvertisements().add(bgpAdvertisement);
receivingVrf.getReceivedAdvertisements().add(bgpAdvertisement);
receivingVrf.getReceivedEbgpAdvertisements().add(bgpAdvertisement);
}
break;
}
case IBGP_RECEIVED:
{
String recevingNodeName = bgpAdvertisement.getDstNode();
Configuration receivingNode = configurations.get(recevingNodeName);
if (receivingNode != null) {
receivingNode.getBgpAdvertisements().add(bgpAdvertisement);
receivingNode.getReceivedAdvertisements().add(bgpAdvertisement);
receivingNode.getReceivedIbgpAdvertisements().add(bgpAdvertisement);
Vrf receivingVrf = receivingNode.getVrfs().get(dstVrf);
receivingVrf.getBgpAdvertisements().add(bgpAdvertisement);
receivingVrf.getReceivedAdvertisements().add(bgpAdvertisement);
receivingVrf.getReceivedIbgpAdvertisements().add(bgpAdvertisement);
}
break;
}
case EBGP_SENT:
{
String sendingNodeName = bgpAdvertisement.getSrcNode();
Configuration sendingNode = configurations.get(sendingNodeName);
if (sendingNode != null) {
sendingNode.getBgpAdvertisements().add(bgpAdvertisement);
sendingNode.getSentAdvertisements().add(bgpAdvertisement);
sendingNode.getSentEbgpAdvertisements().add(bgpAdvertisement);
Vrf sendingVrf = sendingNode.getVrfs().get(srcVrf);
sendingVrf.getBgpAdvertisements().add(bgpAdvertisement);
sendingVrf.getSentAdvertisements().add(bgpAdvertisement);
sendingVrf.getSentEbgpAdvertisements().add(bgpAdvertisement);
}
break;
}
case IBGP_SENT:
{
String sendingNodeName = bgpAdvertisement.getSrcNode();
Configuration sendingNode = configurations.get(sendingNodeName);
if (sendingNode != null) {
sendingNode.getBgpAdvertisements().add(bgpAdvertisement);
sendingNode.getSentAdvertisements().add(bgpAdvertisement);
sendingNode.getSentIbgpAdvertisements().add(bgpAdvertisement);
Vrf sendingVrf = sendingNode.getVrfs().get(srcVrf);
sendingVrf.getBgpAdvertisements().add(bgpAdvertisement);
sendingVrf.getSentAdvertisements().add(bgpAdvertisement);
sendingVrf.getSentIbgpAdvertisements().add(bgpAdvertisement);
}
break;
}
default:
throw new BatfishException("Invalid bgp advertisement type");
}
}
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class ConfigurationBuilder method exitPopsf_family.
@Override
public void exitPopsf_family(Popsf_familyContext ctx) {
PsFrom from;
if (ctx.INET() != null) {
from = new PsFromFamilyInet();
} else if (ctx.INET6() != null) {
from = new PsFromFamilyInet6();
} else {
throw new BatfishException("Unsupported family: " + ctx.getText());
}
_currentPsTerm.getFroms().add(from);
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class ConfigurationBuilder method enterIs_level.
@Override
public void enterIs_level(Is_levelContext ctx) {
IsisSettings isisSettings = _currentRoutingInstance.getIsisSettings();
int level = toInt(ctx.DEC());
switch(level) {
case 1:
_currentIsisLevelSettings = isisSettings.getLevel1Settings();
break;
case 2:
_currentIsisLevelSettings = isisSettings.getLevel2Settings();
break;
default:
throw new BatfishException("invalid level: " + level);
}
_currentIsisLevelSettings.setEnabled(true);
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class ConfigurationBuilder method toTcpFlags.
private static TcpFlags toTcpFlags(Tcp_flags_alternativeContext ctx) {
TcpFlags tcpFlags = new TcpFlags();
for (Tcp_flags_literalContext literalCtx : ctx.literals) {
boolean value = literalCtx.BANG() == null;
Tcp_flags_atomContext atom = literalCtx.tcp_flags_atom();
if (atom.ACK() != null) {
tcpFlags.setUseAck(true);
tcpFlags.setAck(value);
} else if (atom.CWR() != null) {
tcpFlags.setUseCwr(true);
tcpFlags.setCwr(value);
} else if (atom.ECE() != null) {
tcpFlags.setUseEce(true);
tcpFlags.setEce(value);
} else if (atom.FIN() != null) {
tcpFlags.setUseFin(true);
tcpFlags.setFin(value);
} else if (atom.PSH() != null) {
tcpFlags.setUsePsh(true);
tcpFlags.setPsh(value);
} else if (atom.RST() != null) {
tcpFlags.setUseRst(true);
tcpFlags.setRst(value);
} else if (atom.SYN() != null) {
tcpFlags.setUseSyn(true);
tcpFlags.setSyn(value);
} else if (atom.URG() != null) {
tcpFlags.setUseUrg(true);
tcpFlags.setUrg(value);
} else {
throw new BatfishException("Invalid tcp-flags atom: " + atom.getText());
}
}
return tcpFlags;
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class CiscoControlPlaneExtractor method enterS_mac_access_list_extended.
@Override
public void enterS_mac_access_list_extended(S_mac_access_list_extendedContext ctx) {
String name;
int line;
if (ctx.num != null) {
name = ctx.num.getText();
line = ctx.num.getLine();
} else if (ctx.name != null) {
name = ctx.name.getText();
line = ctx.name.getStart().getLine();
} else {
throw new BatfishException("Could not determine name of extended mac access-list");
}
MacAccessList list = _configuration.getMacAccessLists().computeIfAbsent(name, n -> new MacAccessList(n, line));
_currentMacAccessList = list;
}
Aggregations