Java Code Examples for org.onlab.packet.IpAddress#toString()

The following examples show how to use org.onlab.packet.IpAddress#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VbngResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Delete a virtual BNG connection.
 *
 * @param privateIp IP Address for the BNG private network
 * @return 200 OK
 */
@DELETE
@Path("{privateip}")
public Response privateIpDeleteNotification(@PathParam("privateip")
        String privateIp) {
    String result;
    if (privateIp == null) {
        log.info("Private IP address to delete is null");
        result = "0";
    }
    log.info("Received a private IP address : {} to delete", privateIp);
    IpAddress privateIpAddress = IpAddress.valueOf(privateIp);

    VbngService vbngService = get(VbngService.class);

    IpAddress assignedPublicIpAddress = null;
    // Delete a virtual BNG
    assignedPublicIpAddress = vbngService.deleteVbng(privateIpAddress);

    if (assignedPublicIpAddress != null) {
        result = assignedPublicIpAddress.toString();
    } else {
        result = "0";
    }
    return Response.ok().entity(result).build();
}
 
Example 2
Source File: K8sIpamManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean releaseIp(String networkId, IpAddress ipAddress) {
    IpAddress releasedIp = allocatedIps(networkId).stream()
            .filter(ip -> ip.equals(ipAddress))
            .findFirst().orElse(null);
    if (releasedIp != null) {
        String ipamId = networkId + "-" + releasedIp.toString();
        k8sIpamStore.removeAllocatedIp(ipamId);
        k8sIpamStore.createAvailableIp(
                new DefaultK8sIpam(ipamId, releasedIp, networkId));

        log.info("Release the IP {}", releasedIp.toString());

        return true;
    } else {
        log.warn("Failed to find requested IP {} for releasing...", ipAddress.toString());
    }

    return false;
}
 
Example 3
Source File: K8sIpamManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public IpAddress allocateIp(String networkId) {
    IpAddress availableIp = availableIps(networkId).stream()
            .findFirst().orElse(null);
    if (availableIp != null) {
        String ipamId = networkId + "-" + availableIp.toString();
        k8sIpamStore.removeAvailableIp(ipamId);
        k8sIpamStore.createAllocatedIp(
                new DefaultK8sIpam(ipamId, availableIp, networkId));

        log.info("Allocate a new IP {}", availableIp.toString());

        return availableIp;
    } else {
        log.warn("No IPs are available for allocating.");
    }
    return null;
}
 
Example 4
Source File: K8sIpamWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Requests for allocating a unique IP address of the given network ID.
 *
 * @param netId     network identifier
 * @return 200 OK with the serialized IPAM JSON string
 * @onos.rsModel K8sIpam
 */
@GET
@Path("{netId}")
@Produces(MediaType.APPLICATION_JSON)
public Response allocateIp(@PathParam("netId") String netId) {
    log.trace("Received IP allocation request of network " + netId);

    K8sNetwork network =
            nullIsNotFound(networkService.network(netId), NETWORK_ID_NOT_FOUND);

    IpAddress ip =
            nullIsNotFound(ipamService.allocateIp(network.networkId()), IP_NOT_ALLOCATED);

    ObjectNode root = mapper().createObjectNode();
    String ipamId = network.networkId() + "-" + ip.toString();
    K8sIpam ipam = new DefaultK8sIpam(ipamId, ip, network.networkId());
    root.set(IPAM, codec(K8sIpam.class).encode(ipam, this));

    return ok(root).build();
}
 
Example 5
Source File: OFChannelHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx)
        throws Exception {

    channel = ctx.channel();
    log.info("New switch connection from {}",
             channel.remoteAddress());

    SocketAddress address = channel.remoteAddress();
    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();
        }
    } else {
        channelId = channel.toString();
    }

    dispatcher = Executors.newSingleThreadExecutor(groupedThreads("onos/of/dispatcher", channelId, log));

    /*
        hack to wait for the switch to tell us what it's
        max version is. This is not spec compliant and should
        be removed as soon as switches behave better.
     */
    //sendHandshakeHelloMessage();
    setState(ChannelState.WAIT_HELLO);
}
 
Example 6
Source File: VbngResource.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new virtual BNG connection.
 *
 * @param privateIp IP Address for the BNG private network
 * @param mac MAC address for the host
 * @param hostName name of the host
 * @return public IP address for the new connection
 */
@POST
@Path("{privateip}/{mac}/{hostname}")
public String privateIpAddNotification(@PathParam("privateip")
        String privateIp, @PathParam("mac") String mac,
        @PathParam("hostname") String hostName) {

    log.info("Received creating vBNG request, "
            + "privateIp= {}, mac={}, hostName= {}",
             privateIp, mac, hostName);

    if (privateIp == null || mac == null || hostName == null) {
        log.info("Parameters can not be null");
        return "0";
    }

    IpAddress privateIpAddress = IpAddress.valueOf(privateIp);
    MacAddress hostMacAddress = MacAddress.valueOf(mac);

    VbngService vbngService = get(VbngService.class);

    IpAddress publicIpAddress = null;
    // Create a virtual BNG
    publicIpAddress = vbngService.createVbng(privateIpAddress,
                                             hostMacAddress,
                                             hostName);

    if (publicIpAddress != null) {
        return publicIpAddress.toString();
    } else {
        return "0";
    }
}
 
