use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class VxlanGreConntrackBasedSnatService method installSnatSpecificEntriesForNaptSwitch.
@Override
protected void installSnatSpecificEntriesForNaptSwitch(Routers routers, BigInteger dpnId, int addOrRemove) {
LOG.info("installSnatSpecificEntriesForNaptSwitch for router {}", routers.getRouterName());
String routerName = routers.getRouterName();
Long routerId = NatUtil.getVpnId(dataBroker, routerName);
int elanId = NatUtil.getElanInstanceByName(routers.getNetworkId().getValue(), dataBroker).getElanTag().intValue();
/* Install Outbound NAT entries */
installSnatMissEntryForPrimrySwch(dpnId, routerId, elanId, addOrRemove);
installTerminatingServiceTblEntryForVxlanGre(dpnId, routerName, routerId, elanId, addOrRemove);
// Long extNetVpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, routers.getNetworkId());
if (vpnUuid == null) {
LOG.error("installSnatSpecificEntriesForNaptSwitch: Unable to retrieve external vpn_id for " + "external network {} with routerId {}", routers.getNetworkId(), routerId);
return;
}
Long extNetVpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
/*//Long extNetVpnId = NatUtil.getAssociatedVPN(dataBroker, routers.getNetworkId(), LOG);
if (extNetVpnId == NatConstants.INVALID_ID && addOrRemove == NwConstants.ADD_FLOW) {
LOG.error("installSnatSpecificEntriesForNaptSwitch: Unable to retrieve external vpn_id for "
+ "external network {} with routerId {}", routers.getNetworkId(), routerId);
return;
}*/
LOG.info("installSnatSpecificEntriesForNaptSwitch: external network vpn_id {} for router {}", extNetVpnId, routers.getRouterName());
List<ExternalIps> externalIps = routers.getExternalIps();
createOutboundTblTrackEntryForVxlanGre(dpnId, routerId, extNetVpnId, addOrRemove);
createOutboundTblEntryForVxlanGre(dpnId, routerId, extNetVpnId, externalIps, elanId, addOrRemove);
installNaptPfibFlowForVxlanGre(routers, dpnId, extNetVpnId, addOrRemove);
installNaptPfibEntry(dpnId, routerId, addOrRemove);
// Install Inbound NAT entries
installInboundEntryForVxlanGre(dpnId, routerId, extNetVpnId, externalIps, elanId, addOrRemove);
if (externalIps.isEmpty()) {
LOG.error("installSnatSpecificEntriesForNaptSwitch: No externalIP present for router {}", routerName);
return;
}
// The logic now handle only one external IP per router, others if present will be ignored.
String externalIp = externalIps.get(0).getIpAddress();
externalIp = NatUtil.validateAndAddNetworkMask(externalIp);
WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
if (addOrRemove == NwConstants.ADD_FLOW) {
externalRouterListener.handleSnatReverseTraffic(dpnId, routers, routerId, routerName, externalIp, writeFlowInvTx);
} else {
externalRouterListener.clearFibTsAndReverseTraffic(dpnId, routerId, routers.getNetworkId(), Collections.singletonList(externalIp), null, routers.getExtGwMacAddress(), writeFlowInvTx);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class NeutronvpnNatManager method addExternalFixedIpToExternalIpsList.
private void addExternalFixedIpToExternalIpsList(List<ExternalIps> externalIps, ExternalFixedIps fixedIps) {
Uuid subnetId = fixedIps.getSubnetId();
String ip = fixedIps.getIpAddress().getIpv4Address().getValue();
ExternalIpsBuilder externalIpsBuilder = new ExternalIpsBuilder();
externalIpsBuilder.setKey(new ExternalIpsKey(ip, subnetId));
externalIpsBuilder.setIpAddress(ip);
externalIpsBuilder.setSubnetId(subnetId);
externalIps.add(externalIpsBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class NeutronvpnNatManager method addExternalRouter.
public void addExternalRouter(Router update) {
Uuid routerId = update.getUuid();
Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
Uuid gatewayPortId = update.getGatewayPortId();
// Create and add Routers object for this Router to the ExtRouters list
// Create a Routers object
InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
try {
Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
if (providerNwType == null) {
LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
return;
}
Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
LOG.trace("Creating/Updating a new Routers node: {}", routerId.getValue());
RoutersBuilder builder = null;
if (optionalRouters.isPresent()) {
builder = new RoutersBuilder(optionalRouters.get());
} else {
builder = new RoutersBuilder().setKey(new RoutersKey(routerId.getValue()));
}
builder.setRouterName(routerId.getValue());
builder.setNetworkId(extNetId);
builder.setEnableSnat(update.getExternalGatewayInfo().isEnableSnat());
ArrayList<ExternalIps> externalIps = new ArrayList<>();
for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
}
builder.setExternalIps(externalIps);
if (gatewayPortId != null) {
LOG.trace("Setting/Updating gateway Mac for router {}", routerId.getValue());
Port port = neutronvpnUtils.getNeutronPort(gatewayPortId);
if (port != null && port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_GATEWAY_INF)) {
builder.setExtGwMacAddress(port.getMacAddress().getValue());
}
}
List<Uuid> subList = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
builder.setSubnetIds(subList);
Routers routers = builder.build();
// Add Routers object to the ExtRouters list
LOG.trace("Creating extrouters {}", routers);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, builder.build());
LOG.trace("Wrote successfully Routers to CONFIG Datastore");
} catch (ReadFailedException | TransactionCommitFailedException ex) {
LOG.error("Creation of extrouters failed for router {} failed", routerId.getValue(), ex);
}
}
Aggregations