use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers in project netvirt by opendaylight.
the class UpgradeStateListener method update.
@Override
public void update(@Nonnull Config original, Config updated) {
if (natMode != NatserviceConfig.NatMode.Conntrack) {
return;
}
LOG.info("UpgradeStateListener update from {} to {}", original, updated);
if (!(original.isUpgradeInProgress() && !updated.isUpgradeInProgress())) {
return;
}
SingleTransactionDataBroker reader = new SingleTransactionDataBroker(dataBroker);
ExtRouters routers;
try {
routers = reader.syncRead(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(ExtRouters.class));
} catch (ReadFailedException e) {
LOG.error("Error reading external routers", e);
return;
}
for (Routers router : routers.getRouters()) {
List<ExternalIps> externalIps = router.getExternalIps();
if (router.isEnableSnat() && externalIps != null && !externalIps.isEmpty()) {
centralizedSwitchScheduler.scheduleCentralizedSwitch(router);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers in project netvirt by opendaylight.
the class VxlanGreConntrackBasedSnatService method handleSnatAllSwitch.
@Override
public boolean handleSnatAllSwitch(Routers routers, BigInteger primarySwitchId, int addOrRemove) {
ProviderTypes extNwProviderType = NatUtil.getProviderTypefromNetworkId(dataBroker, routers.getNetworkId());
LOG.debug("VxlanGreConntrackBasedSnatService: handleSnatAllSwitch ProviderTypes {}", extNwProviderType);
if (extNwProviderType == ProviderTypes.FLAT || extNwProviderType == ProviderTypes.VLAN) {
return false;
}
return super.handleSnatAllSwitch(routers, primarySwitchId, addOrRemove);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers 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.neutron.l3.rev150712.routers.attributes.Routers in project netvirt by opendaylight.
the class NeutronvpnNatManager method handleExternalNetworkForRouter.
public void handleExternalNetworkForRouter(Router original, Router update) {
Uuid routerId = update.getUuid();
Uuid origExtNetId = null;
Uuid updExtNetId = null;
List<ExternalFixedIps> origExtFixedIps;
LOG.trace("handleExternalNetwork for router {}", routerId);
int extNetChanged = externalNetworkChanged(original, update);
if (extNetChanged != EXTERNAL_NO_CHANGE) {
if (extNetChanged == EXTERNAL_ADDED) {
updExtNetId = update.getExternalGatewayInfo().getExternalNetworkId();
LOG.trace("External Network {} addition detected for router {}", updExtNetId.getValue(), routerId.getValue());
addExternalNetworkToRouter(update);
return;
}
if (extNetChanged == EXTERNAL_REMOVED) {
origExtNetId = original.getExternalGatewayInfo().getExternalNetworkId();
origExtFixedIps = original.getExternalGatewayInfo().getExternalFixedIps();
LOG.trace("External Network removal detected for router {}", routerId.getValue());
removeExternalNetworkFromRouter(origExtNetId, update, origExtFixedIps);
// gateway mac unset handled as part of gateway clear deleting top-level routers node
return;
}
origExtNetId = original.getExternalGatewayInfo().getExternalNetworkId();
origExtFixedIps = original.getExternalGatewayInfo().getExternalFixedIps();
updExtNetId = update.getExternalGatewayInfo().getExternalNetworkId();
LOG.trace("External Network changed from {} to {} for router {}", origExtNetId.getValue(), updExtNetId.getValue(), routerId.getValue());
removeExternalNetworkFromRouter(origExtNetId, update, origExtFixedIps);
addExternalNetworkToRouter(update);
return;
}
if (snatSettingChanged(original, update)) {
LOG.trace("SNAT settings on gateway changed for router {}", routerId.getValue());
handleSnatSettingChangeForRouter(update);
}
if (externalFixedIpsChanged(original, update)) {
LOG.trace("External Fixed IPs changed for router {}", routerId.getValue());
handleExternalFixedIpsForRouter(update);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers 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