Search in sources :

Example 71 with Prefix

use of org.batfish.datamodel.Prefix in project batfish by batfish.

the class CiscoControlPlaneExtractor method exitBgp_listen_range_rb_stanza.

@Override
public void exitBgp_listen_range_rb_stanza(Bgp_listen_range_rb_stanzaContext ctx) {
    String name = ctx.name.getText();
    int line = ctx.name.getStart().getLine();
    BgpProcess proc = currentVrf().getBgpProcess();
    if (ctx.IP_PREFIX() != null) {
        Prefix prefix = Prefix.parse(ctx.IP_PREFIX().getText());
        DynamicIpBgpPeerGroup pg = proc.addDynamicIpPeerGroup(prefix);
        pg.setGroupName(name);
        pg.setGroupNameLine(line);
        if (ctx.as != null) {
            int remoteAs = toInteger(ctx.as);
            pg.setRemoteAs(remoteAs);
        }
    } else if (ctx.IPV6_PREFIX() != null) {
        Prefix6 prefix6 = new Prefix6(ctx.IPV6_PREFIX().getText());
        DynamicIpv6BgpPeerGroup pg = proc.addDynamicIpv6PeerGroup(prefix6);
        pg.setGroupName(name);
        pg.setGroupNameLine(line);
        if (ctx.as != null) {
            int remoteAs = toInteger(ctx.as);
            pg.setRemoteAs(remoteAs);
        }
    }
}
Also used : DynamicIpv6BgpPeerGroup(org.batfish.representation.cisco.DynamicIpv6BgpPeerGroup) BgpProcess(org.batfish.representation.cisco.BgpProcess) Prefix(org.batfish.datamodel.Prefix) DynamicIpBgpPeerGroup(org.batfish.representation.cisco.DynamicIpBgpPeerGroup) Prefix6(org.batfish.datamodel.Prefix6)

Example 72 with Prefix

use of org.batfish.datamodel.Prefix in project batfish by batfish.

the class CiscoControlPlaneExtractor method exitRs_route.

@Override
public void exitRs_route(Rs_routeContext ctx) {
    if (ctx.prefix != null) {
        Prefix prefix = Prefix.parse(ctx.prefix.getText());
        Ip nextHopIp = Route.UNSET_ROUTE_NEXT_HOP_IP;
        String nextHopInterface = null;
        if (ctx.nhip != null) {
            nextHopIp = new Ip(ctx.nhip.getText());
        }
        if (ctx.nhint != null) {
            nextHopInterface = getCanonicalInterfaceName(ctx.nhint.getText());
        }
        int distance = DEFAULT_STATIC_ROUTE_DISTANCE;
        if (ctx.distance != null) {
            distance = toInteger(ctx.distance);
        }
        Integer tag = null;
        if (ctx.tag != null) {
            tag = toInteger(ctx.tag);
        }
        boolean permanent = ctx.PERMANENT() != null;
        Integer track = null;
        if (ctx.track != null) {
        // TODO: handle named instead of numbered track
        }
        StaticRoute route = new StaticRoute(prefix, nextHopIp, nextHopInterface, distance, tag, track, permanent);
        currentVrf().getStaticRoutes().add(route);
    } else if (ctx.prefix6 != null) {
    // TODO: ipv6 static route
    }
}
Also used : StaticRoute(org.batfish.representation.cisco.StaticRoute) Ip(org.batfish.datamodel.Ip) RoutePolicyNextHopIp(org.batfish.representation.cisco.RoutePolicyNextHopIp) Prefix(org.batfish.datamodel.Prefix)

Example 73 with Prefix

use of org.batfish.datamodel.Prefix in project batfish by batfish.

the class CiscoControlPlaneExtractor method enterRoa_interface.

@Override
public void enterRoa_interface(Roa_interfaceContext ctx) {
    String ifaceName = ctx.iname.getText();
    String canonicalIfaceName = getCanonicalInterfaceName(ifaceName);
    Interface iface = _configuration.getInterfaces().get(canonicalIfaceName);
    if (iface == null) {
        _w.redFlag("OSPF: Interface: '" + ifaceName + "' not declared before OSPF process");
        iface = addInterface(canonicalIfaceName, ctx.iname, false);
    }
    // whatever
    for (InterfaceAddress address : iface.getAllAddresses()) {
        Prefix prefix = address.getPrefix();
        OspfNetwork network = new OspfNetwork(prefix, _currentOspfArea);
        _currentOspfProcess.getNetworks().add(network);
    }
    _currentOspfInterface = iface.getName();
}
Also used : InterfaceAddress(org.batfish.datamodel.InterfaceAddress) OspfNetwork(org.batfish.representation.cisco.OspfNetwork) Prefix(org.batfish.datamodel.Prefix) VrrpInterface(org.batfish.representation.cisco.VrrpInterface) Interface(org.batfish.representation.cisco.Interface)

Example 74 with Prefix

use of org.batfish.datamodel.Prefix in project batfish by batfish.

the class CiscoControlPlaneExtractor method exitIp_prefix_list_tail.