Example 7
Source File: K8sIpamManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void reserveIp(String networkId, IpAddress ipAddress) {
    if (!allocatedIps(networkId).contains(ipAddress)) {
        String ipamId = networkId + "-" + ipAddress.toString();
        k8sIpamStore.removeAvailableIp(ipamId);
        k8sIpamStore.createAllocatedIp(
                new DefaultK8sIpam(ipamId, ipAddress, networkId));

        log.info("Reserved the IP {}", ipAddress.toString());
    }
}
 
Example 8
Source File: LispRouterId.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Produces device URI from the given device IpAddress.
 *
 * @param ipAddress device ip address
 * @return device URI
 */
public static URI uri(IpAddress ipAddress) {
    try {
        return new URI(SCHEME, ipAddress.toString(), null);
    } catch (URISyntaxException e) {
        log.warn("Failed to parse the IP address.", e);
        return null;
    }
}
 
Example 9
Source File: BgpPeerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@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();
        }
    }
}
 
Example 10
Source File: BgpId.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Produces device URI from the given DPID long.
 *
 * @param ipAddress device ip address
 * @return device URI
 */
public static URI uri(IpAddress ipAddress) {
    try {
        return new URI(SCHEME, ipAddress.toString(), null);
    } catch (URISyntaxException e) {
        return null;
    }
}
 
Example 11
Source File: PcepClientImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@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();
        }
    }
}
 
Example 12
Source File: PccId.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Produces client URI from the given ip address.
 *
 * @param ipAddress ip of client
 * @return client URI
 */
public static URI uri(IpAddress ipAddress) {
    try {
        return new URI(SCHEME, ipAddress.toString(), null);
    } catch (URISyntaxException e) {
        return null;
    }
}
 
Example 13
Source File: OspfRouterId.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns device URI from the given IP address.
 *
 * @param ipAddress device IP address
 * @return device URI
 */
public static URI uri(IpAddress ipAddress) {
    try {
        return new URI(SCHEME, ipAddress.toString(), null);
    } catch (URISyntaxException e) {
        return null;
    }
}
 
Example 14
Source File: PceWebTopovOverlay.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, String> additionalLinkData(LinkEvent event) {
    Map<String, String> map = new HashMap<>();
    Link link = event.subject();
    long srcPortNo;
    long dstPortNo;
    IpAddress ipDstAddress = null;
    IpAddress ipSrcAddress = null;
    String srcPort;
    String dstPort;
    String bandWidth;

    srcPortNo = link.src().port().toLong();
    if (((srcPortNo & IDENTIFIER_SET) == IDENTIFIER_SET)) {
        srcPort = String.valueOf(srcPortNo);
    } else {
        ipSrcAddress = Ip4Address.valueOf((int) srcPortNo);
        srcPort = ipSrcAddress.toString();
    }

    dstPortNo = link.dst().port().toLong();
    if (((dstPortNo & IDENTIFIER_SET) == IDENTIFIER_SET)) {
        dstPort = String.valueOf(dstPortNo);
    } else {
        ipDstAddress = Ip4Address.valueOf((int) dstPortNo);
        dstPort = ipDstAddress.toString();
    }

    map.put("Src Address", srcPort);
    map.put("Dst Address", dstPort);
    map.put("Te metric", link.annotations().value(TE_METRIC));

    ResourceService resService = AbstractShellCommand.get(ResourceService.class);
    DiscreteResource devResource = Resources.discrete(link.src().deviceId(), link.src().port()).resource();
    if (resService == null) {
        log.warn("resource service does not exist");
        return map;
    }

    if (devResource == null) {
        log.warn("Device resources does not exist");
        return map;
    }
    double regBandwidth = 0;
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        log.error("Exception occurred while getting the bandwidth.");
        Thread.currentThread().interrupt();
    }
    Set<Resource> resources = resService.getRegisteredResources(devResource.id());
    for (Resource res : resources) {
        if (res instanceof ContinuousResource) {
            regBandwidth = ((ContinuousResource) res).value();
            break;
        }
    }

    if (regBandwidth != 0) {
        bandWidth = String.valueOf(regBandwidth);
        map.put("Bandwidth", bandWidth);
    }

    return map;
}
 
Example 15
Source File: OvsdbNodeId.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new node identifier from an IpAddress ipAddress, a long port.
 *
 * @param ipAddress node IP address
 * @param port node port
 */
public OvsdbNodeId(IpAddress ipAddress, long port) {
    // TODO: port is currently not in use, need to remove it later
    super(checkNotNull(ipAddress, "ipAddress is not null").toString());
    this.ipAddress = ipAddress.toString();
}
 
Example 16
Source File: RestClient.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param xosServerIpAddress the IP address of the XOS server
 * @param xosServerPort the port for the REST service on XOS server
 */
RestClient(IpAddress xosServerIpAddress, int xosServerPort) {
    this.url = "http://" + xosServerIpAddress.toString() + ":"
            + xosServerPort + "/xoslib/rs/vbng_mapping/";
}
 
Example 17
Source File: DefaultControllerNode.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance with the specified id and IP address.
 *
 * @param id instance identifier
 * @param ip instance IP address
 */
public DefaultControllerNode(NodeId id, IpAddress ip) {
    this(id, ip != null ? ip.toString() : null, DEFAULT_PORT);
}
 
Example 18
Source File: DefaultControllerNode.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance with the specified id and IP address.
 *
 * @param id instance identifier
 * @param ip instance IP address
 * @param tcpPort TCP port
 */
public DefaultControllerNode(NodeId id, IpAddress ip, int tcpPort) {
    this(id, ip != null ? ip.toString() : null, tcpPort);
}