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

BgpPeerConfigurationQuestion: add description column #6403

Merged
merged 3 commits into from
Nov 7, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
public class BgpPeerPropertySpecifier extends PropertySpecifier {

public static final String CONFEDERATION = "Confederation";
public static final String DESCRIPTION = "Description";
public static final String LOCAL_AS = "Local_AS";
public static final String LOCAL_IP = "Local_IP";
public static final String IS_PASSIVE = "Is_Passive";
Expand Down Expand Up @@ -128,6 +129,10 @@ public class BgpPeerPropertySpecifier extends PropertySpecifier {
CONFEDERATION,
new PropertyDescriptor<>(
BgpPeerConfig::getConfederationAsn, Schema.LONG, "Confederation AS number"))
.put(
DESCRIPTION,
new PropertyDescriptor<>(
BgpPeerConfig::getDescription, Schema.STRING, "Configured peer description"))
.build();

/** Returns the property descriptor for {@code property} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.CLUSTER_ID;
import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.CONFEDERATION;
import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.DESCRIPTION;
import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.EXPORT_POLICY;
import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.IMPORT_POLICY;
import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.IS_PASSIVE;
Expand All @@ -19,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -67,6 +69,7 @@ public class BgpPeerConfigurationAnswerer extends Answerer {
CONFEDERATION,
REMOTE_AS,
COL_REMOTE_IP,
DESCRIPTION,
ROUTE_REFLECTOR_CLIENT,
CLUSTER_ID,
PEER_GROUP,
Expand Down Expand Up @@ -106,7 +109,6 @@ public static List<ColumnMetadata> createColumnMetadata(
columnMetadatas.put(
COL_REMOTE_IP,
new ColumnMetadata(COL_REMOTE_IP, Schema.SELF_DESCRIBING, "Remote IP", true, false));

// Check for unknown columns (present in BgpPeerPropertySpecifier but not COLUMN_ORDER)
List<ColumnMetadata> unknownColumns =
columnMetadatas.entrySet().stream()
Expand All @@ -116,9 +118,7 @@ public static List<ColumnMetadata> createColumnMetadata(

// List the metadatas in order, with any unknown columns tacked onto the end of the table
return Stream.concat(
COLUMN_ORDER.stream()
.filter(prop -> columnMetadatas.containsKey(prop))
.map(prop -> columnMetadatas.get(prop)),
COLUMN_ORDER.stream().map(columnMetadatas::get).filter(Objects::nonNull),
unknownColumns.stream())
.collect(ImmutableList.toImmutableList());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@batfish//skylark:junit.bzl", "junit_tests")

package(
default_testonly = True,
default_visibility = ["//visibility:private"],
)

junit_tests(
name = "tests",
srcs = glob([
"**/*Test.java",
]),
runtime_deps = [
"@maven//:org_apache_logging_log4j_log4j_core",
"@maven//:org_apache_logging_log4j_log4j_slf4j_impl",
],
deps = [
"//projects/batfish-common-protocol:common",
"//projects/batfish-common-protocol:common_testlib",
"//projects/question",
"@maven//:com_google_guava_guava",
"@maven//:junit_junit",
"@maven//:org_hamcrest_hamcrest",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.CLUSTER_ID;
import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.CONFEDERATION;
import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.DESCRIPTION;
import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.EXPORT_POLICY;
import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.IMPORT_POLICY;
import static org.batfish.datamodel.questions.BgpPeerPropertySpecifier.IS_PASSIVE;
Expand Down Expand Up @@ -64,6 +65,7 @@ public BgpPeerConfigurationAnswererTest() {
.setLocalIp(Ip.parse("1.1.1.1"))
.setPeerAddress(Ip.parse("2.2.2.2"))
.setConfederation(1L)
.setDescription("desc1")
.setGroup("g1")
.setIpv4UnicastAddressFamily(
Ipv4UnicastAddressFamily.builder()
Expand All @@ -81,6 +83,7 @@ public BgpPeerConfigurationAnswererTest() {
.setLocalIp(Ip.parse("1.1.1.2"))
.setPeerPrefix(Prefix.create(Ip.parse("3.3.3.0"), 24))
.setConfederation(2L)
.setDescription("desc2")
.setClusterId(Ip.parse("5.5.5.5").asLong())
.setGroup("g2")
.setIpv4UnicastAddressFamily(
Expand All @@ -99,6 +102,7 @@ public BgpPeerConfigurationAnswererTest() {
.setLocalIp(Ip.parse("169.254.0.1"))
.setPeerInterface("iface")
.setConfederation(3L)
.setDescription("desc3")
.setClusterId(Ip.parse("6.6.6.6").asLong())
.setGroup("g3")
.setIpv4UnicastAddressFamily(
Expand Down Expand Up @@ -148,6 +152,7 @@ public void testAnswer() {
.put(getColumnName(REMOTE_AS), LongSpace.of(200L).toString())
.put(getColumnName(LOCAL_IP), Ip.parse("1.1.1.1"))
.put(getColumnName(CONFEDERATION), 1L)
.put(getColumnName(DESCRIPTION), "desc1")
.put(getColumnName(IS_PASSIVE), false)
.put(getColumnName(ROUTE_REFLECTOR_CLIENT), false)
.put(getColumnName(CLUSTER_ID), null)
Expand All @@ -168,6 +173,7 @@ public void testAnswer() {
.put(getColumnName(REMOTE_AS), LongSpace.of(300L).toString())
.put(getColumnName(LOCAL_IP), Ip.parse("1.1.1.2"))
.put(getColumnName(CONFEDERATION), 2L)
.put(getColumnName(DESCRIPTION), "desc2")
.put(getColumnName(IS_PASSIVE), true)
.put(getColumnName(ROUTE_REFLECTOR_CLIENT), true)
.put(getColumnName(CLUSTER_ID), Ip.parse("5.5.5.5"))
Expand All @@ -186,6 +192,7 @@ public void testAnswer() {
.put(getColumnName(REMOTE_AS), LongSpace.of(400L).toString())
.put(getColumnName(LOCAL_IP), null)
.put(getColumnName(CONFEDERATION), 3L)
.put(getColumnName(DESCRIPTION), "desc3")
.put(getColumnName(IS_PASSIVE), false)
.put(getColumnName(ROUTE_REFLECTOR_CLIENT), true)
.put(getColumnName(CLUSTER_ID), Ip.parse("6.6.6.6"))
Expand Down