Package org.jnode.driver.net

Examples of org.jnode.driver.net.NetworkException


    public void doApply(Device device) throws NetworkException {
        final NetDeviceAPI api;
        try {
            api = device.getAPI(NetDeviceAPI.class);
        } catch (ApiNotFoundException ex) {
            throw new NetworkException("Device is not a network device", ex);
        }

        if (netmask == null) {
            netmask = address.getDefaultSubnetmask();
        }
View Full Code Here


    public void doApply(Device device) throws NetworkException {
        final BOOTPClient bootp = new BOOTPClient();
        try {
            bootp.configureDevice(device);
        } catch (IOException ex) {
            throw new NetworkException(ex);
        }
    }
View Full Code Here

     */
    public static NetworkLayerManager getNLM() throws NetworkException {
        try {
            return InitialNaming.lookup(NetworkLayerManager.NAME);
        } catch (NameNotFoundException ex) {
            throw new NetworkException("Cannot find NetworkLayerManager", ex);
        }
    }
View Full Code Here

        throws NetworkException {
        final NetDeviceAPI api;
        try {
            api = device.getAPI(NetDeviceAPI.class);
        } catch (ApiNotFoundException ex) {
            throw new NetworkException("Device is not a network device", ex);
        }

        if (netmask == null) {
            netmask = address.getDefaultSubnetmask();
        }
View Full Code Here

        // Set the network layer header
        skbuf.setNetworkLayerHeader(hdr);

        // The destination address must have been set, check it
        if (hdr.getDestination() == null) {
            throw new NetworkException("The destination address must have been set");
        }
        stat.opackets.inc();

        // The device we will use to transmit the packet
        final Device dev;
        final NetDeviceAPI api;
        // The hardware address we will be sending to
        final HardwareAddress hwDstAddr;

        // Has the destination device been given?
        if (skbuf.getDevice() == null) {
            // The device has not been send, figure out the route ourselves.

            // First lets try to find a route
            final IPv4Route route;
            route = findRoute(hdr, skbuf);
            route.incUseCount();

            // Get the device
            dev = route.getDevice();
            api = route.getDeviceAPI();

            // Get my source address if not already set
            if (hdr.getSource() == null) {
                hdr.setSource(getSourceAddress(route, hdr, skbuf));
            }

            // Get the hardware address for this device
            hwDstAddr = findDstHWAddress(route, hdr, skbuf);
        } else {
            // The device has been given, use it
            dev = skbuf.getDevice();
            try {
                api = dev.getAPI(NetDeviceAPI.class);
            } catch (ApiNotFoundException ex) {
                throw new NetworkException("Device is not a network device", ex);
            }
            // The source address must have been set, check it
            if (hdr.getSource() == null) {
                throw new NetworkException("The source address must have been set");
            }
            // Find the HW destination address
            hwDstAddr = findDstHWAddress(hdr.getDestination(), dev, hdr, skbuf);
        }

        // Set the datalength (if not set)
        if (hdr.getDataLength() == 0) {
            hdr.setDataLength(skbuf.getSize());
        }

        // Set the identification number, if not set before
        if (hdr.getIdentification() == 0) {
            hdr.setIdentification(getNextID());
        }

        // Should we fragment?
        final int mtu = api.getMTU();

        if (hdr.getTotalLength() <= mtu) {
            // We can send the complete packet
            hdr.setMoreFragments(false);
            hdr.setFragmentOffset(0);
            sendPacket(api, hwDstAddr, hdr, skbuf);
        } else if (hdr.isDontFragment()) {
            // This packet cannot be send of this device
            throw new NetworkException("Packet is too large, mtu=" + mtu);
        } else {
            // Fragment the packet and send the fragments
            fragmentPacket(api, hwDstAddr, hdr, skbuf, mtu);
        }
    }
View Full Code Here

     */
    private IPv4Address getSourceAddress(IPv4Route route, IPv4Header hdr, SocketBuffer skbuf)
        throws NetworkException {
        final Object addrInfo = route.getDeviceAPI().getProtocolAddressInfo(ETH_P_IP);
        if (addrInfo == null) {
            throw new NetworkException("Source IP address not configured for device " +
                    route.getDevice().getId());
        }
        if (!(addrInfo instanceof IPv4ProtocolAddressInfo)) {
            throw new NetworkException("Source IP address not valid class for device " +
                    route.getDevice().getId());
        }
        return (IPv4Address) ((IPv4ProtocolAddressInfo) addrInfo).getDefaultAddress();
    }
View Full Code Here

            dstAddr = hdr.getDestination();
        }
        try {
            return arp.getHardwareAddress(dstAddr, hdr.getSource(), route.getDevice(), arpTimeout);
        } catch (TimeoutException ex) {
            throw new NetworkException("Cannot find hardware address of " + dstAddr, ex);
        }
    }
View Full Code Here

            return null;
        } else {
            try {
                return arp.getHardwareAddress(destination, hdr.getSource(), device, arpTimeout);
            } catch (TimeoutException ex) {
                throw new NetworkException("Cannot find hardware address of " + destination, ex);
            }
        }
    }
View Full Code Here

     * @throws NetworkException
     */
    private void fragmentPacket(NetDeviceAPI api, HardwareAddress dstHwAddr, IPv4Header hdr,
            SocketBuffer skbuf, int mtu) throws NetworkException {
        if ((hdr.getLength() + IP_MIN_FRAG_SIZE) > mtu) {
            throw new NetworkException("MTU is too small for IP, mtu=" + mtu);
        }

        // The complete packet
        final byte[] packet = skbuf.toByteArray();
        int length = packet.length;
View Full Code Here

        if (arp == null) {
            try {
                arp = (ARPNetworkLayer) NetUtils.getNLM().getNetworkLayer(
                                EthernetConstants.ETH_P_ARP);
            } catch (NoSuchProtocolException ex) {
                throw new NetworkException("Cannot find ARP layer", ex);
            }
        }
        return arp;
    }
View Full Code Here

TOP

Related Classes of org.jnode.driver.net.NetworkException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.