Search in sources :

Example 6 with PacketReceived

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project openflowplugin by opendaylight.

the class PacketReceivedTranslatorTest method testTranslate.

@Test
public void testTranslate() throws Exception {
    final KeyedInstanceIdentifier<Node, NodeKey> nodePath = KeyedInstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:10")));
    final PacketReceivedTranslator packetReceivedTranslator = new PacketReceivedTranslator(convertorManager);
    final PacketInMessage packetInMessage = createPacketInMessage(DATA.getBytes(), PORT_NO);
    Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
    final PacketReceived packetReceived = packetReceivedTranslator.translate(packetInMessage, deviceInfo, null);
    Assert.assertArrayEquals(packetInMessage.getData(), packetReceived.getPayload());
    Assert.assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.SendToController", packetReceived.getPacketInReason().getName());
    Assert.assertEquals("openflow:10:" + PORT_NO, packetReceived.getIngress().getValue().firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue());
    Assert.assertEquals(0L, packetReceived.getFlowCookie().getValue().longValue());
    Assert.assertEquals(42L, packetReceived.getTableId().getValue().longValue());
}
Also used : NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) PacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey) Test(org.junit.Test)

Example 7 with PacketReceived

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project openflowplugin by opendaylight.

the class DeviceContextImpl method processPacketInMessage.

@Override
public void processPacketInMessage(final PacketInMessage packetInMessage) {
    if (isMasterOfDevice()) {
        final PacketReceived packetReceived = packetInTranslator.translate(packetInMessage, getDeviceInfo(), null);
        handlePacketInMessage(packetReceived, packetInMessage.getImplementedInterface(), packetReceived.getMatch());
    } else {
        LOG.debug("Controller is not owner of the device {}, skipping packet_in message", deviceInfo.getLOGValue());
    }
}
Also used : PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived)

Example 8 with PacketReceived

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project openflowplugin by opendaylight.

the class DeviceContextImplTest method setUp.

@Before
public void setUp() throws Exception {
    final CheckedFuture<Optional<Node>, ReadFailedException> noExistNodeFuture = Futures.immediateCheckedFuture(Optional.<Node>absent());
    Mockito.when(readTx.read(LogicalDatastoreType.OPERATIONAL, nodeKeyIdent)).thenReturn(noExistNodeFuture);
    Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(readTx);
    Mockito.when(dataBroker.createTransactionChain(Mockito.any(TransactionChainManager.class))).thenReturn(txChainFactory);
    Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeKeyIdent);
    Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
    Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.ONE);
    final SettableFuture<RpcResult<GetAsyncReply>> settableFuture = SettableFuture.create();
    final SettableFuture<RpcResult<MultipartReply>> settableFutureMultiReply = SettableFuture.create();
    Mockito.when(requestContext.getFuture()).thenReturn(settableFuture);
    Mockito.doAnswer(invocation -> {
        settableFuture.set((RpcResult<GetAsyncReply>) invocation.getArguments()[0]);
        return null;
    }).when(requestContext).setResult(any(RpcResult.class));
    Mockito.when(requestContextMultiReply.getFuture()).thenReturn(settableFutureMultiReply);
    Mockito.doAnswer(invocation -> {
        settableFutureMultiReply.set((RpcResult<MultipartReply>) invocation.getArguments()[0]);
        return null;
    }).when(requestContextMultiReply).setResult(any(RpcResult.class));
    Mockito.when(txChainFactory.newReadWriteTransaction()).thenReturn(writeTx);
    Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(readTx);
    Mockito.when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
    Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
    Mockito.when(connectionContext.getDeviceInfo()).thenReturn(deviceInfo);
    final FeaturesReply mockedFeaturesReply = mock(FeaturesReply.class);
    when(connectionContext.getFeatures()).thenReturn(mockedFeaturesReply);
    when(connectionContext.getFeatures().getCapabilities()).thenReturn(mock(Capabilities.class));
    Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    Mockito.when(featuresOutput.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
    Mockito.when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    Mockito.when(contextChainHolder.getContextChain(deviceInfo)).thenReturn(contextChain);
    Mockito.when(contextChain.isMastered(ContextChainMastershipState.CHECK, false)).thenReturn(true);
    final PacketReceived packetReceived = new PacketReceivedBuilder().setMatch(new org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.MatchBuilder().setInPort(new NodeConnectorId("openflow:1:LOCAL")).build()).build();
    Mockito.when(messageTranslatorPacketReceived.translate(any(Object.class), any(DeviceInfo.class), any(Object.class))).thenReturn(packetReceived);
    Mockito.when(messageTranslatorFlowCapableNodeConnector.translate(any(Object.class), any(DeviceInfo.class), any(Object.class))).thenReturn(mock(FlowCapableNodeConnector.class));
    Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3, PacketIn.class.getName())))).thenReturn(messageTranslatorPacketReceived);
    Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3, PortGrouping.class.getName())))).thenReturn(messageTranslatorFlowCapableNodeConnector);
    Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3, FlowRemoved.class.getName())))).thenReturn(messageTranslatorFlowRemoved);
    Mockito.when(abstractDeviceInitializer.initialize(any(), anyBoolean(), anyBoolean(), any(), any())).thenReturn(Futures.immediateFuture(null));
    final java.util.Optional<AbstractDeviceInitializer> deviceInitializer = java.util.Optional.of(this.abstractDeviceInitializer);
    Mockito.when(deviceInitializerProvider.lookup(OFConstants.OFP_VERSION_1_3)).thenReturn(deviceInitializer);
    Mockito.when(salRoleService.setRole(any())).thenReturn(Futures.immediateFuture(null));
    deviceContext = new DeviceContextImpl(connectionContext, dataBroker, messageSpy, translatorLibrary, convertorExecutor, false, timer, false, deviceInitializerProvider, true, false, contextChainHolder);
    ((DeviceContextImpl) deviceContext).lazyTransactionManagerInitialization();
    deviceContextSpy = Mockito.spy(deviceContext);
    xid = new Xid(atomicLong.incrementAndGet());
    xidMulti = new Xid(atomicLong.incrementAndGet());
    Mockito.doNothing().when(deviceContextSpy).writeToTransaction(any(), any(), any());
}
Also used : MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) TranslatorKey(org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey) PacketReceivedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder) GetAsyncReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncReply) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) FlowRemoved(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) AbstractDeviceInitializer(org.opendaylight.openflowplugin.impl.device.initialization.AbstractDeviceInitializer) Optional(com.google.common.base.Optional) FeaturesReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) PortGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) PacketIn(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketIn) Xid(org.opendaylight.openflowplugin.api.openflow.device.Xid) Capabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities) TransactionChainManager(org.opendaylight.openflowplugin.common.txchain.TransactionChainManager) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Before(org.junit.Before)

