use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project genius by opendaylight.
the class ArpUtilImpl method fireArpRespRecvdNotification.
private void fireArpRespRecvdNotification(String interfaceName, InetAddress srcInetAddr, byte[] srcMacAddressBytes, int tableId, BigInteger metadata, InetAddress dstInetAddr, byte[] dstMacAddressBytes) throws InterruptedException {
arpRespRecvd.mark();
IpAddress srcIp = new IpAddress(srcInetAddr.getHostAddress().toCharArray());
IpAddress dstIp = new IpAddress(dstInetAddr.getHostAddress().toCharArray());
String srcMacAddress = NWUtil.toStringMacAddress(srcMacAddressBytes);
PhysAddress srcMac = new PhysAddress(srcMacAddress);
String dstMacAddress = NWUtil.toStringMacAddress(dstMacAddressBytes);
PhysAddress dstMac = new PhysAddress(dstMacAddress);
ArpResponseReceivedBuilder builder = new ArpResponseReceivedBuilder();
builder.setInterface(interfaceName);
builder.setSrcIpaddress(srcIp);
builder.setOfTableId((long) tableId);
builder.setSrcMac(srcMac);
builder.setMetadata(metadata);
builder.setDstIpaddress(dstIp);
builder.setDstMac(dstMac);
ListenableFuture<?> offerNotification = notificationPublishService.offerNotification(builder.build());
if (offerNotification != null && offerNotification.equals(NotificationPublishService.REJECTED)) {
arpRespRecvdNotificationRejected.mark();
} else {
arpRespRecvdNotification.mark();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project genius by opendaylight.
the class AlivenessProtocolHandlerARP method handlePacketIn.
@Override
public String handlePacketIn(ARP packet, PacketReceived packetReceived) {
short tableId = packetReceived.getTableId().getValue();
int arpType = packet.getOpCode();
if (LOG.isTraceEnabled()) {
LOG.trace("packet: {}, tableId {}, arpType {}", packetReceived, tableId, arpType);
}
if (arpType == ARP.REPLY) {
if (LOG.isTraceEnabled()) {
LOG.trace("packet: {}", packetReceived);
}
BigInteger metadata = packetReceived.getMatch().getMetadata().getMetadata();
int portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
String interfaceName = null;
try {
GetInterfaceFromIfIndexInput input = new GetInterfaceFromIfIndexInputBuilder().setIfIndex(portTag).build();
Future<RpcResult<GetInterfaceFromIfIndexOutput>> output = interfaceManager.getInterfaceFromIfIndex(input);
RpcResult<GetInterfaceFromIfIndexOutput> result = output.get();
if (result.isSuccessful()) {
GetInterfaceFromIfIndexOutput ifIndexOutput = result.getResult();
interfaceName = ifIndexOutput.getInterfaceName();
} else {
LOG.warn("RPC call to get interface name for if index {} failed with errors {}", portTag, result.getErrors());
return null;
}
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Error retrieving interface Name for tag {}", portTag, e);
}
if (!Strings.isNullOrEmpty(interfaceName)) {
String sourceIp = NWUtil.toStringIpAddress(packet.getSenderProtocolAddress());
String targetIp = NWUtil.toStringIpAddress(packet.getTargetProtocolAddress());
return getMonitoringKey(interfaceName, targetIp, sourceIp);
} else {
LOG.debug("No interface associated with tag {} to interpret the received ARP Reply", portTag);
}
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project genius by opendaylight.
the class FlowBasedServicesUtils method installLportIngressFlow.
public static void installLportIngressFlow(BigInteger dpId, long portNo, Interface iface, List<ListenableFuture<Void>> futures, ManagedNewTransactionRunner txRunner, int lportTag) {
int vlanId = 0;
boolean isVlanTransparent = false;
IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class);
if (l2vlan != null) {
vlanId = l2vlan.getVlanId() == null ? 0 : l2vlan.getVlanId().getValue();
isVlanTransparent = l2vlan.getL2vlanMode() == IfL2vlan.L2vlanMode.Transparent;
}
int instructionKey = 0;
List<Instruction> instructions = new ArrayList<>();
final SplitHorizon splitHorizon = iface.getAugmentation(SplitHorizon.class);
boolean overrideSplitHorizonProtection = splitHorizon != null && splitHorizon.isOverrideSplitHorizonProtection();
int actionKey = -1;
List<Action> actions = new ArrayList<>();
if (vlanId != 0 && !isVlanTransparent) {
actions.add(MDSALUtil.createPopVlanAction(++actionKey));
}
if (overrideSplitHorizonProtection) {
actions.add(MDSALUtil.createNxOfInPortAction(++actionKey, 0));
}
if (!actions.isEmpty()) {
instructions.add(MDSALUtil.buildApplyActionsInstruction(actions, instructionKey++));
}
BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(lportTag, (short) 0, BigInteger.ZERO, isExternal(iface));
BigInteger metadataMask = MetaDataUtil.getMetaDataMaskForLPortDispatcher(MetaDataUtil.METADATA_MASK_LPORT_TAG_SH_FLAG);
instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(metadata, metadataMask, instructionKey++));
instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.LPORT_DISPATCHER_TABLE, instructionKey++));
int priority = isVlanTransparent ? 1 : vlanId == 0 ? IfmConstants.FLOW_PRIORITY_FOR_UNTAGGED_VLAN : IfmConstants.FLOW_HIGH_PRIORITY;
String flowRef = getFlowRef(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE, dpId, iface.getName());
List<MatchInfo> matches = getMatchInfoForVlanPortAtIngressTable(dpId, portNo, iface);
Flow ingressFlow = MDSALUtil.buildFlowNew(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE, flowRef, priority, flowRef, 0, 0, NwConstants.VLAN_TABLE_COOKIE, matches, instructions);
LOG.debug("Installing ingress flow {} for {}", flowRef, iface.getName());
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> installFlow(dpId, ingressFlow, tx)));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project genius by opendaylight.
the class FlowBasedServicesUtils method installInterfaceIngressFlow.
public static void installInterfaceIngressFlow(BigInteger dpId, Interface iface, BoundServices boundServiceNew, WriteTransaction writeTransaction, List<MatchInfo> matches, int lportTag, short tableId) {
List<Instruction> instructions = boundServiceNew.getAugmentation(StypeOpenflow.class).getInstruction();
int serviceInstructionsSize = instructions != null ? instructions.size() : 0;
List<Instruction> instructionSet = new ArrayList<>();
int vlanId = 0;
IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class);
if (l2vlan != null && l2vlan.getVlanId() != null) {
vlanId = l2vlan.getVlanId().getValue();
}
if (vlanId != 0) {
// incrementing instructionSize and using it as actionKey. Because
// it won't clash with any other instructions
int actionKey = ++serviceInstructionsSize;
instructionSet.add(MDSALUtil.buildAndGetPopVlanActionInstruction(actionKey, ++serviceInstructionsSize));
}
if (lportTag != 0L) {
BigInteger[] metadataValues = IfmUtil.mergeOpenflowMetadataWriteInstructions(instructions);
short index = boundServiceNew.getServicePriority();
BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(lportTag, ++index, metadataValues[0], isExternal(iface));
BigInteger metadataMask = MetaDataUtil.getMetaDataMaskForLPortDispatcher(MetaDataUtil.METADATA_MASK_SERVICE_INDEX, MetaDataUtil.METADATA_MASK_LPORT_TAG_SH_FLAG, metadataValues[1]);
instructionSet.add(MDSALUtil.buildAndGetWriteMetadaInstruction(metadata, metadataMask, ++serviceInstructionsSize));
}
if (instructions != null && !instructions.isEmpty()) {
for (Instruction info : instructions) {
// Skip meta data write as that is handled already
if (info.getInstruction() instanceof WriteMetadataCase) {
continue;
} else if (info.getInstruction() instanceof WriteActionsCase) {
info = MDSALUtil.buildWriteActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction(((WriteActionsCase) info.getInstruction()).getWriteActions().getAction()));
} else if (info.getInstruction() instanceof ApplyActionsCase) {
info = MDSALUtil.buildApplyActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction(((ApplyActionsCase) info.getInstruction()).getApplyActions().getAction()));
}
instructionSet.add(info);
}
}
String serviceRef = boundServiceNew.getServiceName();
String flowRef = getFlowRef(dpId, NwConstants.VLAN_INTERFACE_INGRESS_TABLE, iface.getName(), boundServiceNew.getServicePriority());
StypeOpenflow stypeOpenflow = boundServiceNew.getAugmentation(StypeOpenflow.class);
Flow ingressFlow = MDSALUtil.buildFlowNew(tableId, flowRef, stypeOpenflow.getFlowPriority(), serviceRef, 0, 0, stypeOpenflow.getFlowCookie(), matches, instructionSet);
installFlow(dpId, ingressFlow, writeTransaction);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project genius by opendaylight.
the class FlowBasedServicesUtils method installEgressDispatcherFlow.
private static void installEgressDispatcherFlow(BigInteger dpId, BoundServices boundService, String interfaceName, WriteTransaction writeTransaction, int interfaceTag, short currentServiceIndex, short nextServiceIndex) {
// Get the metadata and mask from the service's write metadata instruction
StypeOpenflow stypeOpenflow = boundService.getAugmentation(StypeOpenflow.class);
if (stypeOpenflow == null) {
LOG.warn("Could not install egress dispatcher flow, missing service openflow configuration");
return;
}
List<Instruction> serviceInstructions = stypeOpenflow.getInstruction() != null ? stypeOpenflow.getInstruction() : Collections.emptyList();
// build the final instruction for LPort Dispatcher table flow entry
List<Action> finalApplyActions = new ArrayList<>();
List<Instruction> instructions = new ArrayList<>();
if (boundService.getServicePriority() != ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, NwConstants.DEFAULT_EGRESS_SERVICE_INDEX)) {
BigInteger[] metadataValues = IfmUtil.mergeOpenflowMetadataWriteInstructions(serviceInstructions);
BigInteger metadataMask = MetaDataUtil.getWriteMetaDataMaskForEgressDispatcherTable();
instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(metadataValues[0], metadataMask, instructions.size()));
finalApplyActions.add(MDSALUtil.createSetReg6Action(finalApplyActions.size(), 0, 31, MetaDataUtil.getReg6ValueForLPortDispatcher(interfaceTag, nextServiceIndex)));
}
final int applyActionsOffset = finalApplyActions.size();
for (Instruction info : serviceInstructions) {
if (info.getInstruction() instanceof WriteActionsCase) {
List<Action> writeActions = ActionConverterUtil.convertServiceActionToFlowAction(((WriteActionsCase) info.getInstruction()).getWriteActions().getAction());
instructions.add(MDSALUtil.buildWriteActionsInstruction(writeActions, instructions.size()));
} else if (info.getInstruction() instanceof ApplyActionsCase) {
List<Action> applyActions = ActionConverterUtil.convertServiceActionToFlowAction(((ApplyActionsCase) info.getInstruction()).getApplyActions().getAction(), applyActionsOffset);
finalApplyActions.addAll(applyActions);
} else if (!(info.getInstruction() instanceof WriteMetadataCase)) {
// Skip meta data write as that is handled already
instructions.add(MDSALUtil.buildInstruction(info, instructions.size()));
}
}
if (!finalApplyActions.isEmpty()) {
instructions.add(MDSALUtil.buildApplyActionsInstruction(finalApplyActions, instructions.size()));
}
// build the flow and install it
String serviceRef = boundService.getServiceName();
List<? extends MatchInfoBase> matches = FlowBasedServicesUtils.getMatchInfoForEgressDispatcherTable(interfaceTag, currentServiceIndex);
String flowRef = getFlowRef(dpId, NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, interfaceName, currentServiceIndex);
Flow egressFlow = MDSALUtil.buildFlowNew(NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, flowRef, boundService.getServicePriority(), serviceRef, 0, 0, stypeOpenflow.getFlowCookie(), matches, instructions);
LOG.debug("Installing Egress Dispatcher Flow for interface : {}, with flow-ref : {}", interfaceName, flowRef);
installFlow(dpId, egressFlow, writeTransaction);
}
Aggregations