Search in sources :

Example 91 with BatfishException

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");
        }
    }
}
Also used : CleanBatfishException(org.batfish.common.CleanBatfishException) BatfishException(org.batfish.common.BatfishException) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) HostConfiguration(org.batfish.representation.host.HostConfiguration) Configuration(org.batfish.datamodel.Configuration) ImmutableConfiguration(org.apache.commons.configuration2.ImmutableConfiguration) AwsConfiguration(org.batfish.representation.aws.AwsConfiguration) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration) VendorConfiguration(org.batfish.vendor.VendorConfiguration) BgpAdvertisementType(org.batfish.datamodel.BgpAdvertisement.BgpAdvertisementType) RoutesByVrf(org.batfish.datamodel.collections.RoutesByVrf) Vrf(org.batfish.datamodel.Vrf) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf)

Example 92 with BatfishException

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);
}
Also used : PsFromFamilyInet6(org.batfish.representation.juniper.PsFromFamilyInet6) BatfishException(org.batfish.common.BatfishException) PsFrom(org.batfish.representation.juniper.PsFrom) PsFromFamilyInet(org.batfish.representation.juniper.PsFromFamilyInet)

Example 93 with BatfishException

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);
}
Also used : BatfishException(org.batfish.common.BatfishException) IsisSettings(org.batfish.representation.juniper.IsisSettings)

Example 94 with BatfishException

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;
}
Also used : TcpFlags(org.batfish.datamodel.TcpFlags) FwFromTcpFlags(org.batfish.representation.juniper.FwFromTcpFlags) BatfishException(org.batfish.common.BatfishException) Tcp_flags_atomContext(org.batfish.grammar.flatjuniper.FlatJuniperParser.Tcp_flags_atomContext) Tcp_flags_literalContext(org.batfish.grammar.flatjuniper.FlatJuniperParser.Tcp_flags_literalContext)

Example 95 with BatfishException

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;
}
Also used : BatfishException(org.batfish.common.BatfishException) RedFlagBatfishException(org.batfish.common.RedFlagBatfishException) MacAccessList(org.batfish.representation.cisco.MacAccessList)

Aggregations

BatfishException (org.batfish.common.BatfishException)264 IOException (java.io.IOException)61 Path (java.nio.file.Path)54 CleanBatfishException (org.batfish.common.CleanBatfishException)35 RedFlagBatfishException (org.batfish.common.RedFlagBatfishException)34 TreeMap (java.util.TreeMap)31 ArrayList (java.util.ArrayList)30 JSONException (org.codehaus.jettison.json.JSONException)30 Ip (org.batfish.datamodel.Ip)25 JSONObject (org.codehaus.jettison.json.JSONObject)25 Configuration (org.batfish.datamodel.Configuration)24 Map (java.util.Map)23 Prefix (org.batfish.datamodel.Prefix)22 HashMap (java.util.HashMap)20 HashSet (java.util.HashSet)20 TreeSet (java.util.TreeSet)20 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)18 Test (org.junit.Test)18 Set (java.util.Set)17 SortedMap (java.util.SortedMap)17