@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { final TcpPortCriterion tcpPortCriterion = (TcpPortCriterion) criterion; root.put(CriterionCodec.TCP_PORT, tcpPortCriterion.tcpPort().toInt()); root.put(CriterionCodec.TCP_MASK, tcpPortCriterion.mask().toInt()); return root; } }
@Override public Criterion decodeCriterion(ObjectNode json) { TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT), CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt()); TpPort udpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_MASK), CriterionCodec.UDP_MASK + MISSING_MEMBER_MESSAGE).asInt()); return Criteria.matchUdpSrcMasked(udpPort, udpMask); } }
/** * Converts an integer into a TpPort. * * @param value an integer representing the transport layer port * @return a TpPort * @throws IllegalArgumentException if the value is invalid */ public static TpPort tpPort(int value) { if (value < MIN_PORT || value > MAX_PORT) { throw new IllegalArgumentException( "Transport layer port value " + value + "is not in the interval [0, 0xFFFF]"); } return new TpPort(value); }
private void connectRetry(IpAddress ip, TpPort port, ChannelFutureListener listener) { try { Bootstrap b = new Bootstrap(); b.group(workerGroup) .channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel channel) throws Exception { ChannelPipeline p = channel.pipeline(); p.addLast(new MessageDecoder(), new StringEncoder(CharsetUtil.UTF_8), new IdleStateHandler(IDLE_TIMEOUT_SEC, 0, 0), new ConnectionHandler()); } }); b.remoteAddress(ip.toString(), port.toInt()); b.connect().addListener(listener); } catch (Exception e) { log.warn("Connection to the ovsdb server {}:{} failed", ip.toString(), port.toString()); } }
@Override public void operationComplete(ChannelFuture channelFuture) throws Exception { if (!channelFuture.isSuccess()) { channelFuture.channel().close(); if (count.incrementAndGet() < MAX_RETRY) { final EventLoop loop = channelFuture.channel().eventLoop(); loop.schedule(() -> { controller.connectRetry(this.ip, this.port, this); }, 1L, TimeUnit.SECONDS); } else { log.info("Connection to the ovsdb {}:{} failed", this.ip.toString(), this.port.toString()); } } else { handleNewNodeConnection(channelFuture.channel()); } } }
@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { final UdpPortCriterion udpPortCriterion = (UdpPortCriterion) criterion; root.put(CriterionCodec.UDP_PORT, udpPortCriterion.udpPort().toInt()); root.put(CriterionCodec.UDP_MASK, udpPortCriterion.mask().toInt()); return root; } }
@Override public Criterion decodeCriterion(ObjectNode json) { TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT), CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt()); TpPort udpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_MASK), CriterionCodec.UDP_MASK + MISSING_MEMBER_MESSAGE).asInt()); return Criteria.matchUdpDstMasked(udpPort, udpMask); } }
@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { final TcpPortCriterion tcpPortCriterion = (TcpPortCriterion) criterion; return root.put(CriterionCodec.TCP_PORT, tcpPortCriterion.tcpPort().toInt()); } }
@Override public Criterion decodeCriterion(ObjectNode json) { TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT), CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt()); TpPort sctpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_MASK), CriterionCodec.SCTP_MASK + MISSING_MEMBER_MESSAGE).asInt()); return Criteria.matchSctpSrcMasked(sctpPort, sctpMask); } }
@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { final SctpPortCriterion sctpPortCriterion = (SctpPortCriterion) criterion; return root.put(CriterionCodec.SCTP_PORT, sctpPortCriterion.sctpPort().toInt()); } }
@Override public Criterion decodeCriterion(ObjectNode json) { TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT), CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt()); TpPort sctpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_MASK), CriterionCodec.SCTP_MASK + MISSING_MEMBER_MESSAGE).asInt()); return Criteria.matchSctpDstMasked(sctpPort, sctpMask); } }
@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { final UdpPortCriterion udpPortCriterion = (UdpPortCriterion) criterion; return root.put(CriterionCodec.UDP_PORT, udpPortCriterion.udpPort().toInt()); } }
@Override public Criterion decodeCriterion(ObjectNode json) { TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT), CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt()); TpPort tcpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_MASK), CriterionCodec.TCP_MASK + MISSING_MEMBER_MESSAGE).asInt()); return Criteria.matchTcpSrcMasked(tcpPort, tcpMask); } }
@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { final SctpPortCriterion sctpPortCriterion = (SctpPortCriterion) criterion; root.put(CriterionCodec.SCTP_PORT, sctpPortCriterion.sctpPort().toInt()); root.put(CriterionCodec.SCTP_MASK, sctpPortCriterion.mask().toInt()); return root; } }
@Override public Criterion decodeCriterion(ObjectNode json) { TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT), CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt()); TpPort tcpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_MASK), CriterionCodec.TCP_MASK + MISSING_MEMBER_MESSAGE).asInt()); return Criteria.matchTcpDstMasked(tcpPort, tcpMask); } }
/** * Encode a L4 modification instruction. * * @param result json node that the instruction attributes are added to */ private void encodeL4(ObjectNode result) { L4ModificationInstruction l4Instruction = (L4ModificationInstruction) instruction; result.put(InstructionCodec.SUBTYPE, l4Instruction.subtype().name()); switch (l4Instruction.subtype()) { case TCP_DST: case TCP_SRC: final L4ModificationInstruction.ModTransportPortInstruction modTcpPortInstruction = (L4ModificationInstruction.ModTransportPortInstruction) l4Instruction; result.put(InstructionCodec.TCP_PORT, modTcpPortInstruction.port().toInt()); break; case UDP_DST: case UDP_SRC: final L4ModificationInstruction.ModTransportPortInstruction modUdpPortInstruction = (L4ModificationInstruction.ModTransportPortInstruction) l4Instruction; result.put(InstructionCodec.UDP_PORT, modUdpPortInstruction.port().toInt()); break; default: log.info("Cannot convert L4 subtype of {}", l4Instruction.subtype()); break; } }
@Override public Criterion decodeCriterion(ObjectNode json) { TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT), CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt()); return Criteria.matchSctpSrc(sctpPort); } }
@Override public void init(Criterion criterion, int bitWidth) throws ByteSequenceTrimException { SctpPortCriterion c = (SctpPortCriterion) criterion; ImmutableByteSequence value = copyFrom(c.sctpPort().toInt()); if (c.mask() == null) { initAsExactMatch(value, bitWidth); } else { ImmutableByteSequence mask = copyFrom(c.mask().toInt()); initAsTernaryMatch(value, mask, bitWidth); } } }
@Override public Criterion decodeCriterion(ObjectNode json) { TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT), CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt()); return Criteria.matchTcpSrc(tcpPort); } }
@Override public void init(Criterion criterion, int bitWidth) throws ByteSequenceTrimException { TcpPortCriterion c = (TcpPortCriterion) criterion; ImmutableByteSequence value = copyFrom(c.tcpPort().toInt()); if (c.mask() == null) { initAsExactMatch(value, bitWidth); } else { ImmutableByteSequence mask = copyFrom(c.mask().toInt()); initAsTernaryMatch(value, mask, bitWidth); } } }