Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arista: add set tag and a test of route-map with continue #6466

Merged
merged 2 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@
import org.batfish.grammar.arista.AristaParser.Set_next_hop_peer_address_stanzaContext;
import org.batfish.grammar.arista.AristaParser.Set_next_hop_rm_stanzaContext;
import org.batfish.grammar.arista.AristaParser.Set_origin_rm_stanzaContext;
import org.batfish.grammar.arista.AristaParser.Set_tag_rm_stanzaContext;
import org.batfish.grammar.arista.AristaParser.Set_weight_rm_stanzaContext;
import org.batfish.grammar.arista.AristaParser.Sntp_serverContext;
import org.batfish.grammar.arista.AristaParser.Spanning_tree_portfastContext;
Expand Down Expand Up @@ -986,6 +987,7 @@
import org.batfish.representation.arista.RouteMapSetNextHopLine;
import org.batfish.representation.arista.RouteMapSetNextHopPeerAddress;
import org.batfish.representation.arista.RouteMapSetOriginTypeLine;
import org.batfish.representation.arista.RouteMapSetTagLine;
import org.batfish.representation.arista.RouteMapSetWeightLine;
import org.batfish.representation.arista.SimpleExtendedAccessListServiceSpecifier;
import org.batfish.representation.arista.StandardAccessList;
Expand Down Expand Up @@ -7474,6 +7476,12 @@ public void exitSet_origin_rm_stanza(Set_origin_rm_stanzaContext ctx) {
_currentRouteMapClause.addSetLine(line);
}

@Override
public void exitSet_tag_rm_stanza(Set_tag_rm_stanzaContext ctx) {
long tag = toLong(ctx.tag);
_currentRouteMapClause.addSetLine(new RouteMapSetTagLine(tag));
}

