Skip to content

Commit

Permalink
Cisco/IOS: implement set tag (#6468)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhalperi committed Dec 2, 2020
1 parent d0e94fb commit 2653a3e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@
import org.batfish.grammar.cisco.CiscoParser.Set_next_hop_peer_address_stanzaContext;
import org.batfish.grammar.cisco.CiscoParser.Set_next_hop_rm_stanzaContext;
import org.batfish.grammar.cisco.CiscoParser.Set_origin_rm_stanzaContext;
import org.batfish.grammar.cisco.CiscoParser.Set_tag_rm_stanzaContext;
import org.batfish.grammar.cisco.CiscoParser.Set_weight_rm_stanzaContext;
import org.batfish.grammar.cisco.CiscoParser.Shutdown_bgp_tailContext;
import org.batfish.grammar.cisco.CiscoParser.Sntp_serverContext;
Expand Down Expand Up @@ -1134,6 +1135,7 @@
import org.batfish.representation.cisco.RouteMapSetNextHopLine;
import org.batfish.representation.cisco.RouteMapSetNextHopPeerAddress;
import org.batfish.representation.cisco.RouteMapSetOriginTypeLine;
import org.batfish.representation.cisco.RouteMapSetTagLine;
import org.batfish.representation.cisco.RouteMapSetWeightLine;
import org.batfish.representation.cisco.SecurityZone;
import org.batfish.representation.cisco.SecurityZonePair;
Expand Down Expand Up @@ -9067,6 +9069,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.cisco;

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, CiscoConfiguration cc, Configuration c, Warnings w) {
statements.add(new SetTag(new LiteralLong(_tag)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.batfish.datamodel.matchers.AaaMatchers.hasAuthentication;
import static org.batfish.datamodel.matchers.AbstractRouteDecoratorMatchers.hasPrefix;
import static org.batfish.datamodel.matchers.AbstractRouteDecoratorMatchers.hasProtocol;
import static org.batfish.datamodel.matchers.AbstractRouteDecoratorMatchers.hasTag;
import static org.batfish.datamodel.matchers.AclLineMatchers.isExprAclLineThat;
import static org.batfish.datamodel.matchers.AndMatchExprMatchers.hasConjuncts;
import static org.batfish.datamodel.matchers.AndMatchExprMatchers.isAndMatchExprThat;
Expand Down Expand Up @@ -3566,6 +3567,30 @@ public void testIosRouteMapLocalPreference() throws IOException {
assertThat(transformedRoute.build().getLocalPreference(), equalTo((1L << 32) - 1));
}

@Test
public void testIosRouteMapSetTag() throws IOException {
String hostname = "ios-route-map-set-tag";
Batfish batfish = getBatfishForConfigurationNames(hostname);
RoutingPolicy setTagPolicy =
batfish
.loadConfigurations(batfish.getSnapshot())
.get(hostname)
.getRoutingPolicies()
.get("SET_TAG");
Bgpv4Route r =
Bgpv4Route.builder()
.setWeight(1)
.setNetwork(Prefix.ZERO)
.setOriginatorIp(Ip.ZERO)
.setOriginType(OriginType.IGP)
.setProtocol(RoutingProtocol.BGP)
.build();
Bgpv4Route.Builder transformedRoute = r.toBuilder();

assertThat(setTagPolicy.process(r, transformedRoute, Direction.IN), equalTo(true));
assertThat(transformedRoute.build(), hasTag(20));
}

@Test
public void testIosRouteMapSetWeight() throws IOException {
// Config contains a route-map SET_WEIGHT with one line, "set weight 20"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
!
hostname ios-route-map-set-tag
!
route-map SET_TAG permit 10
set tag 20
!

0 comments on commit 2653a3e

Please sign in to comment.