Search in sources :

Example 56 with BatfishException

use of org.batfish.common.BatfishException in project batfish by batfish.

the class CiscoControlPlaneExtractor method exitRo_network.

@Override
public void exitRo_network(Ro_networkContext ctx) {
    Ip address;
    Ip wildcard;
    if (ctx.prefix != null) {
        Prefix prefix = Prefix.parse(ctx.prefix.getText());
        address = prefix.getStartIp();
        wildcard = prefix.getPrefixWildcard();
    } else {
        address = toIp(ctx.ip);
        wildcard = toIp(ctx.wildcard);
    }
    if (_configuration.getVendor() == ConfigurationFormat.CISCO_ASA) {
        wildcard = wildcard.inverted();
    }
    long area;
    if (ctx.area_int != null) {
        area = toLong(ctx.area_int);
    } else if (ctx.area_ip != null) {
        area = toIp(ctx.area_ip).asLong();
    } else {
        throw new BatfishException("bad area");
    }
    OspfWildcardNetwork network = new OspfWildcardNetwork(address, wildcard, area);
    _currentOspfProcess.getWildcardNetworks().add(network);
}
Also used : BatfishException(org.batfish.common.BatfishException) RedFlagBatfishException(org.batfish.common.RedFlagBatfishException) OspfWildcardNetwork(org.batfish.representation.cisco.OspfWildcardNetwork) Ip(org.batfish.datamodel.Ip) RoutePolicyNextHopIp(org.batfish.representation.cisco.RoutePolicyNextHopIp) Prefix(org.batfish.datamodel.Prefix)

Example 57 with BatfishException

use of org.batfish.common.BatfishException in project batfish by batfish.

the class CiscoControlPlaneExtractor method enterSs_host.

@Override
public void enterSs_host(Ss_hostContext ctx) {
    String hostname;
    if (ctx.ip4 != null) {
        hostname = ctx.ip4.getText();
    } else if (ctx.ip6 != null) {
        hostname = ctx.ip6.getText();
    } else if (ctx.host != null) {
        hostname = ctx.host.getText();
    } else {
        throw new BatfishException("Invalid host");
    }
    Map<String, SnmpHost> hosts = _configuration.getSnmpServer().getHosts();
    SnmpHost host = hosts.computeIfAbsent(hostname, SnmpHost::new);
    _currentSnmpHost = host;
}
Also used : BatfishException(org.batfish.common.BatfishException) RedFlagBatfishException(org.batfish.common.RedFlagBatfishException) SnmpHost(org.batfish.datamodel.SnmpHost)

Example 58 with BatfishException

use of org.batfish.common.BatfishException in project batfish by batfish.

the class CiscoControlPlaneExtractor method enterS_line.

