Search in sources :

Example 21 with IP4Address

use of org.eclipse.kura.net.IP4Address in project kura by eclipse.

the class ConnectionInfoImpl method getIpAddress.

@Override
public IP4Address getIpAddress() {
    IP4Address ipAddress = null;
    String sIpAddress = this.m_props.getProperty("IPADDR");
    if (sIpAddress != null) {
        try {
            ipAddress = (IP4Address) IPAddress.parseHostAddress(sIpAddress);
        } catch (Exception e) {
            s_logger.error("Error parsing IP address!", e);
        }
    }
    return ipAddress;
}
Also used : IP4Address(org.eclipse.kura.net.IP4Address) IOException(java.io.IOException) KuraException(org.eclipse.kura.KuraException)

Example 22 with IP4Address

use of org.eclipse.kura.net.IP4Address in project kura by eclipse.

the class RouteFile method findRoute.

private RouteConfig findRoute(Properties props, int index) {
    RouteConfig route = null;
    IPAddress dest = null;
    IPAddress gw = null;
    IPAddress mask = null;
    if (!props.containsKey("ADDRESS" + index)) {
        return null;
    }
    try {
        dest = IPAddress.parseHostAddress((String) props.get("ADDRESS" + index));
        gw = IPAddress.parseHostAddress((String) props.get("GATEWAY" + index));
        mask = IPAddress.parseHostAddress((String) props.get("NETMASK" + index));
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    if (dest != null && gw != null && mask != null) {
        if (dest instanceof IP4Address) {
            route = new RouteConfigIP4((IP4Address) dest, (IP4Address) gw, (IP4Address) mask, this.interfaceName, -1);
        } else if (dest instanceof IP6Address) {
            route = new RouteConfigIP6((IP6Address) dest, (IP6Address) gw, (IP6Address) mask, this.interfaceName, -1);
        }
    }
    return route;
}
Also used : RouteConfigIP6(org.eclipse.kura.net.route.RouteConfigIP6) UnknownHostException(java.net.UnknownHostException) IP4Address(org.eclipse.kura.net.IP4Address) RouteConfigIP4(org.eclipse.kura.net.route.RouteConfigIP4) IP6Address(org.eclipse.kura.net.IP6Address) RouteConfig(org.eclipse.kura.net.route.RouteConfig) IPAddress(org.eclipse.kura.net.IPAddress)

Example 23 with IP4Address

use of org.eclipse.kura.net.IP4Address in project kura by eclipse.

the class RouteFile method removeRoute.

public boolean removeRoute(IPAddress destination, IPAddress gateway, IPAddress netmask, String iface) {
    RouteConfig route = null;
    if (destination instanceof IP4Address) {
        route = new RouteConfigIP4((IP4Address) destination, (IP4Address) gateway, (IP4Address) netmask, this.interfaceName, -1);
    } else if (destination instanceof IP6Address) {
        route = new RouteConfigIP6((IP6Address) destination, (IP6Address) gateway, (IP6Address) netmask, this.interfaceName, -1);
    }
    int index = routeIndex(route);
    if (index != -1) {
        this.routes.remove(index);
        storeFile();
        return true;
    }
    return false;
}
Also used : RouteConfigIP6(org.eclipse.kura.net.route.RouteConfigIP6) IP4Address(org.eclipse.kura.net.IP4Address) RouteConfigIP4(org.eclipse.kura.net.route.RouteConfigIP4) IP6Address(org.eclipse.kura.net.IP6Address) RouteConfig(org.eclipse.kura.net.route.RouteConfig)

Example 24 with IP4Address

use of org.eclipse.kura.net.IP4Address in project kura by eclipse.

the class RouteFile method addRoute.

public boolean addRoute(IPAddress destination, IPAddress gateway, IPAddress netmask, String ifaceName) {
    RouteConfig route = null;
    if (destination instanceof IP4Address) {
        route = new RouteConfigIP4((IP4Address) destination, (IP4Address) gateway, (IP4Address) netmask, ifaceName, -1);
    } else if (destination instanceof IP6Address) {
        route = new RouteConfigIP6((IP6Address) destination, (IP6Address) gateway, (IP6Address) netmask, ifaceName, -1);
    }
    if (routeIndex(route) != -1) {
        return false;
    }
    this.routes.add(route);
    storeFile();
    return true;
}
Also used : RouteConfigIP6(org.eclipse.kura.net.route.RouteConfigIP6) IP4Address(org.eclipse.kura.net.IP4Address) RouteConfigIP4(org.eclipse.kura.net.route.RouteConfigIP4) IP6Address(org.eclipse.kura.net.IP6Address) RouteConfig(org.eclipse.kura.net.route.RouteConfig)

Example 25 with IP4Address

use of org.eclipse.kura.net.IP4Address in project kura by eclipse.

the class RouteServiceImpl method entryToRoute.

private RouteConfig entryToRoute(String entry) {
    RouteConfig route;
    IPAddress destination;
    IPAddress gateway;
    IPAddress netmask;
    int metric;
    String iface;
    String tmp;
    try {
        route = null;
        StringTokenizer tok = new StringTokenizer(entry, " ");
        tmp = tok.nextToken();
        destination = IPAddress.parseHostAddress(tmp);
        gateway = IPAddress.parseHostAddress(tok.nextToken());
        netmask = IPAddress.parseHostAddress(tok.nextToken());
        tok.nextToken();
        metric = Integer.parseInt(tok.nextToken());
        tok.nextToken();
        tok.nextToken();
        iface = tok.nextToken();
    } catch (Exception e) {
        s_logger.error("Error parsing route table entry:  " + e.getMessage());
        e.printStackTrace();
        return null;
    }
    if (destination instanceof IP4Address) {
        route = new RouteConfigIP4((IP4Address) destination, (IP4Address) gateway, (IP4Address) netmask, iface, metric);
    } else if (destination instanceof IP6Address) {
        route = new RouteConfigIP6((IP6Address) destination, (IP6Address) gateway, (IP6Address) netmask, iface, metric);
    }
    s_logger.trace("Route successfully read from route table entry");
    return route;
}
Also used : RouteConfigIP6(org.eclipse.kura.net.route.RouteConfigIP6) StringTokenizer(java.util.StringTokenizer) IP4Address(org.eclipse.kura.net.IP4Address) RouteConfigIP4(org.eclipse.kura.net.route.RouteConfigIP4) IP6Address(org.eclipse.kura.net.IP6Address) RouteConfig(org.eclipse.kura.net.route.RouteConfig) IPAddress(org.eclipse.kura.net.IPAddress) IOException(java.io.IOException)

Aggregations

IP4Address (org.eclipse.kura.net.IP4Address)33 KuraException (org.eclipse.kura.KuraException)20 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)12 NetConfigIP4 (org.eclipse.kura.net.NetConfigIP4)11 IPAddress (org.eclipse.kura.net.IPAddress)10 NetConfig (org.eclipse.kura.net.NetConfig)10 UnknownHostException (java.net.UnknownHostException)9 NetInterfaceAddressConfig (org.eclipse.kura.net.NetInterfaceAddressConfig)9 IP6Address (org.eclipse.kura.net.IP6Address)8 RouteConfig (org.eclipse.kura.net.route.RouteConfig)7 RouteConfigIP4 (org.eclipse.kura.net.route.RouteConfigIP4)6 RouteConfigIP6 (org.eclipse.kura.net.route.RouteConfigIP6)6 FileNotFoundException (java.io.FileNotFoundException)5 List (java.util.List)5 StringTokenizer (java.util.StringTokenizer)5 DhcpServerConfigIP4 (org.eclipse.kura.net.dhcp.DhcpServerConfigIP4)5 WifiConfig (org.eclipse.kura.net.wifi.WifiConfig)5 BufferedReader (java.io.BufferedReader)4 FileReader (java.io.FileReader)4