Search in sources :

Example 66 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class ExternalNetworkManagerTest method testAllocateReleaseIp.

@Test
public void testAllocateReleaseIp() {
    IpPrefix cidr = IpPrefix.valueOf("192.168.200.0/24");
    target.registerNetwork(cidr);
    IpAddress ip = target.allocateIp(cidr);
    assertEquals(251, target.getAllIps(cidr).size());
    target.releaseIp(cidr, ip);
    assertEquals(252, target.getAllIps(cidr).size());
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress) Test(org.junit.Test)

Example 67 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class ExternalNetworkManagerTest method testObtainGatewayIp.

/**
 * Checks if creating and removing a config work well with proper events.
 */
@Test
public void testObtainGatewayIp() {
    IpPrefix cidr = IpPrefix.valueOf("192.168.200.0/24");
    target.registerNetwork(cidr);
    assertEquals(target.getGatewayIp(cidr), IpAddress.valueOf("192.168.200.1"));
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Test(org.junit.Test)

Example 68 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class KubevirtSecurityGroupRuleJsonMatcher method matchesSafely.

@Override
protected boolean matchesSafely(JsonNode jsonNode, Description description) {
    // check rule ID
    String jsonId = jsonNode.get(ID).asText();
    String id = rule.id();
    if (!jsonId.equals(id)) {
        description.appendText("Rule ID was " + jsonId);
        return false;
    }
    // check security group ID
    String jsonSecurityGroupId = jsonNode.get(SECURITY_GROUP_ID).asText();
    String securityGroupId = rule.securityGroupId();
    if (!jsonSecurityGroupId.equals(securityGroupId)) {
        description.appendText("Security group ID was " + jsonSecurityGroupId);
        return false;
    }
    // check direction
    String jsonDirection = jsonNode.get(DIRECTION).asText();
    String direction = rule.direction();
    if (!jsonDirection.equals(direction)) {
        description.appendText("Direction was " + jsonDirection);
        return false;
    }
    // check ether type
    JsonNode jsonEtherType = jsonNode.get(ETHER_TYPE);
    if (jsonEtherType != null) {
        String etherType = rule.etherType();
        if (!jsonEtherType.asText().equals(etherType)) {
            description.appendText("EtherType was " + jsonEtherType);
            return false;
        }
    }
    // check port range max
    JsonNode jsonPortRangeMax = jsonNode.get(PORT_RANGE_MAX);
    if (jsonPortRangeMax != null) {
        int portRangeMax = rule.portRangeMax();
        if (portRangeMax != jsonPortRangeMax.asInt()) {
            description.appendText("PortRangeMax was " + jsonPortRangeMax);
            return false;
        }
    }
    // check port range min
    JsonNode jsonPortRangeMin = jsonNode.get(PORT_RANGE_MIN);
    if (jsonPortRangeMin != null) {
        int portRangeMin = rule.portRangeMin();
        if (portRangeMin != jsonPortRangeMin.asInt()) {
            description.appendText("PortRangeMin was " + jsonPortRangeMin);
            return false;
        }
    }
    // check protocol
    JsonNode jsonProtocol = jsonNode.get(PROTOCOL);
    if (jsonProtocol != null) {
        String protocol = rule.protocol();
        if (!jsonProtocol.asText().equals(protocol)) {
            description.appendText("Protocol was " + jsonProtocol);
            return false;
        }
    }
    // check remote IP prefix
    JsonNode jsonRemoteIpPrefix = jsonNode.get(REMOTE_IP_PREFIX);
    if (jsonRemoteIpPrefix != null) {
        IpPrefix remoteIpPrefix = rule.remoteIpPrefix();
        if (!jsonRemoteIpPrefix.asText().equals(remoteIpPrefix.toString())) {
            description.appendText("Remote IP prefix was " + jsonRemoteIpPrefix);
            return false;
        }
    }
    // check remote group ID
    JsonNode jsonRemoteGroupId = jsonNode.get(REMOTE_GROUP_ID);
    if (jsonRemoteGroupId != null) {
        String remoteGroupId = rule.remoteGroupId();
        if (!jsonRemoteGroupId.asText().equals(remoteGroupId)) {
            description.appendText("Remote group ID was " + jsonRemoteGroupId);
            return false;
        }
    }
    return true;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 69 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class DefaultMappingTreatmentTest method testIllegalMulticastTypeConstruction.

/**
 * Tests illegal multicast type instruction construction.
 */
@Test(expected = IllegalArgumentException.class)
public void testIllegalMulticastTypeConstruction() {
    IpPrefix ip = IpPrefix.valueOf(IP_ADDRESS_1);
    MappingAddress address = MappingAddresses.ipv4MappingAddress(ip);
    DefaultMappingTreatment.builder().withAddress(address).setMulticastPriority(10).setMulticastWeight(10).setMulticastPriority(20).build();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) Test(org.junit.Test)

Example 70 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class DefaultMappingTreatmentTest method testEquals.

/**
 * Tests equals() method.
 */
@Test
public void testEquals() {
    IpPrefix ip1 = IpPrefix.valueOf(IP_ADDRESS_1);
    MappingAddress address1 = MappingAddresses.ipv4MappingAddress(ip1);
    MappingTreatment treatment1 = DefaultMappingTreatment.builder().withAddress(address1).setUnicastPriority(10).setUnicastWeight(10).build();
    MappingTreatment sameAsTreatment1 = DefaultMappingTreatment.builder().withAddress(address1).setUnicastPriority(10).setUnicastWeight(10).build();
    IpPrefix ip2 = IpPrefix.valueOf(IP_ADDRESS_2);
    MappingAddress address2 = MappingAddresses.ipv4MappingAddress(ip2);
    MappingTreatment treatment2 = DefaultMappingTreatment.builder().withAddress(address2).setMulticastPriority(20).setMulticastWeight(20).build();
    new EqualsTester().addEqualityGroup(treatment1, sameAsTreatment1).addEqualityGroup(treatment2).testEquals();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Aggregations

IpPrefix (org.onlab.packet.IpPrefix)107 Test (org.junit.Test)37 IpAddress (org.onlab.packet.IpAddress)29 LinkedList (java.util.LinkedList)24 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)22 BgpHeader (org.onosproject.bgpio.types.BgpHeader)22 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)21 AsPath (org.onosproject.bgpio.types.AsPath)21 BgpValueType (org.onosproject.bgpio.types.BgpValueType)21 Origin (org.onosproject.bgpio.types.Origin)21 OriginType (org.onosproject.bgpio.types.Origin.OriginType)21 Med (org.onosproject.bgpio.types.Med)20 TrafficSelector (org.onosproject.net.flow.TrafficSelector)20 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)19 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)18 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)16 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)14 MacAddress (org.onlab.packet.MacAddress)12