use of io.netty.channel.socket.DatagramPacket in project lispflowmapping by opendaylight.
the class LispSouthboundHandlerTest method mapRegisterAndNotify__ValidExtraDataParsedSuccessfully.
@Test
@Ignore
public void mapRegisterAndNotify__ValidExtraDataParsedSuccessfully() throws Exception {
byte[] extraDataPacket = new byte[mapRegisterPacket.length + 3];
extraDataPacket[mapRegisterPacket.length] = 0x9;
System.arraycopy(mapRegisterPacket, 0, extraDataPacket, 0, mapRegisterPacket.length);
DatagramPacket dp = new DatagramPacket(wrappedBuffer(extraDataPacket), new InetSocketAddress(0), new InetSocketAddress(0));
testedLispService.handlePacket(dp);
// Check map register fields.
// XXX: test
// byte[] notifyResult = testedLispService.handlePacket(dp).getData();
byte[] notifyResult = lastMapNotifyPacket().content().array();
assertEquals(mapRegisterPacket.length, notifyResult.length);
}
use of io.netty.channel.socket.DatagramPacket in project lispflowmapping by opendaylight.
the class LispSouthboundPluginTest method handleSerializedLispBufferTest_withIpv6.
/**
* Tests {@link LispSouthboundPlugin#handleSerializedLispBuffer} method with ipv6.
*/
@Test
public void handleSerializedLispBufferTest_withIpv6() throws NoSuchFieldException, IllegalAccessException, UnknownHostException {
final ArgumentCaptor<DatagramPacket> captor = ArgumentCaptor.forClass(DatagramPacket.class);
final InetAddress address = InetAddress.getByAddress(IPV6_BINARY.getIpv6AddressBinary().getValue());
final InetSocketAddress inetSocketAddress = new InetSocketAddress(address, PORT);
// Ensures that NPE is not thrown.
Mockito.when(channel.write(Mockito.any())).thenReturn(Mockito.mock(ChannelFuture.class));
lispSouthboundPlugin.handleSerializedLispBuffer(TRANSPORT_ADDRESS_IPV6, PACKET, MessageType.MapRequest);
Mockito.verify(channel).write(captor.capture());
Mockito.verify(channel).flush();
final DatagramPacket result = captor.getValue();
assertArrayEquals(PACKET.array(), result.content().array());
assertEquals(inetSocketAddress, result.recipient());
}
use of io.netty.channel.socket.DatagramPacket in project LanternServer by LanternPowered.
the class QueryHandler method handleBasicStats.
private void handleBasicStats(ChannelHandlerContext ctx, DatagramPacket packet, int sessionId) {
LanternServer server = this.queryServer.getGame().getServer();
// TODO: Find out how to support the size and max size properties
final Cause cause = Cause.of(EventContext.empty(), new SimpleRemoteConnection((InetSocketAddress) ctx.channel().remoteAddress(), null));
final QueryServerEvent.Basic event = SpongeEventFactory.createQueryServerEventBasic(cause, (InetSocketAddress) ctx.channel().localAddress(), "SMP", this.getWorldName(), server.getMotd().toPlain(), server.getMaxPlayers(), Integer.MAX_VALUE, server.getOnlinePlayers().size(), 0);
Sponge.getEventManager().post(event);
final InetSocketAddress address = event.getAddress();
final ByteBuf buf = ctx.alloc().buffer();
buf.writeByte(ACTION_STATS);
buf.writeInt(sessionId);
writeString(buf, event.getMotd());
writeString(buf, event.getGameType());
writeString(buf, event.getMap());
writeString(buf, String.valueOf(event.getPlayerCount()));
writeString(buf, String.valueOf(event.getMaxPlayerCount()));
buf.writeShortLE(address.getPort());
writeString(buf, address.getHostString());
ctx.write(new DatagramPacket(buf, packet.sender()));
}
use of io.netty.channel.socket.DatagramPacket in project LanternServer by LanternPowered.
the class QueryHandler method handleHandshake.
private void handleHandshake(ChannelHandlerContext ctx, DatagramPacket packet, int sessionId) {
int challengeToken = queryServer.generateChallengeToken(packet.sender());
ByteBuf out = ctx.alloc().buffer();
out.writeByte(ACTION_HANDSHAKE);
out.writeInt(sessionId);
writeString(out, String.valueOf(challengeToken));
ctx.write(new DatagramPacket(out, packet.sender()));
}
use of io.netty.channel.socket.DatagramPacket in project netty by netty.
the class DatagramPacketEncoderTest method testEncode.
private void testEncode(boolean senderIsNull) {
InetSocketAddress recipient = SocketUtils.socketAddress("127.0.0.1", 10000);
InetSocketAddress sender = senderIsNull ? null : SocketUtils.socketAddress("127.0.0.1", 20000);
assertTrue(channel.writeOutbound(new DefaultAddressedEnvelope<String, InetSocketAddress>("netty", recipient, sender)));
DatagramPacket packet = channel.readOutbound();
try {
assertEquals("netty", packet.content().toString(CharsetUtil.UTF_8));
assertEquals(recipient, packet.recipient());
assertEquals(sender, packet.sender());
} finally {
packet.release();
}
}
Aggregations