Search in sources :

Example 1 with HostInterface

use of org.batfish.representation.host.HostInterface in project batfish by batfish.

the class HostInterfaceTest method testShared.

@Test
public void testShared() throws IOException {
    Ip sharedIp = new Ip("1.0.0.1");
    InterfaceAddress sharedAddress = new InterfaceAddress(sharedIp, 24);
    Prefix nonShared1Prefix = Prefix.parse("2.0.0.2/24");
    Prefix nonShared2Prefix = Prefix.parse("3.0.0.2/24");
    String ifaceSharedText = "{\"name\":\"shared_interface\", \"prefix\":\"" + sharedAddress + "\", \"shared\":true}";
    String ifaceNonShared1Text = "{\"name\":\"non_shared1_interface\", \"prefix\":\"" + nonShared1Prefix + "\", \"shared\":false}";
    String ifaceNonShared2Text = "{\"name\":\"non_shared2_interface\", \"prefix\":\"" + nonShared2Prefix + "\"}";
    HostInterface sharedHostInterface = BatfishObjectMapper.mapper().readValue(ifaceSharedText, HostInterface.class);
    HostInterface nonShared1HostInterface = BatfishObjectMapper.mapper().readValue(ifaceNonShared1Text, HostInterface.class);
    HostInterface nonShared2HostInterface = BatfishObjectMapper.mapper().readValue(ifaceNonShared2Text, HostInterface.class);
    Interface sharedInterface = sharedHostInterface.toInterface(_c, _w);
    Interface nonShared1Interface = nonShared1HostInterface.toInterface(_c, _w);
    Interface nonShared2Interface = nonShared2HostInterface.toInterface(_c, _w);
    /*
     * Check that shared status from text is propagated into instances with correct defaults.
     */
    assertThat(sharedHostInterface, isShared());
    assertThat(nonShared1HostInterface, not(isShared()));
    assertThat(nonShared2HostInterface, not(isShared()));
    /*
     * The shared interface should contain source NAT info as indicated, while the other interfaces
     * should not contain any source NAT information.
     */
    assertThat(sharedInterface, hasSourceNats(hasItem(allOf(hasPoolIpFirst(sharedIp), hasPoolIpLast(sharedIp)))));
    assertThat(nonShared1Interface, hasSourceNats(empty()));
    assertThat(nonShared2Interface, hasSourceNats(empty()));
}
Also used : InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Ip(org.batfish.datamodel.Ip) HostInterface(org.batfish.representation.host.HostInterface) Prefix(org.batfish.datamodel.Prefix) HostInterface(org.batfish.representation.host.HostInterface) Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Example 2 with HostInterface

use of org.batfish.representation.host.HostInterface in project batfish by batfish.

the class HostInterfaceTest method testToInterface.

@Test
public void testToInterface() {
    String name = "eth0";
    HostInterface hi = new HostInterface(name);
    hi.setCanonicalName(name);
    Interface i = hi.toInterface(_c, new Warnings());
    /* Check defaults */
    assertThat(i, isProxyArp(equalTo(false)));
}
Also used : HostInterface(org.batfish.representation.host.HostInterface) Warnings(org.batfish.common.Warnings) HostInterface(org.batfish.representation.host.HostInterface) Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Aggregations

Interface (org.batfish.datamodel.Interface)2 HostInterface (org.batfish.representation.host.HostInterface)2 Test (org.junit.Test)2 Warnings (org.batfish.common.Warnings)1 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)1 Ip (org.batfish.datamodel.Ip)1 Prefix (org.batfish.datamodel.Prefix)1