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());
}
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());
}
}
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());
}
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);
}
}
}
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());
}
Aggregations