Search in sources :

Example 36 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project genius by opendaylight.

the class FlowBasedServicesUtils method installLPortDispatcherFlow.

public static void installLPortDispatcherFlow(BigInteger dpId, BoundServices boundService, String interfaceName, WriteTransaction writeTransaction, int interfaceTag, short currentServiceIndex, short nextServiceIndex) {
    String serviceRef = boundService.getServiceName();
    List<MatchInfo> matches = FlowBasedServicesUtils.getMatchInfoForDispatcherTable(interfaceTag, currentServiceIndex);
    // Get the metadata and mask from the service's write metadata
    // instruction
    StypeOpenflow stypeOpenFlow = boundService.getAugmentation(StypeOpenflow.class);
    List<Instruction> serviceInstructions = stypeOpenFlow.getInstruction();
    int instructionSize = serviceInstructions != null ? serviceInstructions.size() : 0;
    BigInteger[] metadataValues = IfmUtil.mergeOpenflowMetadataWriteInstructions(serviceInstructions);
    BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(interfaceTag, nextServiceIndex, metadataValues[0]);
    BigInteger metadataMask = MetaDataUtil.getWriteMetaDataMaskForDispatcherTable();
    // build the final instruction for LPort Dispatcher table flow entry
    List<Instruction> instructions = new ArrayList<>();
    instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(metadata, metadataMask, ++instructionSize));
    if (serviceInstructions != null && !serviceInstructions.isEmpty()) {
        for (Instruction info : serviceInstructions) {
            // 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()));
            }
            instructions.add(info);
        }
    }
    // build the flow and install it
    String flowRef = getFlowRef(dpId, NwConstants.LPORT_DISPATCHER_TABLE, interfaceName, currentServiceIndex);
    Flow ingressFlow = MDSALUtil.buildFlowNew(NwConstants.LPORT_DISPATCHER_TABLE, flowRef, DEFAULT_DISPATCHER_PRIORITY, serviceRef, 0, 0, stypeOpenFlow.getFlowCookie(), matches, instructions);
    LOG.debug("Installing LPort Dispatcher Flow on DPN {}, for interface {}, with flowRef {}", dpId, interfaceName, flowRef);
    installFlow(dpId, ingressFlow, writeTransaction);
}
Also used : WriteMetadataCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase) StypeOpenflow(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.StypeOpenflow) ArrayList(java.util.ArrayList) WriteActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) BigInteger(java.math.BigInteger) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase)

Example 37 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project genius by opendaylight.

the class IfmUtil method mergeOpenflowMetadataWriteInstructions.

public static BigInteger[] mergeOpenflowMetadataWriteInstructions(List<Instruction> instructions) {
    BigInteger metadata = new BigInteger("0", 16);
    BigInteger metadataMask = new BigInteger("0", 16);
    if (instructions != null && !instructions.isEmpty()) {
        // check if metadata write instruction is present
        for (Instruction instruction : instructions) {
            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction actualInstruction = instruction.getInstruction();
            if (actualInstruction instanceof WriteMetadataCase) {
                WriteMetadataCase writeMetaDataInstruction = (WriteMetadataCase) actualInstruction;
                WriteMetadata availableMetaData = writeMetaDataInstruction.getWriteMetadata();
                metadata = metadata.or(availableMetaData.getMetadata());
                metadataMask = metadataMask.or(availableMetaData.getMetadataMask());
            }
        }
    }
    return new BigInteger[] { metadata, metadataMask };
}
Also used : WriteMetadata(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadata) WriteMetadataCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase) BigInteger(java.math.BigInteger) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)

Example 38 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project genius by opendaylight.

the class ArpUtilImpl method fireArpReqRecvdNotification.

private void fireArpReqRecvdNotification(String interfaceName, InetAddress srcInetAddr, byte[] srcMac, InetAddress dstInetAddr, int tableId, BigInteger metadata) throws InterruptedException {
    arpReqRecvd.mark();
    String macAddress = NWUtil.toStringMacAddress(srcMac);
    ArpRequestReceivedBuilder builder = new ArpRequestReceivedBuilder();
    builder.setInterface(interfaceName);
    builder.setOfTableId((long) tableId);
    builder.setSrcIpaddress(new IpAddress(srcInetAddr.getHostAddress().toCharArray()));
    builder.setDstIpaddress(new IpAddress(dstInetAddr.getHostAddress().toCharArray()));
    builder.setSrcMac(new PhysAddress(macAddress));
    builder.setMetadata(metadata);
    ListenableFuture<?> offerNotification = notificationPublishService.offerNotification(builder.build());
    if (offerNotification != null && offerNotification.equals(NotificationPublishService.REJECTED)) {
        arpReqRecvdNotificationRejected.mark();
    } else {
        arpReqRecvdNotification.mark();
    }
}
Also used : ArpRequestReceivedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.ArpRequestReceivedBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)

