@Override public Ipv4Address parseTlvBody(final ByteBuf value) { return Ipv4Util.addressForByteBuf(value); }
/** * From string ipAddress creates an InetAddress and puts it into ByteBuf. * @param ipAddress Ipv4 address * @return ByteBuf with filled in bytes from ipAddress */ public static ByteBuf byteBufForAddress(final Ipv4Address ipAddress) { return Unpooled.wrappedBuffer(bytesForAddress(ipAddress)); }
@Override public IpPrefix parseTlvBody(final ByteBuf value) { return new IpPrefix(Ipv4Util.prefixForByteBuf(value)); }
/** * Returns number of minimum bytes needed to cover all bits of prefix. * * @param prefix * @return */ public static int getPrefixLengthBytes(final String prefix) { return prefixBitsToBytes(Ipv4Util.getPrefixLength(prefix)); }
private BgpPeerSingletonService(final RIB rib, final Neighbor neighbor, final BGPOpenConfigMappingService mappingService, final WriteConfiguration configurationWriter) { this.neighborAddress = neighbor.getNeighborAddress(); this.bgpPeer = new BGPPeer(Ipv4Util.toStringIP(this.neighborAddress), rib, mappingService.toPeerRole(neighbor), rpcRegistry); final List<BgpParameters> bgpParameters = getBgpParameters(neighbor, rib, mappingService); final KeyMapping key = OpenConfigMappingUtil.getNeighborKey(neighbor); this.prefs = new BGPSessionPreferences(rib.getLocalAs(), getHoldTimer(neighbor), rib.getBgpIdentifier(), getPeerAs(neighbor, rib), bgpParameters, getPassword(key)); this.activeConnection = OpenConfigMappingUtil.isActive(neighbor); this.dispatcher = rib.getDispatcher(); this.inetAddress = Ipv4Util.toInetSocketAddress(this.neighborAddress, OpenConfigMappingUtil.getPort(neighbor)); this.retryTimer = OpenConfigMappingUtil.getRetryTimer(neighbor); this.key = Optional.fromNullable(key); this.configurationWriter = configurationWriter; this.serviceGroupIdentifier = rib.getRibIServiceGroupIdentifier(); LOG.info("Peer Singleton Service {} registered", this.serviceGroupIdentifier); //this need to be always the last step this.registration = rib.registerClusterSingletonService(this); }
/** * Converts IpAddress and PortNumber to InetSocketAddress * * @param ipAddress * @param port * @return InetSocketAddress */ public static InetSocketAddress toInetSocketAddress(final IpAddress ipAddress, final PortNumber port) { final String ipString = toStringIP(ipAddress); return new InetSocketAddress(InetAddresses.forString(ipString), port.getValue()); }
static byte[] prefixedBytes(final byte prefixBits, final byte[] address) { if (prefixBits != 0) { final int prefixBytes = prefixBitsToBytes(Byte.toUnsignedInt(prefixBits)); final byte[] ret = new byte[prefixBytes + 1]; ret[0] = prefixBits; System.arraycopy(address, 0, ret, 1, prefixBytes); return ret; } else { return new byte[] { 0 }; } }
private void connectMonitoredRouters(final BmpDispatcher dispatcher) { if (this.monitoredRouters != null) { for (final MonitoredRouter mr : this.monitoredRouters) { if (mr.getActive()) { Preconditions.checkNotNull(mr.getAddress()); Preconditions.checkNotNull(mr.getPort()); final String s = mr.getAddress().getIpv4Address().getValue(); final InetAddress addr = InetAddresses.forString(s); KeyMapping ret = null; final Rfc2385Key rfc2385KeyPassword = mr.getPassword(); ret = KeyMapping.getKeyMapping(addr, rfc2385KeyPassword.getValue()); dispatcher.createClient( Ipv4Util.toInetSocketAddress(mr.getAddress(), mr.getPort()), this.sessionManager, Optional.<KeyMapping>fromNullable(ret)); } } } }
public static String getNeighborInstanceName(final InstanceIdentifier<?> rootIdentifier) { return Ipv4Util.toStringIP(rootIdentifier.firstKeyOf(Neighbor.class).getNeighborAddress()); }
private static void writeMinimalPrefix(final ByteBuf output, final byte[] bytes, final byte prefixBits) { output.writeByte(prefixBits); output.writeBytes(bytes, 0, Ipv4Util.prefixBitsToBytes(Byte.toUnsignedInt(prefixBits))); }
@Override public java.lang.AutoCloseable createInstance() { try { return BmpMonitoringStationImpl.createBmpMonitorInstance(getExtensionsDependency(), getBmpDispatcherDependency(), getDomDataProviderDependency(), new MonitorId(getIdentifier().getInstanceName()), Ipv4Util.toInetSocketAddress(getBindingAddress(), getBindingPort()), constructKeys(), getCodecTreeFactoryDependency(), getSchemaProvider(), getMonitoredRouter()); } catch(final InterruptedException e) { throw new IllegalStateException("Failed to istantiate BMP application.", e); } }
@Override public Ipv4InterfaceIdentifier parseTlvBody(final ByteBuf value) { return new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value)); }
/** * Writes IPv4 address if not null, otherwise writes zeros to the * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4. * * @param ipv4Address * IPv4 address to be written to the output. * @param output * ByteBuf, where ipv4Address or zeros are written. */ public static void writeIpv4Address(final Ipv4Address ipv4Address, final ByteBuf output) { if (ipv4Address != null) { output.writeBytes(Ipv4Util.bytesForAddress(ipv4Address)); } else { output.writeZero(Ipv4Util.IP4_LENGTH); } }
@Override public FlowspecType parseType(final ByteBuf buffer) { Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); return new SourcePrefixCaseBuilder().setSourcePrefix(Ipv4Util.prefixForByteBuf(buffer)).build(); } }
this.bundleContext, "(" + InstanceType.PEER.getBeanName() + "=" + Ipv4Util.toStringIP(getHost()) + ")"); final BGPPeerRuntimeMXBean peer = peerTracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); final BGPPeerRuntimeRegistration runtimeRegistration = getRootRuntimeBeanRegistratorWrapper().register(peer);
static void writePrefix(final Ipv6Prefix prefix, final ByteBuf output) { final byte[] bytes = Ipv6Util.bytesForPrefix(prefix); final byte prefixBits = bytes[Ipv6Util.IPV6_LENGTH]; output.writeByte(prefixBits); output.writeByte(0); output.writeBytes(bytes, 0, Ipv4Util.prefixBitsToBytes(Byte.toUnsignedInt(prefixBits))); }
@Override public Ipv4InterfaceIdentifier parseTlvBody(final ByteBuf value) { return new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value)); }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final OriginatorId originator = ((Attributes) attribute).getOriginatorId(); if (originator == null) { return; } final ByteBuf originatorIdBuf = Unpooled.buffer(); originatorIdBuf.writeBytes(Ipv4Util.bytesForAddress(originator.getOriginator())); AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, originatorIdBuf, byteAggregator); } }
@Override public FlowspecType parseType(final ByteBuf buffer) { Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); return new DestinationPrefixCaseBuilder().setDestinationPrefix(Ipv4Util.prefixForByteBuf(buffer)).build(); } }
private static IpAddress parseForwardingAddress(final ByteBuf value) { IpAddress fwdAddress = null; switch (value.readableBytes()) { case Ipv4Util.IP4_LENGTH: fwdAddress = new IpAddress(Ipv4Util.addressForByteBuf(value)); break; case Ipv6Util.IPV6_LENGTH: fwdAddress = new IpAddress(Ipv6Util.addressForByteBuf(value)); break; default: LOG.debug("Ignoring unsupported forwarding address length {}", value.readableBytes()); } return fwdAddress; }