List of usage examples for io.netty.channel.socket DatagramPacket DatagramPacket
public DatagramPacket(ByteBuf data, InetSocketAddress recipient)
From source file:org.opendaylight.capwap.dtls.DtlsHandlerTransport.java
License:Open Source License
@Override public void send(byte[] buf, int off, int len) throws IOException { log.trace(" send " + len + " bytes"); DatagramPacket packet = new DatagramPacket(Unpooled.copiedBuffer(buf, off, len), remoteAddress); channel.writeAndFlush(new DtlsPacket(packet)); }
From source file:org.opendaylight.capwap.fsm.CapwapDiscoveryServiceActor.java
License:Open Source License
void handleDiscovery(CapwapEvent e) { ODLCapwapMessage m = CapwapMessageCreator.createResponse(e.getdMessage()); //Need to access configuration data base to create discovery response //Need to access operational database to update discovery count ByteBuf buf = Unpooled.buffer();/*from w w w . j av a 2 s .c om*/ int len = m.header.encodeHeader(buf); m.ctrlMsg.encode(buf); //Create a Datagrampacket DatagramPacket packet = new DatagramPacket(buf, e.packet.sender()); e.ctx.writeAndFlush(packet); }
From source file:org.opendaylight.capwap.fsm.CapwapFsmUtils.java
License:Open Source License
public static boolean sendMessage(CapwapEvent e, CapwapContext c, ODLCapwapMessage res) { ByteBuf buf = Unpooled.buffer();/*from w w w .j a va 2 s . c o m*/ DatagramPacket packet = null; res.header.encodeHeader(buf); res.ctrlMsg.encode(buf); c.setLastSendBuf(buf); packet = new DatagramPacket(buf, e.packet.sender()); e.ctx.writeAndFlush(packet); return true; }
From source file:org.opendaylight.lispflowmapping.southbound.LispSouthboundPlugin.java
License:Open Source License
public void handleSerializedLispBuffer(TransportAddress address, ByteBuffer outBuffer, final MessageType packetType) { InetAddress ip = InetAddresses.forString(new String(address.getIpAddress().getValue())); InetSocketAddress recipient = new InetSocketAddress(ip, address.getPort().getValue()); // the wrappedBuffer() method doesn't copy data, so this conversion shouldn't hurt performance ByteBuf data = wrappedBuffer(outBuffer.array()); DatagramPacket packet = new DatagramPacket(data, recipient); LOG.debug("Sending {} on port {} to address: {}", packetType, address.getPort().getValue(), ip); if (LOG.isTraceEnabled()) { LOG.trace("Buffer:\n{}", ByteBufUtil.prettyHexDump(data)); }// w ww . j a v a 2 s. c om channel.write(packet).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { LOG.trace("Success"); statistics.incrementTx(packetType.getIntValue()); } else { LOG.warn("Failed to send packet"); statistics.incrementTxErrors(); } } }); channel.flush(); }
From source file:org.opendaylight.openflowjava.protocol.impl.core.OFDatagramPacketEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, UdpMessageListenerWrapper wrapper, List<Object> out) throws Exception { LOG.trace("Encoding"); try {//w w w. ja va 2 s .c o m ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); serializationFactory.messageToBuffer(wrapper.getMsg().getVersion(), buffer, wrapper.getMsg()); out.add(new DatagramPacket(buffer, wrapper.getAddress())); } catch (Exception e) { LOG.warn("Message serialization failed: {}", e.getMessage()); Future<Void> newFailedFuture = ctx.newFailedFuture(e); wrapper.getListener().operationComplete(newFailedFuture); return; } }
From source file:org.opendaylight.usc.crypto.dtls.DtlsEngine.java
License:Open Source License
public ArrayList<DatagramPacket> read(DatagramPacket msg) throws InterruptedException, ExecutionException, IOException { log.trace("DtlsEngine read " + msg); // add to queue irrespective of whether initialized or not; // this way the protocol handshake can retrieve them rawTransport.enqueue(msg);/*from w w w . j a va 2 s . co m*/ ArrayList<DatagramPacket> packets = new ArrayList<>(); if (encTransport != null) { byte buf[] = new byte[encTransport.getReceiveLimit()]; while (rawTransport.hasPackets()) { int bytesRead = encTransport.receive(buf, 0, buf.length, 100); if (bytesRead > 0) { packets.add(new DatagramPacket(Unpooled.copiedBuffer(buf, 0, bytesRead), rawTransport.getRemoteAddress())); } } } return packets; }
From source file:org.opendaylight.usc.plugin.UscFrameEncoderUdp.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, UscFrame msg, List<Object> out) throws Exception { ByteBuf buf = Unpooled.buffer();// w w w . j a va 2 s .co m buf.writeBytes(msg.getHeader().toByteBuffer()); buf.writeBytes(msg.getPayload()); msg.getPayload().release(); log.trace("Encode to " + ctx.channel().remoteAddress()); DatagramPacket packet = new DatagramPacket(buf, (InetSocketAddress) ctx.channel().remoteAddress()); out.add(packet); }
From source file:org.opendaylight.usc.plugin.UscMultiplexer.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf payload = (ByteBuf) msg;//from w w w.j a v a 2s. c om LOG.trace("UscMultiplexer.channelRead: " + payload); Channel ch = ctx.channel(); Channel outboundChannel = ch.attr(UscPlugin.DIRECT_CHANNEL).get(); if (outboundChannel != null) { if (plugin.getChannelType() == UscChannel.ChannelType.DTLS || plugin.getChannelType() == UscChannel.ChannelType.UDP) { DatagramPacket packet = new DatagramPacket(payload, (InetSocketAddress) outboundChannel.remoteAddress()); LOG.trace("UscMultiplexer.channelRead: convert payload to DatagramPacket " + packet); outboundChannel.write(packet); } else outboundChannel.write(msg); } else { UscSessionImpl session = ch.attr(UscPlugin.SESSION).get().get(); outboundChannel = session.getChannel().getChannel(); UscData reply = null; ByteBuf subPayload = null; int length = payload.readableBytes(); int bytesOut = length; int index = 0; int realLength = 0; while (length > 0) { realLength = (length > MAX_PAYLOAD_SIZE) ? MAX_PAYLOAD_SIZE : length; subPayload = payload.copy(index, realLength); index += realLength; length -= realLength; reply = new UscData(session.getPort(), session.getSessionId(), subPayload); LOG.trace("Send data to Java Agent " + reply); outboundChannel.writeAndFlush(reply); } plugin.sendEvent(new UscSessionTransactionEvent(session, 0, bytesOut)); } }
From source file:org.opendaylight.usc.test.EchoServerUdpHandler.java
License:Open Source License
@Override protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { LOG.trace("channelRead0: " + msg); DatagramPacket reply = new DatagramPacket(msg.content().copy(), msg.sender()); ctx.writeAndFlush(reply);/* w ww .ja v a 2 s . c o m*/ }
From source file:org.restcomm.imscf.common.lwcomm.service.impl.LwCommListenerHandler.java
License:Open Source License
private void sendAckImmediately(LwCommMessage message, boolean positive, ChannelHandlerContext context) { OutgoingMessage ack = positive ? OutgoingMessage.createAck(message) : OutgoingMessage.createNack(message); DatagramPacket ackDp = new DatagramPacket(Unpooled.copiedBuffer(ack.toRawMessage(), CharsetUtil.UTF_8), new InetSocketAddress(message.getFrom().getHost(), message.getFrom().getPort())); context.writeAndFlush(ackDp);/*from w w w . jav a 2 s. co m*/ }