Example 9 with PacketReceived

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived 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 10 with PacketReceived

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project genius by opendaylight.

the class ArpUtilTest method testGetMac.

@Test
public void testGetMac() throws Exception {
    final InterfaceAddress interfaceAddress = new InterfaceAddressBuilder().setInterface(INTERFACE_NAME).setIpAddress(new IpAddress(Ipv4Address.getDefaultInstance("192.168.0.1"))).setMacaddress(new PhysAddress("1F:1F:1F:1F:1F:1F")).build();
    final List<InterfaceAddress> itf = Arrays.asList(interfaceAddress);
    GetMacInput getMacInput = new GetMacInputBuilder().setIpaddress(new IpAddress(Ipv4Address.getDefaultInstance("192.168.0.2"))).setInterfaceAddress(itf).build();
    // request payload
    PacketReceived packetReceived = ArpUtilTestUtil.createPayload(0);
    Future<RpcResult<GetMacOutput>> output = odlArputilService.getMac(getMacInput);
    arpUtil.onPacketReceived(packetReceived);
    Assert.assertEquals("00:01:02:03:04:05", output.get().getResult().getMacaddress().getValue());
}
Also used : InterfaceAddressBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddressBuilder) InterfaceAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddress) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetMacInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacInput) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) GetMacInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacInputBuilder) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress) Test(org.junit.Test)

Aggregations

BigInteger (java.math.BigInteger)5 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)5 PacketReceived (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived)5 Ethernet (org.opendaylight.genius.mdsalutil.packet.Ethernet)4 PacketException (org.opendaylight.openflowplugin.libraries.liblldp.PacketException)4 PacketReceivedBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder)4 ExecutionException (java.util.concurrent.ExecutionException)3 Test (org.junit.Test)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 UnknownHostException (java.net.UnknownHostException)2 InterfaceInfo (org.opendaylight.genius.interfacemanager.globals.InterfaceInfo)2 Packet (org.opendaylight.openflowplugin.libraries.liblldp.Packet)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)2 PhysAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)2 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)2 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)2 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)2 TableId (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId)2 Optional (com.google.common.base.Optional)1