@Override
public void exitIp_prefix_list_tail(Ip_prefix_list_tailContext ctx) {
    LineAction action = toLineAction(ctx.action);
    Prefix prefix = Prefix.parse(ctx.prefix.getText());
    int prefixLength = prefix.getPrefixLength();
    int minLen = prefixLength;
    int maxLen = prefixLength;
    if (ctx.minpl != null) {
        minLen = toInteger(ctx.minpl);
        maxLen = Prefix.MAX_PREFIX_LENGTH;
    }
    if (ctx.maxpl != null) {
        maxLen = toInteger(ctx.maxpl);
    }
    if (ctx.eqpl != null) {
        minLen = toInteger(ctx.eqpl);
        maxLen = toInteger(ctx.eqpl);
    }
    SubRange lengthRange = new SubRange(minLen, maxLen);
    PrefixListLine line = new PrefixListLine(action, prefix, lengthRange);
    _currentPrefixList.addLine(line);
}
Also used : LineAction(org.batfish.datamodel.LineAction) PrefixListLine(org.batfish.representation.cisco.PrefixListLine) RouteMapMatchIpPrefixListLine(org.batfish.representation.cisco.RouteMapMatchIpPrefixListLine) RouteMapMatchIpv6PrefixListLine(org.batfish.representation.cisco.RouteMapMatchIpv6PrefixListLine) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange)

Example 75 with Prefix

use of org.batfish.datamodel.Prefix in project batfish by batfish.

the class CiscoControlPlaneExtractor method exitPrefix_set_elem.

@Override
public void exitPrefix_set_elem(Prefix_set_elemContext ctx) {
    String name = _currentPrefixSetName;
    if (name != null) {
        if (ctx.ipa != null || ctx.prefix != null) {
            PrefixList pl = _configuration.getPrefixLists().computeIfAbsent(name, n -> new PrefixList(n, _currentPrefixSetDefinitionLine));
            Prefix prefix;
            if (ctx.ipa != null) {
                prefix = new Prefix(toIp(ctx.ipa), Prefix.MAX_PREFIX_LENGTH);
            } else {
                prefix = Prefix.parse(ctx.prefix.getText());
            }
            int prefixLength = prefix.getPrefixLength();
            int minLen = prefixLength;
            int maxLen = prefixLength;
            if (ctx.minpl != null) {
                minLen = toInteger(ctx.minpl);
                maxLen = Prefix.MAX_PREFIX_LENGTH;
            }
            if (ctx.maxpl != null) {
                maxLen = toInteger(ctx.maxpl);
            }
            if (ctx.eqpl != null) {
                minLen = toInteger(ctx.eqpl);
                maxLen = toInteger(ctx.eqpl);
            }
            SubRange lengthRange = new SubRange(minLen, maxLen);
            PrefixListLine line = new PrefixListLine(LineAction.ACCEPT, prefix, lengthRange);
            pl.addLine(line);
        } else {
            Prefix6List pl = _configuration.getPrefix6Lists().computeIfAbsent(name, n -> new Prefix6List(n, _currentPrefixSetDefinitionLine));
            Prefix6 prefix6;
            if (ctx.ipv6a != null) {
                prefix6 = new Prefix6(toIp6(ctx.ipv6a), Prefix6.MAX_PREFIX_LENGTH);
            } else {
                prefix6 = new Prefix6(ctx.ipv6_prefix.getText());
            }
            int prefixLength = prefix6.getPrefixLength();
            int minLen = prefixLength;
            int maxLen = prefixLength;
            if (ctx.minpl != null) {
                minLen = toInteger(ctx.minpl);
                maxLen = Prefix6.MAX_PREFIX_LENGTH;
            }
            if (ctx.maxpl != null) {
                maxLen = toInteger(ctx.maxpl);
            }
            if (ctx.eqpl != null) {
                minLen = toInteger(ctx.eqpl);
                maxLen = toInteger(ctx.eqpl);
            }
            SubRange lengthRange = new SubRange(minLen, maxLen);
            Prefix6ListLine line = new Prefix6ListLine(LineAction.ACCEPT, prefix6, lengthRange);
            pl.addLine(line);
        }
    }
}
Also used : Prefix6ListLine(org.batfish.representation.cisco.Prefix6ListLine) Prefix6List(org.batfish.representation.cisco.Prefix6List) PrefixListLine(org.batfish.representation.cisco.PrefixListLine) RouteMapMatchIpPrefixListLine(org.batfish.representation.cisco.RouteMapMatchIpPrefixListLine) RouteMapMatchIpv6PrefixListLine(org.batfish.representation.cisco.RouteMapMatchIpv6PrefixListLine) PrefixList(org.batfish.representation.cisco.PrefixList) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange) Prefix6(org.batfish.datamodel.Prefix6)

Aggregations

Prefix (org.batfish.datamodel.Prefix)133 Ip (org.batfish.datamodel.Ip)53 Configuration (org.batfish.datamodel.Configuration)33 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)29 Interface (org.batfish.datamodel.Interface)28 BatfishException (org.batfish.common.BatfishException)22 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)20 SubRange (org.batfish.datamodel.SubRange)19 HashMap (java.util.HashMap)18 StaticRoute (org.batfish.datamodel.StaticRoute)18 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)17 BgpProcess (org.batfish.datamodel.BgpProcess)17 SortedSet (java.util.SortedSet)16 TreeSet (java.util.TreeSet)16 AbstractRoute (org.batfish.datamodel.AbstractRoute)16 RoutingProtocol (org.batfish.datamodel.RoutingProtocol)16 TreeMap (java.util.TreeMap)14 HashSet (java.util.HashSet)13