use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class DhcpInterfaceEventListener method update.
@Override
public void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
// We're only interested in Vlan and Tunnel ports
if (!L2vlan.class.equals(update.getType()) && !Tunnel.class.equals(update.getType())) {
return;
}
if ((original.getOperStatus().getIntValue() ^ update.getOperStatus().getIntValue()) == 0) {
LOG.trace("Interface operstatus is same orig {} updated {}", original, update);
return;
}
List<String> ofportIds = update.getLowerLayerIf();
if (ofportIds == null || ofportIds.isEmpty()) {
return;
}
NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
Uint64 dpnId = DhcpServiceUtils.getDpnIdFromNodeConnectorId(nodeConnectorId);
String interfaceName = update.getName();
OperStatus updatedOperStatus = update.getOperStatus();
if (original.getOperStatus().equals(OperStatus.Up) && updatedOperStatus.equals(OperStatus.Unknown)) {
updatedOperStatus = OperStatus.Down;
}
DhcpInterfaceUpdateJob job = new DhcpInterfaceUpdateJob(dhcpExternalTunnelManager, dataBroker, interfaceName, dpnId, updatedOperStatus, interfaceManager);
jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), job, DhcpMConstants.RETRY_COUNT);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class DhcpSubnetListener method installDirectPortEntries.
private void installDirectPortEntries(List<Uuid> directPortList) {
LOG.trace("DhcpSubnetListener installDirectPortEntries : directPortList: {}", directPortList);
for (Uuid portIntf : directPortList) {
Port port = dhcpManager.getNeutronPort(portIntf.getValue());
String vmMacAddress = port.getMacAddress().getValue();
Uuid networkId = port.getNetworkId();
// install the entries on designated dpnId
List<Uint64> listOfDpns = DhcpServiceUtils.getListOfDpns(dataBroker);
IpAddress tunnelIp = dhcpExternalTunnelManager.getTunnelIpBasedOnElan(networkId.getValue(), vmMacAddress);
if (null == tunnelIp) {
LOG.warn("DhcpSubnetListener installDirectPortEntries tunnelIP is null for port {}", portIntf);
continue;
}
Uint64 designatedDpnId = dhcpExternalTunnelManager.readDesignatedSwitchesForExternalTunnel(tunnelIp, networkId.getValue());
LOG.trace("CR-DHCP DhcpSubnetListener update Install DIRECT vmMacAddress: {} tunnelIp: {} " + "designatedDpnId : {} ListOf Dpn: {}", vmMacAddress, tunnelIp, designatedDpnId, listOfDpns);
dhcpExternalTunnelManager.installDhcpFlowsForVms(tunnelIp, networkId.getValue(), listOfDpns, designatedDpnId, vmMacAddress);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class DhcpSubnetListener method update.
@Override
public void update(InstanceIdentifier<Subnet> identifier, Subnet original, Subnet update) {
if (!config.isControllerDhcpEnabled()) {
return;
}
LOG.trace("DhcpSubnetListener Update : Original dhcpstatus: {}, Updated dhcpstatus {}", original.isEnableDhcp(), update.isEnableDhcp());
if (!Objects.equals(original.isEnableDhcp(), update.isEnableDhcp())) {
// write api to get port list
SubnetmapBuilder subnetmapBuilder = getSubnetMapBuilder(dataBroker, update.getUuid());
List<Uuid> portList = subnetmapBuilder.getPortList();
List<Uuid> directPortList = subnetmapBuilder.getDirectPortList();
if (update.isEnableDhcp()) {
if (null != portList) {
// Install Entries for neutron ports
installNeutronPortEntries(portList);
}
if (null != directPortList) {
// install Entries for direct ports
installDirectPortEntries(directPortList);
}
} else {
if (null != portList) {
// UnInstall Entries for neutron ports
uninstallNeutronPortEntries(portList);
}
if (null != directPortList) {
// Uninstall Entries for direct ports
uninstallDirectPortEntries(directPortList);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class NatUtil method handleSNATForDPN.
@SuppressWarnings("checkstyle:IllegalCatch")
public static void handleSNATForDPN(DataBroker dataBroker, IMdsalApiManager mdsalManager, IdManagerService idManager, NaptSwitchHA naptSwitchHA, Uint64 dpnId, Routers extRouters, Uint32 routerId, Uint32 routerVpnId, TypedReadWriteTransaction<Configuration> confTx, ProviderTypes extNwProvType, UpgradeState upgradeState) {
// Check if primary and secondary switch are selected, If not select the role
// Install select group to NAPT switch
// Install default miss entry to NAPT switch
Uint64 naptSwitch;
String routerName = extRouters.getRouterName();
Boolean upgradeInProgress = false;
if (upgradeState != null) {
upgradeInProgress = upgradeState.isUpgradeInProgress();
}
Uint64 naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
if (naptId == null || naptId.equals(Uint64.ZERO) || !NatUtil.getSwitchStatus(dataBroker, naptId) && upgradeInProgress == false) {
LOG.debug("handleSNATForDPN : NaptSwitch is down or not selected for router {},naptId {}", routerName, naptId);
naptSwitch = dpnId;
boolean naptstatus = naptSwitchHA.updateNaptSwitch(routerName, naptSwitch);
if (!naptstatus) {
LOG.error("handleSNATForDPN : Failed to update newNaptSwitch {} for routername {}", naptSwitch, routerName);
return;
}
LOG.debug("handleSNATForDPN : Switch {} is elected as NaptSwitch for router {}", dpnId, routerName);
String externalVpnName = null;
NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
naptSwitchHA.subnetRegisterMapping(extRouters, routerId);
Uuid extNwUuid = extRouters.getNetworkId();
externalVpnName = NatUtil.getAssociatedVPN(dataBroker, extNwUuid);
if (externalVpnName != null) {
naptSwitchHA.installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, extNwUuid, externalVpnName, confTx);
}
// Install miss entry (table 26) pointing to table 46
FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId, NatConstants.ADD_FLOW);
if (flowEntity == null) {
LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
return;
}
LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {}", dpnId, routerName);
mdsalManager.addFlow(confTx, flowEntity);
// Removing primary flows from old napt switch
if (naptId != null && !naptId.equals(Uint64.ZERO)) {
LOG.debug("handleSNATForDPN : Removing primary flows from old napt switch {} for router {}", naptId, routerName);
try {
naptSwitchHA.removeSnatFlowsInOldNaptSwitch(extRouters, routerId, naptId, null, externalVpnName, confTx);
} catch (Exception e) {
LOG.error("Exception while removing SnatFlows form OldNaptSwitch {}", naptId, e);
}
}
naptSwitchHA.updateNaptSwitchBucketStatus(routerName, routerId, naptSwitch);
} else if (naptId.equals(dpnId)) {
LOG.error("handleSNATForDPN : NaptSwitch {} gone down during cluster reboot came alive", naptId);
} else {
naptSwitch = naptId;
LOG.debug("handleSNATForDPN : Napt switch with Id {} is already elected for router {}", naptId, routerName);
// installing group
List<BucketInfo> bucketInfo = naptSwitchHA.handleGroupInNeighborSwitches(dpnId, routerName, routerId, naptSwitch);
naptSwitchHA.installSnatGroupEntry(dpnId, bucketInfo, routerName);
// Install miss entry (table 26) pointing to group
Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
if (groupId != NatConstants.INVALID_ID) {
FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId.longValue(), routerVpnId, NatConstants.ADD_FLOW);
if (flowEntity == null) {
LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}" + " groupId {}", routerName, dpnId, groupId);
return;
}
LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {} group {}", dpnId, routerName, groupId);
mdsalManager.addFlow(confTx, flowEntity);
} else {
LOG.error("handleSNATForDPN: Unable to get groupId for router:{}", routerName);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class UpgradeStateListener method update.
@Override
public void update(@NonNull UpgradeConfig original, UpgradeConfig updated) {
if (natMode == NatserviceConfig.NatMode.Controller) {
if (original.isUpgradeInProgress() && !updated.isUpgradeInProgress()) {
Optional<NaptSwitches> npatSwitches = NatUtil.getAllPrimaryNaptSwitches(dataBroker);
if (npatSwitches.isPresent()) {
for (RouterToNaptSwitch routerToNaptSwitch : npatSwitches.get().nonnullRouterToNaptSwitch().values()) {
Uint64 primaryNaptDpnId = routerToNaptSwitch.getPrimarySwitchId();
if (!NatUtil.getSwitchStatus(dataBroker, routerToNaptSwitch.getPrimarySwitchId())) {
String routerUuid = routerToNaptSwitch.getRouterName();
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routerUuid, () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> reElectNewNaptSwitch(routerUuid, primaryNaptDpnId, confTx))), NatConstants.NAT_DJC_MAX_RETRIES);
}
}
}
}
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.nonnullRouters().values()) {
Map<ExternalIpsKey, ExternalIps> keyExternalIpsMap = router.nonnullExternalIps();
if (router.isEnableSnat() && keyExternalIpsMap != null && !keyExternalIpsMap.isEmpty()) {
centralizedSwitchScheduler.scheduleCentralizedSwitch(router);
}
}
}
Aggregations