use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.
the class ElanUtils method updateOperationalDataStore.
/**
* Updates the Elan information in the Operational DS. It also updates the
* ElanInstance in the Config DS by setting the adquired elanTag.
*
* @param idManager
* the id manager
* @param elanInstanceAdded
* the elan instance added
* @param elanInterfaces
* the elan interfaces
* @param operTx
* transaction
*
* @return the updated ELAN instance.
*/
public static ElanInstance updateOperationalDataStore(IdManagerService idManager, ElanInstance elanInstanceAdded, List<String> elanInterfaces, TypedWriteTransaction<Configuration> confTx, TypedWriteTransaction<Operational> operTx) {
String elanInstanceName = elanInstanceAdded.getElanInstanceName();
Uint32 elanTag = elanInstanceAdded.getElanTag();
if (elanTag == null || elanTag.longValue() == 0L) {
elanTag = retrieveNewElanTag(idManager, elanInstanceName);
}
if (elanTag.longValue() == 0L) {
LOG.error("ELAN tag creation failed for elan instance {}. Not updating the ELAN DS. " + "Recreate network for recovery", elanInstanceName);
return null;
}
Elan elanInfo = new ElanBuilder().setName(elanInstanceName).setElanInterfaces(elanInterfaces).withKey(new ElanKey(elanInstanceName)).build();
// Add the ElanState in the elan-state operational data-store
operTx.mergeParentStructurePut(getElanInstanceOperationalDataPath(elanInstanceName), elanInfo);
// Add the ElanMacTable in the elan-mac-table operational data-store
MacTable elanMacTable = new MacTableBuilder().withKey(new MacTableKey(elanInstanceName)).build();
operTx.mergeParentStructurePut(getElanMacTableOperationalDataPath(elanInstanceName), elanMacTable);
ElanTagNameBuilder elanTagNameBuilder = new ElanTagNameBuilder().setElanTag(elanTag).withKey(new ElanTagNameKey(elanTag)).setName(elanInstanceName);
Uint32 etreeLeafTag = Uint32.valueOf(0L);
if (isEtreeInstance(elanInstanceAdded)) {
etreeLeafTag = retrieveNewElanTag(idManager, elanInstanceName + ElanConstants.LEAVES_POSTFIX);
EtreeLeafTagName etreeLeafTagName = new EtreeLeafTagNameBuilder().setEtreeLeafTag(new EtreeLeafTag(etreeLeafTag)).build();
elanTagNameBuilder.addAugmentation(etreeLeafTagName);
addTheLeafTagAsElanTag(elanInstanceName, etreeLeafTag, operTx);
}
ElanTagName elanTagName = elanTagNameBuilder.build();
// Add the ElanTag to ElanName in the elan-tag-name Operational
// data-store
operTx.put(getElanInfoEntriesOperationalDataPath(elanTag), elanTagName);
// Updates the ElanInstance Config DS by setting the just acquired
// elanTag
ElanInstanceBuilder elanInstanceBuilder = new ElanInstanceBuilder(elanInstanceAdded).setElanInstanceName(elanInstanceName).setDescription(elanInstanceAdded.getDescription()).setMacTimeout(elanInstanceAdded.getMacTimeout() == null ? Uint32.valueOf(ElanConstants.DEFAULT_MAC_TIME_OUT) : elanInstanceAdded.getMacTimeout()).withKey(elanInstanceAdded.key()).setElanTag(elanTag);
if (isEtreeInstance(elanInstanceAdded)) {
EtreeInstance etreeInstance = new EtreeInstanceBuilder().setEtreeLeafTagVal(new EtreeLeafTag(etreeLeafTag)).build();
elanInstanceBuilder.addAugmentation(etreeInstance);
}
ElanInstance elanInstanceWithTag = elanInstanceBuilder.build();
LOG.trace("Updated elan Operational DS for elan: {} with elanTag: {} and interfaces: {}", elanInstanceName, elanTag, elanInterfaces);
confTx.mergeParentStructureMerge(ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName), elanInstanceWithTag);
return elanInstanceWithTag;
}
use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.
the class ElanUtils method deleteMacFlows.
public void deleteMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress, boolean deleteSmac, TypedReadWriteTransaction<Configuration> flowTx) throws ExecutionException, InterruptedException {
String elanInstanceName = elanInfo.getElanInstanceName();
List<DpnInterfaces> remoteFEs = getInvolvedDpnsInElan(elanInstanceName);
Uint64 srcdpId = interfaceInfo.getDpId();
boolean isFlowsRemovedInSrcDpn = false;
for (DpnInterfaces dpnInterface : remoteFEs) {
Uint32 elanTag = elanInfo.getElanTag();
Uint64 dstDpId = dpnInterface.getDpId();
if (executeDeleteMacFlows(elanInfo, interfaceInfo, macAddress, deleteSmac, elanInstanceName, srcdpId, elanTag, dstDpId, flowTx)) {
isFlowsRemovedInSrcDpn = true;
}
executeEtreeDeleteMacFlows(elanInfo, interfaceInfo, macAddress, deleteSmac, elanInstanceName, srcdpId, elanTag, dstDpId, flowTx);
}
if (!isFlowsRemovedInSrcDpn) {
deleteSmacAndDmacFlows(elanInfo, interfaceInfo, macAddress, deleteSmac, flowTx);
}
}
use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.
the class ElanUtils method deleteSmacAndDmacFlows.
private void deleteSmacAndDmacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress, boolean deleteSmac, TypedReadWriteTransaction<Configuration> flowTx) throws ExecutionException, InterruptedException {
String elanInstanceName = elanInfo.getElanInstanceName();
Uint64 srcdpId = interfaceInfo.getDpId();
Uint32 elanTag = elanInfo.getElanTag();
if (deleteSmac) {
LOG.debug("Deleting SMAC flow with id {}", getKnownDynamicmacFlowRef(elanTag, macAddress));
mdsalManager.removeFlow(flowTx, srcdpId, MDSALUtil.buildFlow(NwConstants.ELAN_SMAC_TABLE, getKnownDynamicmacFlowRef(elanTag, macAddress)));
}
mdsalManager.removeFlow(flowTx, srcdpId, MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE, getKnownDynamicmacFlowRef(elanTag, macAddress)));
LOG.debug("All the required flows deleted for elan:{}, logical Interface port:{} and MAC address:{} on dpn:{}", elanInstanceName, interfaceInfo.getPortName(), macAddress, srcdpId);
}
use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.
the class BaseVrfEntryHandler method makeConnectedRoute.
// Allow deprecated TransactionRunner calls for now
@SuppressWarnings("ForbidCertainMethod")
protected void makeConnectedRoute(Uint64 dpId, Uint32 vpnId, VrfEntry vrfEntry, String rd, @Nullable List<InstructionInfo> instructions, int addOrRemove, WriteTransaction tx, @Nullable List<SubTransaction> subTxns) {
if (tx == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, newTx -> makeConnectedRoute(dpId, vpnId, vrfEntry, rd, instructions, addOrRemove, TransactionAdapter.toWriteTransaction(newTx), subTxns)), LOG, "Error making connected route");
return;
}
LOG.trace("makeConnectedRoute: vrfEntry {}", vrfEntry);
String[] values = vrfEntry.getDestPrefix().split("/");
String ipAddress = values[0];
int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
if (addOrRemove == NwConstants.ADD_FLOW) {
LOG.debug("Adding route to DPN {} for rd {} prefix {} ", dpId, rd, vrfEntry.getDestPrefix());
} else {
LOG.debug("Removing route from DPN {} for rd {} prefix {}", dpId, rd, vrfEntry.getDestPrefix());
}
InetAddress destPrefix;
try {
destPrefix = InetAddress.getByName(ipAddress);
} catch (UnknownHostException e) {
LOG.error("Failed to get destPrefix for prefix {} rd {} VpnId {} DPN {}", vrfEntry.getDestPrefix(), rd, vpnId, dpId, e);
return;
}
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
if (destPrefix instanceof Inet4Address) {
matches.add(MatchEthernetType.IPV4);
if (prefixLength != 0) {
matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
}
} else {
matches.add(MatchEthernetType.IPV6);
if (prefixLength != 0) {
matches.add(new MatchIpv6Destination(destPrefix.getHostAddress() + "/" + prefixLength));
}
}
int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
String flowRef = FibUtil.getFlowRef(dpId, NwConstants.L3_FIB_TABLE, rd, priority, destPrefix);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_VM_FIB_TABLE, matches, instructions);
Flow flow = flowEntity.getFlowBuilder().build();
String flowId = flowEntity.getFlowId();
FlowKey flowKey = new FlowKey(new FlowId(flowId));
Node nodeDpn = FibUtil.buildDpnNode(dpId);
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.key()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP) {
SubTransaction subTransaction = new SubTransactionImpl();
if (addOrRemove == NwConstants.ADD_FLOW) {
subTransaction.setInstanceIdentifier(flowInstanceId);
subTransaction.setInstance(flow);
subTransaction.setAction(SubTransaction.CREATE);
} else {
subTransaction.setInstanceIdentifier(flowInstanceId);
subTransaction.setAction(SubTransaction.DELETE);
}
subTxns.add(subTransaction);
}
if (addOrRemove == NwConstants.ADD_FLOW) {
tx.mergeParentStructurePut(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow);
} else {
tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
}
}
use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.
the class BaseVrfEntryHandler method deleteRemoteRoute.
// Allow deprecated TransactionRunner calls for now
@SuppressWarnings("ForbidCertainMethod")
public void deleteRemoteRoute(@Nullable final Uint64 localDpnId, final Uint64 remoteDpnId, final Uint32 vpnId, final VrfTablesKey vrfTableKey, final VrfEntry vrfEntry, Optional<Routes> extraRouteOptional, @Nullable WriteTransaction tx) {
if (tx == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, newTx -> deleteRemoteRoute(localDpnId, remoteDpnId, vpnId, vrfTableKey, vrfEntry, extraRouteOptional, TransactionAdapter.toWriteTransaction(newTx))), LOG, "Error deleting remote route");
return;
}
LOG.debug("deleting remote route: prefix={}, vpnId={} localDpnId {} remoteDpnId {}", vrfEntry.getDestPrefix(), vpnId, localDpnId, remoteDpnId);
String rd = vrfTableKey.getRouteDistinguisher();
if (localDpnId != null && !Uint64.ZERO.equals(localDpnId)) {
// localDpnId is not known when clean up happens for last vm for a vpn on a dpn
if (extraRouteOptional.isPresent()) {
nextHopManager.deleteLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix());
}
makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, null, NwConstants.DEL_FLOW, tx, null);
LOG.debug("Successfully delete FIB entry: vrfEntry={}, vpnId={}", vrfEntry.getDestPrefix(), vpnId);
return;
}
// below two reads are kept as is, until best way is found to identify dpnID
VpnNexthop localNextHopInfo = nextHopManager.getVpnNexthop(vpnId, vrfEntry.getDestPrefix());
if (extraRouteOptional.isPresent()) {
nextHopManager.deleteLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix());
} else {
checkDpnDeleteFibEntry(localNextHopInfo, remoteDpnId, vpnId, vrfEntry, rd, tx, null);
}
}
Aggregations