Example 39 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project genius by opendaylight.

the class ArpUtilImpl method onPacketReceived.

@Override
public void onPacketReceived(PacketReceived packetReceived) {
    Class<? extends PacketInReason> pktInReason = packetReceived.getPacketInReason();
    LOG.trace("Packet Received {}", packetReceived);
    if (pktInReason == SendToController.class) {
        try {
            int tableId = packetReceived.getTableId().getValue();
            byte[] data = packetReceived.getPayload();
            Ethernet ethernet = new Ethernet();
            ethernet.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
            if (ethernet.getEtherType() != ArpConstants.ETH_TYPE_ARP) {
                return;
            }
            Packet pkt = ethernet.getPayload();
            ARP arp = (ARP) pkt;
            InetAddress srcInetAddr = InetAddress.getByAddress(arp.getSenderProtocolAddress());
            InetAddress dstInetAddr = InetAddress.getByAddress(arp.getTargetProtocolAddress());
            byte[] srcMac = ethernet.getSourceMACAddress();
            byte[] dstMac = ethernet.getDestinationMACAddress();
            Metadata metadata = packetReceived.getMatch().getMetadata();
            String interfaceName = getInterfaceName(metadata);
            checkAndFireMacChangedNotification(interfaceName, srcInetAddr, srcMac);
            macsDB.put(interfaceName + "-" + srcInetAddr.getHostAddress(), NWUtil.toStringMacAddress(srcMac));
            if (arp.getOpCode() == ArpConstants.ARP_REQUEST_OP) {
                fireArpReqRecvdNotification(interfaceName, srcInetAddr, srcMac, dstInetAddr, tableId, metadata.getMetadata());
            } else {
                fireArpRespRecvdNotification(interfaceName, srcInetAddr, srcMac, tableId, metadata.getMetadata(), dstInetAddr, dstMac);
            }
            if (macAddrs.get(srcInetAddr.getHostAddress()) != null) {
                threadPool.execute(new MacResponderTask(arp));
            }
        } catch (PacketException | UnknownHostException | InterruptedException | ExecutionException e) {
            LOG.trace("Failed to decode packet", e);
        }
    }
}
Also used : Packet(org.opendaylight.openflowplugin.libraries.liblldp.Packet) UnknownHostException(java.net.UnknownHostException) Metadata(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) ExecutionException(java.util.concurrent.ExecutionException) InetAddress(java.net.InetAddress) ARP(org.opendaylight.genius.mdsalutil.packet.ARP)

Example 40 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project bgpcep by opendaylight.

the class AbstractTopologySessionListener method stateSynchronizationAchieved.

/**
 * Indicate that the peer has completed state synchronization.
 *
 * @param ctx Message context
 */
protected final synchronized void stateSynchronizationAchieved(final MessageContext ctx) {
    if (this.synced.getAndSet(true)) {
        LOG.debug("State synchronization achieved while synchronizing, not updating state");
        return;
    }
    if (this.triggeredResyncInProcess) {
        this.triggeredResyncInProcess = false;
    }
    updatePccNode(ctx, new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized).build());
    // The node has completed synchronization, cleanup metadata no longer reported back
    this.nodeState.cleanupExcept(this.lsps.values());
    LOG.debug("Session {} achieved synchronized state", this.session);
}
Also used : PathComputationClientBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.pcep.client.attributes.PathComputationClientBuilder)

Aggregations

BigInteger (java.math.BigInteger)44 ArrayList (java.util.ArrayList)34 Test (org.junit.Test)22 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)14 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)13 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)13 ByteBuf (io.netty.buffer.ByteBuf)10 MetadataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder)10 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)8 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)7 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)7 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)7 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)7 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)7 MatchTunnelId (org.opendaylight.genius.mdsalutil.matches.MatchTunnelId)6 PhysAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)6 Metadata (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata)6 WriteMetadataCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCaseBuilder)6 InstructionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder)6 List (java.util.List)5