use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress in project netvirt by opendaylight.
the class ConntrackBasedSnatService method createOutboundTblEntry.
protected void createOutboundTblEntry(BigInteger dpnId, long routerId, String externalIp, int elanId, String extGwMacAddress, int addOrRemove) {
LOG.info("createOutboundTblEntry : dpId {} and routerId {}", dpnId, routerId);
List<MatchInfoBase> matches = new ArrayList<>();
matches.add(MatchEthernetType.IPV4);
matches.add(new NxMatchCtState(TRACKED_NEW_CT_STATE, TRACKED_NEW_CT_MASK));
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId), MetaDataUtil.METADATA_MASK_VRFID));
List<ActionInfo> actionsInfos = new ArrayList<>();
if (addOrRemove == NwConstants.ADD_FLOW) {
actionsInfos.add(new ActionSetFieldEthernetSource(new MacAddress(extGwMacAddress)));
}
List<NxCtAction> ctActionsListCommit = new ArrayList<>();
int rangePresent = NxActionNatRangePresent.NXNATRANGEIPV4MIN.getIntValue();
int flags = NxActionNatFlags.NXNATFSRC.getIntValue();
NxCtAction nxCtActionCommit = new ActionNxConntrack.NxNat(0, flags, rangePresent, new IpPrefixOrAddress(externalIp.toCharArray()).getIpAddress(), null, 0, 0);
ctActionsListCommit.add(nxCtActionCommit);
int ctCommitFlag = 1;
ActionNxConntrack actionNxConntrackSubmit = new ActionNxConntrack(ctCommitFlag, 0, elanId, NwConstants.NAPT_PFIB_TABLE, ctActionsListCommit);
actionsInfos.add(actionNxConntrackSubmit);
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionApplyActions(actionsInfos));
String flowRef = getFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId);
syncFlow(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, flowRef, NatConstants.SNAT_NEW_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress in project netvirt by opendaylight.
the class Ipv6ServiceUtilsTest method testgetIpv6MulticastMacAddress.
/**
* Test getIpv6MulticastMacAddress with different IPv6Address values.
*/
@Test
public void testgetIpv6MulticastMacAddress() {
Ipv6Address ipv6Address = new Ipv6Address(IPv6_ADDR_1);
MacAddress expectedMacAddress = new MacAddress("33:33:fe:4e:18:0c");
assertEquals(expectedMacAddress, Ipv6ServiceUtils.getIpv6MulticastMacAddress(ipv6Address));
ipv6Address = new Ipv6Address(IPv6_ADDR_2);
expectedMacAddress = new MacAddress("33:33:fe:4e:18:c0");
assertEquals(expectedMacAddress, Ipv6ServiceUtils.getIpv6MulticastMacAddress(ipv6Address));
ipv6Address = new Ipv6Address(IPv6_ADDR_4);
expectedMacAddress = new MacAddress("33:33:fe:0f:00:6b");
assertEquals(expectedMacAddress, Ipv6ServiceUtils.getIpv6MulticastMacAddress(ipv6Address));
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress in project netvirt by opendaylight.
the class Ipv6ServiceUtilsTest method testgetIpv6LinkLocalAddressFromMac.
/**
* Test getIpv6LinkLocalAddressFromMac with different MACAddress values.
*/
@Test
public void testgetIpv6LinkLocalAddressFromMac() {
MacAddress mac = new MacAddress("fa:16:3e:4e:18:0c");
Ipv6Address expectedLinkLocalAddress = new Ipv6Address(IPv6_ADDR_1);
assertEquals(expectedLinkLocalAddress, Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(mac));
mac = new MacAddress("fa:16:3e:4e:18:c0");
expectedLinkLocalAddress = new Ipv6Address(IPv6_ADDR_2);
assertEquals(expectedLinkLocalAddress, Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(mac));
mac = new MacAddress("0a:16:03:04:08:0c");
expectedLinkLocalAddress = new Ipv6Address(IPv6_ADDR_3);
assertEquals(expectedLinkLocalAddress, Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(mac));
mac = new MacAddress("f4:00:00:0f:00:6b");
expectedLinkLocalAddress = new Ipv6Address(IPv6_ADDR_4);
assertEquals(expectedLinkLocalAddress, Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(mac));
mac = new MacAddress("50:7B:9D:78:54:F3");
expectedLinkLocalAddress = new Ipv6Address(IPv6_ADDR_5);
assertEquals(expectedLinkLocalAddress, Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(mac));
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress in project netvirt by opendaylight.
the class IPv6Handler method installPing6ResponderFlowEntry.
public void installPing6ResponderFlowEntry(BigInteger dpnId, long vpnId, String routerInternalIp, MacAddress routerMac, long label, int addOrRemove) {
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchIpProtocol.ICMPV6);
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
matches.add(new MatchIcmpv6((short) 128, (short) 0));
matches.add(MatchEthernetType.IPV6);
matches.add(new MatchIpv6Destination(routerInternalIp));
List<ActionInfo> actionsInfos = new ArrayList<>();
// Set Eth Src and Eth Dst
actionsInfos.add(new ActionMoveSourceDestinationEth());
actionsInfos.add(new ActionSetFieldEthernetSource(routerMac));
// Move Ipv6 Src to Ipv6 Dst
actionsInfos.add(new ActionMoveSourceDestinationIpv6());
actionsInfos.add(new ActionSetSourceIpv6(new Ipv6Prefix(routerInternalIp)));
// Set the ICMPv6 type to 129 (echo reply)
actionsInfos.add(new ActionSetIcmpv6Type((short) 129));
actionsInfos.add(new ActionNxLoadInPort(BigInteger.ZERO));
actionsInfos.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionApplyActions(actionsInfos));
int priority = FibConstants.DEFAULT_FIB_FLOW_PRIORITY + FibConstants.DEFAULT_IPV6_PREFIX_LENGTH;
String flowRef = FibUtil.getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, label, priority);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, NwConstants.COOKIE_VM_FIB_TABLE, matches, instructions);
if (addOrRemove == NwConstants.ADD_FLOW) {
mdsalManager.syncInstallFlow(flowEntity);
} else {
mdsalManager.syncRemoveFlow(flowEntity);
}
}
Aggregations