@Override
public void enterS_line(S_lineContext ctx) {
    String lineType = ctx.line_type().getText();
    if (lineType.equals("")) {
        lineType = "<UNNAMED>";
    }
    String nameBase = lineType;
    Integer slot1 = null;
    Integer slot2 = null;
    Integer port1 = null;
    Integer port2 = null;
    List<String> names = new ArrayList<>();
    if (ctx.first != null) {
        if (ctx.slot1 != null) {
            slot1 = toInteger(ctx.slot1);
            slot2 = slot1;
            if (ctx.port1 != null) {
                port1 = toInteger(ctx.port1);
                port2 = port1;
            }
        }
        int first = toInteger(ctx.first);
        int last;
        if (ctx.last != null) {
            if (ctx.slot2 != null) {
                slot2 = toInteger(ctx.slot2);
                if (ctx.port2 != null) {
                    port2 = toInteger(ctx.port2);
                }
            }
            last = toInteger(ctx.last);
        } else {
            last = first;
        }
        if (last < first) {
            throw new BatfishException("Do not support decreasing line range: " + first + " " + last);
        }
        if (slot1 != null && port1 != null) {
            for (int s = slot1; s <= slot2; s++) {
                for (int p = port1; p <= port2; p++) {
                    for (int i = first; i <= last; i++) {
                        String name = nameBase + s + "/" + p + "/" + i;
                        names.add(name);
                    }
                }
            }
        } else if (slot1 != null) {
            for (int s = slot1; s <= slot2; s++) {
                for (int i = first; i <= last; i++) {
                    String name = nameBase + s + "/" + i;
                    names.add(name);
                }
            }
        } else {
            for (int i = first; i <= last; i++) {
                String name = nameBase + i;
                names.add(name);
            }
        }
    } else {
        names.add(nameBase);
    }
    for (String name : names) {
        if (_configuration.getCf().getLines().get(name) == null) {
            Line line = new Line(name);
            line.setLoginAuthentication(AaaAuthenticationLogin.DEFAULT_LIST_NAME);
            _configuration.getCf().getLines().put(name, line);
        }
    }
    _currentLineNames = names;
}
Also used : RouteMapSetAsPathPrependLine(org.batfish.representation.cisco.RouteMapSetAsPathPrependLine) RouteMapMatchAsPathAccessListLine(org.batfish.representation.cisco.RouteMapMatchAsPathAccessListLine) RouteMapSetCommunityNoneLine(org.batfish.representation.cisco.RouteMapSetCommunityNoneLine) RouteMapSetCommunityLine(org.batfish.representation.cisco.RouteMapSetCommunityLine) RouteMapSetDeleteCommunityLine(org.batfish.representation.cisco.RouteMapSetDeleteCommunityLine) RouteMapSetLocalPreferenceLine(org.batfish.representation.cisco.RouteMapSetLocalPreferenceLine) PrefixListLine(org.batfish.representation.cisco.PrefixListLine) ExtendedIpv6AccessListLine(org.batfish.representation.cisco.ExtendedIpv6AccessListLine) RouteMapMatchCommunityListLine(org.batfish.representation.cisco.RouteMapMatchCommunityListLine) ExpandedCommunityListLine(org.batfish.representation.cisco.ExpandedCommunityListLine) RouteMapMatchIpv6AccessListLine(org.batfish.representation.cisco.RouteMapMatchIpv6AccessListLine) RouteMapMatchIpAccessListLine(org.batfish.representation.cisco.RouteMapMatchIpAccessListLine) Prefix6ListLine(org.batfish.representation.cisco.Prefix6ListLine) RouteMapMatchIpPrefixListLine(org.batfish.representation.cisco.RouteMapMatchIpPrefixListLine) RouteMapMatchIpv6PrefixListLine(org.batfish.representation.cisco.RouteMapMatchIpv6PrefixListLine) StandardAccessListLine(org.batfish.representation.cisco.StandardAccessListLine) RouteMapSetAdditiveCommunityLine(org.batfish.representation.cisco.RouteMapSetAdditiveCommunityLine) RouteMapSetAdditiveCommunityListLine(org.batfish.representation.cisco.RouteMapSetAdditiveCommunityListLine) RouteMapMatchTagLine(org.batfish.representation.cisco.RouteMapMatchTagLine) RouteMapSetCommunityListLine(org.batfish.representation.cisco.RouteMapSetCommunityListLine) Line(org.batfish.datamodel.vendor_family.cisco.Line) StandardCommunityListLine(org.batfish.representation.cisco.StandardCommunityListLine) RouteMapSetOriginTypeLine(org.batfish.representation.cisco.RouteMapSetOriginTypeLine) ExtendedAccessListLine(org.batfish.representation.cisco.ExtendedAccessListLine) RouteMapSetMetricLine(org.batfish.representation.cisco.RouteMapSetMetricLine) RouteMapSetNextHopLine(org.batfish.representation.cisco.RouteMapSetNextHopLine) StandardIpv6AccessListLine(org.batfish.representation.cisco.StandardIpv6AccessListLine) IpAsPathAccessListLine(org.batfish.representation.cisco.IpAsPathAccessListLine) RouteMapSetLine(org.batfish.representation.cisco.RouteMapSetLine) BatfishException(org.batfish.common.BatfishException) RedFlagBatfishException(org.batfish.common.RedFlagBatfishException) ArrayList(java.util.ArrayList)

Example 59 with BatfishException

use of org.batfish.common.BatfishException in project batfish by batfish.

the class CiscoControlPlaneExtractor method exitNo_redistribute_connected_rb_stanza.

@Override
public void exitNo_redistribute_connected_rb_stanza(No_redistribute_connected_rb_stanzaContext ctx) {
    BgpProcess proc = currentVrf().getBgpProcess();
    // Intentional identity comparison
    if (_currentPeerGroup == proc.getMasterBgpPeerGroup()) {
        RoutingProtocol sourceProtocol = RoutingProtocol.CONNECTED;
        proc.getRedistributionPolicies().remove(sourceProtocol);
    } else if (_currentIpPeerGroup != null || _currentNamedPeerGroup != null) {
        throw new BatfishException("do not currently handle per-neighbor redistribution policies");
    }
}
Also used : BatfishException(org.batfish.common.BatfishException) RedFlagBatfishException(org.batfish.common.RedFlagBatfishException) RoutingProtocol(org.batfish.datamodel.RoutingProtocol) BgpProcess(org.batfish.representation.cisco.BgpProcess)

Example 60 with BatfishException

use of org.batfish.common.BatfishException in project batfish by batfish.

the class CiscoControlPlaneExtractor method enterCip_transform_set.

@Override
public void enterCip_transform_set(Cip_transform_setContext ctx) {
    if (_currentIpsecTransformSet != null) {
        throw new BatfishException("IpsecTransformSet should be null!");
    }
    _currentIpsecTransformSet = new IpsecTransformSet(ctx.name.getText(), ctx.getStart().getLine());
    IpsecProposal proposal = _currentIpsecTransformSet.getProposal();
    proposal.setEncryptionAlgorithm(toEncryptionAlgorithm(ctx.ipsec_encryption()));
    proposal.setAuthenticationAlgorithm(toIpsecAuthenticationAlgorithm(ctx.ipsec_authentication()));
    proposal.setProtocol(toProtocol(ctx.ipsec_authentication()));
}
Also used : BatfishException(org.batfish.common.BatfishException) RedFlagBatfishException(org.batfish.common.RedFlagBatfishException) IpsecTransformSet(org.batfish.representation.cisco.IpsecTransformSet) IpsecProposal(org.batfish.datamodel.IpsecProposal)

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