Search in sources :

Example 6 with IpMappingKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey in project netvirt by opendaylight.

the class NaptManager method removeIpMappingForRouterID.

private void removeIpMappingForRouterID(long segmentId) {
    InstanceIdentifierBuilder<IpMapping> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(segmentId));
    InstanceIdentifier<IpMapping> id = idBuilder.build();
    // Get all externalIps and decrement their counters before deleting the ipmap
    String externalIp = null;
    Optional<IpMapping> ipMapping = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
    if (ipMapping.isPresent()) {
        List<IpMap> ipMaps = ipMapping.get().getIpMap();
        for (IpMap ipMap : ipMaps) {
            externalIp = ipMap.getExternalIp();
            LOG.debug("removeIpMappingForRouterID : externalIP is {}", externalIp);
            if (externalIp != null) {
                updateCounter(segmentId, externalIp, false);
            }
        }
        // remove from ipmap DS
        LOG.debug("removeIpMappingForRouterID : Removing Ipmap for router {} from datastore", segmentId);
        MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
    }
}
Also used : IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap) IpMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey) IpMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap)

Example 7 with IpMappingKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey in project netvirt by opendaylight.

the class NaptManagerTest method testRegisterMappingIpIP.

@Ignore
@Test
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void testRegisterMappingIpIP() {
    // TODO : This needs to be modified to make it work
    // TODO : Issue with Mockito.any() usage, so for now run registerMapping testcases as seperate Tests.
    // This needs to be fixed properly.
    ipmapId = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(5L)).child(IpMap.class, new IpMapKey("10.0.0.1")).build();
    ipmap = new IpMapBuilder().setKey(new IpMapKey("10.0.0.1")).setInternalIp("10.0.0.1").setExternalIp("192.17.13.1").build();
    try {
        PowerMockito.doNothing().when(MDSALUtil.class, "syncWrite", dataBroker, LogicalDatastoreType.OPERATIONAL, ipmapId, ipmap);
    } catch (Exception e) {
        // Test failed anyways
        assertEquals("true", "false");
    }
    IPAddress internal = new IPAddress("10.0.0.1", 0);
    IPAddress external = new IPAddress("192.17.13.1", 0);
    naptManager.registerMapping(5, internal, external);
    PowerMockito.verifyStatic();
}
Also used : IpMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapKey) IpMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey) IpMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping) IPAddress(org.opendaylight.netvirt.natservice.internal.IPAddress) IpMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapBuilder) Ignore(org.junit.Ignore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with IpMappingKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey in project netvirt by opendaylight.

the class NaptManagerTest method testRegisterMappingIpSubnet.

@Ignore
@Test
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void testRegisterMappingIpSubnet() {
    // TODO : This needs to be modified to make it work
    ipmapId = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(5L)).child(IpMap.class, new IpMapKey("10.0.0.1")).build();
    ipmap = new IpMapBuilder().setKey(new IpMapKey("10.0.0.1")).setInternalIp("10.0.0.1").setExternalIp("192.17.13.1/24").build();
    try {
        PowerMockito.doNothing().when(MDSALUtil.class, "syncWrite", dataBroker, LogicalDatastoreType.OPERATIONAL, ipmapId, ipmap);
    } catch (Exception e) {
        // Test failed anyways
        assertEquals("true", "false");
    }
    IPAddress internal = new IPAddress("10.0.0.1", 0);
    IPAddress external = new IPAddress("192.17.13.1", 24);
    naptManager.registerMapping(5, internal, external);
    PowerMockito.verifyStatic();
}
Also used : IpMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapKey) IpMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey) IpMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping) IPAddress(org.opendaylight.netvirt.natservice.internal.IPAddress) IpMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapBuilder) Ignore(org.junit.Ignore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with IpMappingKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey in project netvirt by opendaylight.

the class NaptManagerTest method testRegisterMappingSubnetIp.

@Ignore
@Test
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void testRegisterMappingSubnetIp() {
    // TODO : This needs to be modified to make it work
    ipmapId = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(6L)).child(IpMap.class, new IpMapKey("10.0.2.1/16")).build();
    ipmap = new IpMapBuilder().setKey(new IpMapKey("10.0.0.1")).setInternalIp("10.0.0.1").setExternalIp("192.19.15.3").build();
    try {
        PowerMockito.doNothing().when(MDSALUtil.class, "syncWrite", dataBroker, LogicalDatastoreType.OPERATIONAL, ipmapId, ipmap);
    } catch (Exception e) {
        // Test failed anyways
        assertEquals("true", "false");
    }
    IPAddress internal = new IPAddress("10.0.2.1", 16);
    IPAddress external = new IPAddress("192.19.15.3", 0);
    naptManager.registerMapping(6, internal, external);
    PowerMockito.verifyStatic();
}
Also used : IpMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapKey) IpMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey) IpMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping) IPAddress(org.opendaylight.netvirt.natservice.internal.IPAddress) IpMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapBuilder) Ignore(org.junit.Ignore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

IpMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping)9 IpMappingKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey)9 IpMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapKey)7 IntextIpMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap)5 IpMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap)5 Ignore (org.junit.Ignore)4 Test (org.junit.Test)4 IPAddress (org.opendaylight.netvirt.natservice.internal.IPAddress)4 IpMapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapBuilder)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 SubnetUtils (org.apache.commons.net.util.SubnetUtils)1 SubnetInfo (org.apache.commons.net.util.SubnetUtils.SubnetInfo)1