@Override
public void exitSet_weight_rm_stanza(Set_weight_rm_stanzaContext ctx) {
RouteMapSetWeightLine line = new RouteMapSetWeightLine(toInteger(ctx.DEC()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.batfish.representation.arista;

import java.util.List;
import org.batfish.common.Warnings;
import org.batfish.datamodel.Configuration;
import org.batfish.datamodel.routing_policy.expr.LiteralLong;
import org.batfish.datamodel.routing_policy.statement.SetTag;
import org.batfish.datamodel.routing_policy.statement.Statement;

/** Represents a {@code `set tag n`} line in a route-map. */
public class RouteMapSetTagLine extends RouteMapSetLine {

private final long _tag;

public RouteMapSetTagLine(long tag) {
_tag = tag;
}

@Override
public void applyTo(
List<Statement> statements, AristaConfiguration cc, Configuration c, Warnings w) {
statements.add(new SetTag(new LiteralLong(_tag)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
import org.batfish.datamodel.matchers.MlagMatchers;
import org.batfish.datamodel.routing_policy.Environment.Direction;
import org.batfish.datamodel.routing_policy.RoutingPolicy;
import org.batfish.datamodel.routing_policy.communities.CommunitySet;
import org.batfish.datamodel.vxlan.Layer2Vni;
import org.batfish.datamodel.vxlan.Layer3Vni;
import org.batfish.main.Batfish;
Expand Down Expand Up @@ -2395,6 +2396,115 @@ public void testRouteMapParsing() {
parseConfig("route_map");
}

private @Nonnull Bgpv4Route processRouteIn(RoutingPolicy routingPolicy, Bgpv4Route route) {
Bgpv4Route.Builder builder = route.toBuilder();
assertTrue(routingPolicy.process(route, builder, Direction.IN));
return builder.build();
}

private void assertRoutingPolicyDeniesRoute(RoutingPolicy routingPolicy, AbstractRoute route) {
assertFalse(
routingPolicy.process(
route, Bgpv4Route.builder().setNetwork(route.getNetwork()), Direction.OUT));
}

@Test
public void testRouteMapExhaustive() {
Configuration c = parseConfig("arista_route_map_exhaustive");
assertThat(c.getRoutingPolicies(), hasKey("RM"));
RoutingPolicy rm = c.getRoutingPolicies().get("RM");
Bgpv4Route base =
Bgpv4Route.builder()
.setTag(0L)
.setSrcProtocol(RoutingProtocol.BGP)
.setMetric(0L)
.setAsPath(AsPath.ofSingletonAsSets(2L))
.setOriginatorIp(Ip.ZERO)
.setOriginType(OriginType.INCOMPLETE)
.setProtocol(RoutingProtocol.BGP)
.setNextHopIp(Ip.parse("192.0.2.254"))
.setNetwork(Prefix.ZERO)
.build();
// There are 8 paths through the route-map, let's test them all.
// 10 deny tag 1, continue OR fall-through
// 20 permit community 0:2, continue OR fall-through
// 30 deny 1.2.3.4/32, terminate OR 40 terminate
{
// false false false -> 40 only
Bgpv4Route after = processRouteIn(rm, base);
assertThat(after.getTag(), not(equalTo(10L)));
assertThat(after.getCommunities(), not(equalTo(CommunitySet.of(StandardCommunity.of(20)))));
assertThat(after.getMetric(), not(equalTo(30L)));
assertThat(after.getLocalPreference(), equalTo(40L));
}
{
// false false true -> 30 only
assertRoutingPolicyDeniesRoute(
rm, base.toBuilder().setNetwork(Prefix.parse("1.2.3.4/32")).build());
}
{
// false true false -> 20, 40
Bgpv4Route after =
processRouteIn(
rm,
base.toBuilder().setCommunities(CommunitySet.of(StandardCommunity.of(2))).build());
assertThat(after.getTag(), not(equalTo(10L)));
assertThat(after.getCommunities(), equalTo(CommunitySet.of(StandardCommunity.of(20))));
assertThat(after.getMetric(), not(equalTo(30L)));
assertThat(after.getLocalPreference(), equalTo(40L));
}
{
// false true true -> 20, 30
assertRoutingPolicyDeniesRoute(
rm,
base.toBuilder()
.setCommunities(CommunitySet.of(StandardCommunity.of(2)))
.setNetwork(Prefix.parse("1.2.3.4/32"))
.build());
}
{
assert true;
// TODO(PR#6465) true false false -> 10, 40
// Bgpv4Route after = processRouteIn(rm, base.toBuilder().setTag(1L).build());
// assertThat(after.getTag(), equalTo(10L));
// assertThat(after.getCommunities(),
// not(equalTo(CommunitySet.of(StandardCommunity.of(20)))));
// assertThat(after.getMetric(), not(equalTo(30L)));
// assertThat(after.getLocalPreference(), equalTo(40L));
}
{
// true false true -> 10, 30
assertRoutingPolicyDeniesRoute(
rm, base.toBuilder().setTag(1L).setNetwork(Prefix.parse("1.2.3.4/32")).build());
}
{
assert true;
// // TODO(PR#6465) true true false -> 10, 20, 40
// Bgpv4Route after =
// processRouteIn(
// rm,
// base.toBuilder()
// .setTag(1L)
// .setCommunities(CommunitySet.of(StandardCommunity.of(2)))
// .build());
// assertThat(after.getTag(), equalTo(10L));
// assertThat(after.getCommunities(),
// equalTo(CommunitySet.of(StandardCommunity.of(20))));
// assertThat(after.getMetric(), not(equalTo(30L)));
// assertThat(after.getLocalPreference(), equalTo(40L));
}
{
// true true true -> 10, 20, 30
assertRoutingPolicyDeniesRoute(
rm,
base.toBuilder()
.setTag(1L)
.setCommunities(CommunitySet.of(StandardCommunity.of(2)))
.setNetwork(Prefix.parse("1.2.3.4/32"))
.build());
}
}

@Test
public void testSnmpExtraction() {
Configuration config = parseConfig("arista_snmp");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
!RANCID-CONTENT-TYPE: arista
!
hostname arista_route_map_exhaustive
!
ip community-list cl20 permit 0:2
!
ip prefix-list pl30 permit 1.2.3.4/32
!
route-map RM deny 10
match tag 1
set tag 10
continue 20
route-map RM permit 20
match community cl20
set community 0:20
continue 30
route-map RM deny 30
match ip address pl30
set metric 30
route-map RM permit 40
set local-preference 40
description Done
!