Search in sources :

Example 1 with RoutermappingKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.to.vpn.mapping.RoutermappingKey in project netvirt by opendaylight.

the class RouterPortsListener method add.

@Override
protected void add(final InstanceIdentifier<RouterPorts> identifier, final RouterPorts routerPorts) {
    LOG.trace("add : key:{}  value:{}", routerPorts.getKey(), routerPorts);
    Optional<RouterPorts> optRouterPorts = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
    if (optRouterPorts.isPresent()) {
        RouterPorts ports = optRouterPorts.get();
        String routerName = ports.getRouterId();
        MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier, new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId(routerName).setExternalNetworkId(routerPorts.getExternalNetworkId()).build());
    } else {
        String routerName = routerPorts.getRouterId();
        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier, new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId(routerName).setExternalNetworkId(routerPorts.getExternalNetworkId()).build());
    }
    // Check if the router is associated with any BGP VPN and update the association
    String routerName = routerPorts.getRouterId();
    Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerName);
    if (vpnName != null) {
        InstanceIdentifier<Routermapping> routerMappingId = NatUtil.getRouterVpnMappingId(routerName);
        Optional<Routermapping> optRouterMapping = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, routerMappingId);
        if (!optRouterMapping.isPresent()) {
            Long vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
            LOG.debug("add : Updating router {} to VPN {} association with Id {}", routerName, vpnName, vpnId);
            Routermapping routerMapping = new RoutermappingBuilder().setKey(new RoutermappingKey(routerName)).setRouterName(routerName).setVpnName(vpnName.getValue()).setVpnId(vpnId).build();
            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, routerMappingId, routerMapping);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RoutermappingBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.to.vpn.mapping.RoutermappingBuilder) RouterPortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Routermapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.to.vpn.mapping.Routermapping) RouterPortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsBuilder) RoutermappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.to.vpn.mapping.RoutermappingKey)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)1 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)1 RouterPortsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsBuilder)1 RouterPortsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey)1 Routermapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.to.vpn.mapping.Routermapping)1 RoutermappingBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.to.vpn.mapping.RoutermappingBuilder)1 RoutermappingKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.to.vpn.mapping.RoutermappingKey)1