@Test public void testToRow() { IpsecSessionInfo.Builder ipsecPeeringInfoBuilder = IpsecSessionInfo.builder(); IpsecSessionInfo ipsecSessionInfo = ipsecPeeringInfoBuilder .setInitiatorHostname(INITIATOR_HOST_NAME) .setInitiatorInterface("Test_interface") .setInitiatorIp(Ip.parse("1.2.3.4")) .setInitiatorTunnelInterface("Tunnel_interface") .setResponderHostname(RESPONDER_HOST_NAME) .setResponderInterface("Test_interface") .setResponderIp(Ip.parse("2.3.4.5")) .setResponderTunnelInterface("Tunnel1_interface") .setIpsecSessionStatus(IPSEC_SESSION_ESTABLISHED) .build(); Row row = toRow(ipsecSessionInfo); assertThat( row, allOf( hasColumn(COL_INITIATOR, equalTo(new Node(INITIATOR_HOST_NAME)), Schema.NODE), hasColumn(COL_RESPONDER, equalTo(new Node(RESPONDER_HOST_NAME)), Schema.NODE), hasColumn( COL_INIT_INTERFACE, equalTo(NodeInterfacePair.of(INITIATOR_HOST_NAME, "Test_interface")), Schema.INTERFACE), hasColumn(COL_INIT_IP, equalTo(Ip.parse("1.2.3.4")), Schema.IP))); assertThat( row, allOf( hasColumn( COL_RESPONDER_INTERFACE, equalTo(NodeInterfacePair.of(RESPONDER_HOST_NAME, "Test_interface")), Schema.INTERFACE), hasColumn(COL_RESPONDER_IP, equalTo(Ip.parse("2.3.4.5")), Schema.IP))); assertThat( row, allOf( hasColumn( COL_TUNNEL_INTERFACES, equalTo("Tunnel_interface -> Tunnel1_interface"), Schema.STRING), hasColumn(COL_STATUS, equalTo("IPSEC_SESSION_ESTABLISHED"), Schema.STRING))); }
@VisibleForTesting static Row toRow(@Nonnull IpsecSessionInfo info) { RowBuilder row = Row.builder(); row.put(COL_INITIATOR, new Node(info.getInitiatorHostname())) .put( COL_INIT_INTERFACE, NodeInterfacePair.of( info.getInitiatorHostname(), String.format("%s", info.getInitiatorInterface()))) .put(COL_INIT_IP, info.getInitiatorIp()) .put( COL_RESPONDER, info.getResponderHostname() == null ? null : new Node(info.getResponderHostname())) .put( COL_RESPONDER_INTERFACE, info.getResponderHostname() != null && info.getResponderInterface() != null ? NodeInterfacePair.of( info.getResponderHostname(), String.format("%s", info.getResponderInterface())) : null) .put(COL_RESPONDER_IP, info.getResponderIp()) .put( COL_TUNNEL_INTERFACES, info.getInitiatorTunnelInterface() == null && info.getResponderTunnelInterface() == null ? NOT_APPLICABLE : String.format( "%s -> %s", firstNonNull(info.getInitiatorTunnelInterface(), "Missing Initiator"), firstNonNull(info.getResponderTunnelInterface(), "Missing Responder"))) .put(COL_STATUS, info.getIpsecSessionStatus()); return row.build(); }
IpsecSessionStatusAnswerer extends Answerer { @VisibleForTesting static Row toRow(@Nonnull IpsecSessionInfo info) { RowBuilder row = Row.builder(); row.put(COL_INITIATOR, new Node(info.getInitiatorHostname())) .put( COL_INIT_INTERFACE, NodeInterfacePair.of( info.getInitiatorHostname(), String.format("%s", info.getInitiatorInterface()))) .put(COL_INIT_IP, info.getInitiatorIp()) .put( COL_RESPONDER, info.getResponderHostname() == null ? null : new Node(info.getResponderHostname())) .put( COL_RESPONDER_INTERFACE, info.getResponderHostname() != null && info.getResponderInterface() != null ? NodeInterfacePair.of( info.getResponderHostname(), String.format("%s", info.getResponderInterface())) : null) .put(COL_RESPONDER_IP, info.getResponderIp()) .put( COL_TUNNEL_INTERFACES, info.getInitiatorTunnelInterface() == null && info.getResponderTunnelInterface() == null ? NOT_APPLICABLE : String.format( "%s -> %s", firstNonNull(info.getInitiatorTunnelInterface(), "Missing Initiator"), firstNonNull(info.getResponderTunnelInterface(), "Missing Responder"))) .put(COL_STATUS, info.getIpsecSessionStatus()); return row.build(); } }
IpsecSessionStatusAnswerer extends Answerer { @VisibleForTesting static Row toRow(@Nonnull IpsecSessionInfo info) { RowBuilder row = Row.builder(); row.put(COL_INITIATOR, new Node(info.getInitiatorHostname())) .put( COL_INIT_INTERFACE, NodeInterfacePair.of( info.getInitiatorHostname(), String.format("%s", info.getInitiatorInterface()))) .put(COL_INIT_IP, info.getInitiatorIp()) .put( COL_RESPONDER, info.getResponderHostname() == null ? null : new Node(info.getResponderHostname())) .put( COL_RESPONDER_INTERFACE, info.getResponderHostname() != null && info.getResponderInterface() != null ? NodeInterfacePair.of( info.getResponderHostname(), String.format("%s", info.getResponderInterface())) : null) .put(COL_RESPONDER_IP, info.getResponderIp()) .put( COL_TUNNEL_INTERFACES, info.getInitiatorTunnelInterface() == null && info.getResponderTunnelInterface() == null ? NOT_APPLICABLE : String.format( "%s -> %s", firstNonNull(info.getInitiatorTunnelInterface(), "Missing Initiator"), firstNonNull(info.getResponderTunnelInterface(), "Missing Responder"))) .put(COL_STATUS, info.getIpsecSessionStatus()); return row.build(); } IpsecSessionStatusAnswerer(Question question, IBatfish batfish); }
IpsecSessionStatusAnswerer extends Answerer { @VisibleForTesting static Row toRow(@Nonnull IpsecSessionInfo info) { RowBuilder row = Row.builder(); row.put(COL_INITIATOR, new Node(info.getInitiatorHostname())) .put( COL_INIT_INTERFACE, NodeInterfacePair.of( info.getInitiatorHostname(), String.format("%s", info.getInitiatorInterface()))) .put(COL_INIT_IP, info.getInitiatorIp()) .put( COL_RESPONDER, info.getResponderHostname() == null ? null : new Node(info.getResponderHostname())) .put( COL_RESPONDER_INTERFACE, info.getResponderHostname() != null && info.getResponderInterface() != null ? NodeInterfacePair.of( info.getResponderHostname(), String.format("%s", info.getResponderInterface())) : null) .put(COL_RESPONDER_IP, info.getResponderIp()) .put( COL_TUNNEL_INTERFACES, info.getInitiatorTunnelInterface() == null && info.getResponderTunnelInterface() == null ? NOT_APPLICABLE : String.format( "%s -> %s", firstNonNull(info.getInitiatorTunnelInterface(), "Missing Initiator"), firstNonNull(info.getResponderTunnelInterface(), "Missing Responder"))) .put(COL_STATUS, info.getIpsecSessionStatus()); return row.build(); } IpsecSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
IpsecSessionStatusAnswerer extends Answerer { @VisibleForTesting static Row toRow(@Nonnull IpsecSessionInfo info) { RowBuilder row = Row.builder(); row.put(COL_INITIATOR, new Node(info.getInitiatorHostname())) .put( COL_INIT_INTERFACE, NodeInterfacePair.of( info.getInitiatorHostname(), String.format("%s", info.getInitiatorInterface()))) .put(COL_INIT_IP, info.getInitiatorIp()) .put( COL_RESPONDER, info.getResponderHostname() == null ? null : new Node(info.getResponderHostname())) .put( COL_RESPONDER_INTERFACE, info.getResponderHostname() != null && info.getResponderInterface() != null ? NodeInterfacePair.of( info.getResponderHostname(), String.format("%s", info.getResponderInterface())) : null) .put(COL_RESPONDER_IP, info.getResponderIp()) .put( COL_TUNNEL_INTERFACES, info.getInitiatorTunnelInterface() == null && info.getResponderTunnelInterface() == null ? NOT_APPLICABLE : String.format( "%s -> %s", firstNonNull(info.getInitiatorTunnelInterface(), "Missing Initiator"), firstNonNull(info.getResponderTunnelInterface(), "Missing Responder"))) .put(COL_STATUS, info.getIpsecSessionStatus()); return row.build(); } IpsecSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }