Refine search
/** * Converts an integer and a prefix length into an IPv4 prefix. * * @param address an integer representing the IPv4 address * @param prefixLength the prefix length * @return an IP prefix * @throws IllegalArgumentException if the prefix length value is invalid */ public static IpPrefix valueOf(int address, int prefixLength) { return new IpPrefix(IpAddress.valueOf(address), prefixLength); }
@Override public final void setChannel(Channel channel) { this.channel = channel; final SocketAddress address = channel.getRemoteAddress(); if (address instanceof InetSocketAddress) { final InetSocketAddress inetAddress = (InetSocketAddress) address; final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress()); if (ipAddress.isIp4()) { channelId = ipAddress.toString() + ':' + inetAddress.getPort(); } else { channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort(); } } };
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if ((obj == null) || (!(obj instanceof IpPrefix))) { return false; } IpPrefix other = (IpPrefix) obj; return ((prefixLength == other.prefixLength) && address.equals(other.address)); }
/** * Check if this IP address is a multicast address. * * @return true if this address is a multicast address */ public boolean isMulticast() { return isIp4() ? Ip4Prefix.IPV4_MULTICAST_PREFIX.contains(this.getIp4Address()) : Ip6Prefix.IPV6_MULTICAST_PREFIX.contains(this.getIp6Address()); }
/** * Adds a BGP speaker to the configuration. * * @param speaker the BGP speaker configuration entry */ public void addSpeaker(BgpSpeakerConfig speaker) { // Create the new speaker node and set the parameters ObjectNode speakerNode = JsonNodeFactory.instance.objectNode(); speakerNode.put(NAME, speaker.name().get()); speakerNode.put(VLAN, speaker.vlan().toString()); speakerNode.put(CONNECT_POINT, speaker.connectPoint().elementId().toString() + "/" + speaker.connectPoint().port().toString()); ArrayNode peersNode = speakerNode.putArray(PEERS); for (IpAddress peerAddress: speaker.peers()) { peersNode.add(peerAddress.toString()); } // Add the new BGP speaker to the existing node array ArrayNode speakersArray = bgpSpeakers().isEmpty() ? initBgpSpeakersConfiguration() : (ArrayNode) object.get(SPEAKERS); speakersArray.add(speakerNode); }
@Override public ObjectNode encode(Host host, CodecContext context) { checkNotNull(host, "Host cannot be null"); final JsonCodec<HostLocation> locationCodec = context.codec(HostLocation.class); final ObjectNode result = context.mapper().createObjectNode() .put("id", host.id().toString()) .put("mac", host.mac().toString()) .put("vlan", host.vlan().toString()) .put("innerVlan", host.innerVlan().toString()) .put("outerTpid", host.tpid().toString()) .put("configured", host.configured()); final ArrayNode jsonIpAddresses = result.putArray("ipAddresses"); for (final IpAddress ipAddress : host.ipAddresses()) { jsonIpAddresses.add(ipAddress.toString()); } result.set("ipAddresses", jsonIpAddresses); final ArrayNode jsonLocations = result.putArray("locations"); for (final HostLocation location : host.locations()) { jsonLocations.add(locationCodec.encode(location, context)); } result.set("locations", jsonLocations); return annotate(result, host, context); }
/** * Produces JSON object for a route. * * @param mapper the JSON object mapper to use * @param route the route with the data * @return JSON object for the route */ private ObjectNode json(ObjectMapper mapper, BgpRouteEntry route) { ObjectNode result = mapper.createObjectNode(); result.put("prefix", route.prefix().toString()); result.put("nextHop", route.nextHop().toString()); result.put("bgpId", route.getBgpSession().remoteInfo().bgpId().toString()); result.put("origin", BgpConstants.Update.Origin.typeToString(route.getOrigin())); result.set("asPath", json(mapper, route.getAsPath())); result.put("localPref", route.getLocalPref()); result.put("multiExitDisc", route.getMultiExitDisc()); return result; }
/** * Gets the set of configured local IPv6 prefixes. * * @return IPv6 prefixes */ public Set<LocalIpPrefixEntry> localIp6PrefixEntries() { Set<LocalIpPrefixEntry> prefixes = Sets.newHashSet(); JsonNode prefixesNode = object.get(IP6LOCALPREFIXES); if (prefixesNode == null) { log.warn("ip6LocalPrefixes is null!"); return prefixes; } prefixesNode.forEach(jsonNode -> { prefixes.add(new LocalIpPrefixEntry( IpPrefix.valueOf(jsonNode.get(IPPREFIX).asText()), IpPrefixType.valueOf(jsonNode.get(TYPE).asText()), IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText()))); }); return prefixes; }
/** * Adds peering address to BGP speaker. * * @param speakerName name of BGP speaker * @param peerAddress peering address to be added */ public void addPeerToSpeaker(String speakerName, IpAddress peerAddress) { JsonNode speakersNode = object.get(SPEAKERS); speakersNode.forEach(jsonNode -> { if (jsonNode.hasNonNull(NAME) && jsonNode.get(NAME).asText().equals(speakerName)) { ArrayNode peersNode = (ArrayNode) jsonNode.get(PEERS); for (int i = 0; i < peersNode.size(); i++) { if (peersNode.get(i).asText().equals(peerAddress.toString())) { return; // Peer already exists. } } peersNode.add(peerAddress.toString()); } }); }
@Override public void process(long sid, ObjectNode payload) { String srcId = string(payload, SRCID); ElementId src = elementId(srcId); String dstId = string(payload, DSTID); ElementId dst = elementId(dstId); Device srcDevice = deviceService.getDevice((DeviceId) src); Device dstDevice = deviceService.getDevice((DeviceId) dst); TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress .valueOf(srcDevice.annotations().value("lsrId"))); TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress .valueOf(dstDevice.annotations().value("lsrId"))); Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst); ObjectNode result = objectNode(); ArrayNode arrayNode = arrayNode(); for (Tunnel tunnel : tunnelSet) { if (tunnel.type() == MPLS) { arrayNode.add(tunnel.tunnelId().toString()); } } result.putArray(BUFFER_ARRAY).addAll(arrayNode); sendMessage(PCEWEB_SHOW_TUNNEL, sid, result); } }
@Override public McastRoute decode(ObjectNode json, CodecContext context) { if (json == null || !json.isObject()) { return null; } IpAddress source = IpAddress.valueOf(json.path(SOURCE).asText()); IpAddress group = IpAddress.valueOf(json.path(GROUP).asText()); McastRoute route = new McastRoute(source, group, McastRoute.Type.STATIC); return route; } }
/** * Gets tunnel name. * * @param tunnelType * @param dstIp the remote ip address * @return tunnel name */ private String getTunnelName(String tunnelType, IpAddress dstIp) { return tunnelType + "-" + dstIp.toString(); }
@Override public ControllerNode decode(ObjectNode json, CodecContext context) { checkNotNull(json, "JSON cannot be null"); String ip = json.path("ip").asText(); return new DefaultControllerNode(new NodeId(json.path("id").asText(ip)), IpAddress.valueOf(ip), json.path("tcpPort").asInt(DEFAULT_PORT)); }
pushGlobalNodeLabel(getPcepClient(otherDevId), labelId, IpAddress.valueOf(specificLsrId).getIp4Address().toInt(), PcepLabelOp.REMOVE, false);
if (targetIp.equals(portInfo == null ? null : portInfo.gatewayIP())) { dstMac = GATEWAY_MAC; } else { log.debug("Failed to find MAC address for {}", targetIp.toString()); return; Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), dstMac, ethRequest);
protected Ip4Address getIp(Host host) { return host.ipAddresses().stream().findFirst().get().getIp4Address(); }
/** * The size in bytes of a serialized address. * * @return the number of bytes when serialized */ public int getByteSize() { int size = 4; size += addr.isIp4() ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6; return size; }
/** * Determines whether a given IP address is contained within this prefix. * * @param other the IP address to test * @return true if the IP address is contained in this prefix, otherwise * false */ public boolean contains(IpAddress other) { if (version() != other.version()) { return false; } // // Mask the other address with my prefix length. // If the other prefix is within this prefix, the masked address must // be same as the address of this prefix. // IpAddress maskedAddr = IpAddress.makeMaskedAddress(other, this.prefixLength); return this.address.equals(maskedAddr); }