use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.
the class ExternalNetworksChangeListenerTest method testSnatFlowEntity.
@Test
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void testSnatFlowEntity() {
FlowEntity flowMock = mock(FlowEntity.class);
final short snatTable = 40;
final int defaultSnatFlowPriority = 0;
final String flowidSeparator = ".";
String routerName = "200";
List<BucketInfo> bucketInfo = new ArrayList<>();
List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
listActionInfoPrimary.add(new ActionOutput(new Uri("3")));
BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
List<ActionInfo> listActionInfoSecondary = new ArrayList<>();
listActionInfoSecondary.add(new ActionOutput(new Uri("4")));
BucketInfo bucketSecondary = new BucketInfo(listActionInfoPrimary);
bucketInfo.add(0, bucketPrimary);
bucketInfo.add(1, bucketSecondary);
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.IPV4);
List<InstructionInfo> instructions = new ArrayList<>();
List<ActionInfo> actionsInfos = new ArrayList<>();
long groupId = 300;
actionsInfos.add(new ActionGroup(groupId));
instructions.add(new InstructionApplyActions(actionsInfos));
BigInteger dpnId = new BigInteger("100");
long routerId = 200;
String snatFlowidPrefix = "SNAT.";
String flowRef = snatFlowidPrefix + dpnId + flowidSeparator + snatTable + flowidSeparator + routerId;
BigInteger cookieSnat = NatUtil.getCookieSnatFlow(routerId);
try {
PowerMockito.when(MDSALUtil.class, "buildFlowEntity", dpnId, snatTable, flowRef, defaultSnatFlowPriority, flowRef, 0, 0, cookieSnat, matches, instructions).thenReturn(flowMock);
} catch (Exception e) {
// Test failed anyways
assertEquals("true", "false");
}
/* TODO : Fix this to mock it properly when it reads DS
extNetworks.buildSnatFlowEntity(dpnId, routerName, groupId);
PowerMockito.verifyStatic(); */
}
use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.
the class Ipv6ServiceUtils method installIcmpv6RsPuntFlow.
public void installIcmpv6RsPuntFlow(short tableId, BigInteger dpId, Long elanTag, int addOrRemove) {
if (dpId == null || dpId.equals(Ipv6Constants.INVALID_DPID)) {
return;
}
List<MatchInfo> routerSolicitationMatch = getIcmpv6RSMatch(elanTag);
List<InstructionInfo> instructions = new ArrayList<>();
List<ActionInfo> actionsInfos = new ArrayList<>();
// Punt to controller
actionsInfos.add(new ActionPuntToController());
instructions.add(new InstructionApplyActions(actionsInfos));
FlowEntity rsFlowEntity = MDSALUtil.buildFlowEntity(dpId, tableId, getIPv6FlowRef(dpId, elanTag, "IPv6RS"), Ipv6Constants.DEFAULT_FLOW_PRIORITY, "IPv6RS", 0, 0, NwConstants.COOKIE_IPV6_TABLE, routerSolicitationMatch, instructions);
if (addOrRemove == Ipv6Constants.DEL_FLOW) {
LOG.trace("Removing IPv6 Router Solicitation Flow DpId {}, elanTag {}", dpId, elanTag);
mdsalUtil.removeFlow(rsFlowEntity);
} else {
LOG.trace("Installing IPv6 Router Solicitation Flow DpId {}, elanTag {}", dpId, elanTag);
mdsalUtil.installFlow(rsFlowEntity);
}
}
use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.
the class SNATDefaultRouteProgrammer method installDefNATRouteInDPN.
void installDefNATRouteInDPN(BigInteger dpnId, long bgpVpnId, long routerId, WriteTransaction writeFlowInvTx) {
FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, bgpVpnId, routerId);
if (flowEntity == null) {
LOG.error("installDefNATRouteInDPN : Flow entity received is NULL." + "Cannot proceed with installation of Default NAT flow");
return;
}
NatServiceCounters.install_default_nat_flow.inc();
mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
}
use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.
the class SNATDefaultRouteProgrammer method addOrDelDefaultFibRouteToSNATForSubnet.
void addOrDelDefaultFibRouteToSNATForSubnet(Subnets subnet, String networkId, int flowAction, long vpnId) {
String subnetId = subnet.getId().getValue();
InstanceIdentifier<VpnInstanceOpDataEntry> networkVpnInstanceIdentifier = NatUtil.getVpnInstanceOpDataIdentifier(networkId);
Optional<VpnInstanceOpDataEntry> networkVpnInstanceOp = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, networkVpnInstanceIdentifier);
if (!networkVpnInstanceOp.isPresent()) {
LOG.debug("addOrDelDefaultFibRouteToSNATForSubnet : Cannot create/remove default FIB route to SNAT flow " + "for subnet {} vpn-instance-op-data entry for network {} does not exist", subnetId, networkId);
return;
}
List<VpnToDpnList> dpnListInVpn = networkVpnInstanceOp.get().getVpnToDpnList();
if (dpnListInVpn == null) {
LOG.debug("addOrDelDefaultFibRouteToSNATForSubnet : Will not add/remove default NAT flow for subnet {} " + "no dpn set for vpn instance {}", subnetId, networkVpnInstanceOp.get());
return;
}
for (VpnToDpnList dpn : dpnListInVpn) {
String macAddress = NatUtil.getSubnetGwMac(dataBroker, subnet.getId(), networkId);
extNetGroupInstaller.installExtNetGroupEntry(new Uuid(networkId), subnet.getId(), dpn.getDpnId(), macAddress);
FlowEntity flowEntity = NatUtil.buildDefaultNATFlowEntityForExternalSubnet(dpn.getDpnId(), vpnId, subnetId, idManager);
if (flowAction == NwConstants.ADD_FLOW || flowAction == NwConstants.MOD_FLOW) {
LOG.info("addOrDelDefaultFibRouteToSNATForSubnet : Installing flow {} for subnetId {}," + "vpnId {} on dpn {}", flowEntity, subnetId, vpnId, dpn.getDpnId());
mdsalManager.installFlow(flowEntity);
} else {
LOG.info("addOrDelDefaultFibRouteToSNATForSubnet : Removing flow for subnetId {}," + "vpnId {} with dpn {}", subnetId, vpnId, dpn);
mdsalManager.removeFlow(flowEntity);
}
}
}
use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.
the class AbstractAclServiceImpl method syncFlow.
/**
* Writes/remove the flow to/from the datastore.
*
* @param dpId
* the dpId
* @param tableId
* the tableId
* @param flowId
* the flowId
* @param priority
* the priority
* @param flowName
* the flow name
* @param idleTimeOut
* the idle timeout
* @param hardTimeOut
* the hard timeout
* @param cookie
* the cookie
* @param matches
* the list of matches to be writted
* @param instructions
* the list of instruction to be written.
* @param addOrRemove
* add or remove the entries.
*/
protected void syncFlow(BigInteger dpId, short tableId, String flowId, int priority, String flowName, int idleTimeOut, int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase> matches, List<InstructionInfo> instructions, int addOrRemove) {
jobCoordinator.enqueueJob(flowName, () -> {
if (addOrRemove == NwConstants.DEL_FLOW) {
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId, flowId, priority, flowName, idleTimeOut, hardTimeOut, cookie, matches, null);
LOG.trace("Removing Acl Flow DpnId {}, flowId {}", dpId, flowId);
return Collections.singletonList(mdsalManager.removeFlow(dpId, flowEntity));
} else {
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId, flowId, priority, flowName, idleTimeOut, hardTimeOut, cookie, matches, instructions);
LOG.trace("Installing DpnId {}, flowId {}", dpId, flowId);
return Collections.singletonList(mdsalManager.installFlow(dpId, flowEntity));
}
});
}
Aggregations