0

I am working on simulating a network topology with Java Network Simulator(JNS). I have followed the tutorial which is in documentation of JNS download. Following is the code of the example:

package simulator_;
import java.awt.peer.TextComponentPeer;
import java.io.IOException;

import jns.Simulator;
import jns.element.DuplexInterface;
import jns.element.DuplexLink;
import jns.element.Interface;
import jns.element.Link;
import jns.element.Node;
import jns.trace.Event;
import jns.trace.Trace;
import jns.util.IPAddr;

public class simu {

    public static void main(String[] args) {
        Simulator sim=Simulator.getInstance();

        Node src=new Node("Source node");
        Node router=new Node("Router");
        Node dest=new Node("Destination node");
        sim.attach(src);
        sim.attach(router);
        sim.attach(dest);


        Interface src_iface=new DuplexInterface(new IPAddr(192,168,1,10));
        src.attach(src_iface);
        sim.attach(src_iface);

        Interface dest_iface=new DuplexInterface(new IPAddr(128,116,11,20));
        dest.attach(dest_iface);
        sim.attach(dest_iface);


        Interface route_iface192=new DuplexInterface(new IPAddr(192,168,1,1));
        Interface route_iface128=new DuplexInterface(new IPAddr(128,116,11,1));

        router.attach(route_iface192);
        router.attach(route_iface128);

        sim.attach(route_iface192);
        sim.attach(route_iface128);


        Link link_src_router=new DuplexLink(1000000,0.001);
        Link link_router_dest=new DuplexLink(64000,0.1);

        src_iface.attach(link_src_router,true);
        route_iface192.attach(link_src_router,true);
        sim.attach(link_src_router);

        route_iface128.attach(link_router_dest,true);
        dest_iface.attach(link_router_dest,true);
        sim.attach(link_router_dest);


        src.addDefaultRoute(src_iface);
        dest.addDefaultRoute(dest_iface);

        router.addRoute(new IPAddr(192,168,1,0),new IPAddr(255,255,255,0),
                        route_iface192);
        router.addRoute(new IPAddr(128,116,11,0),new IPAddr(255,255,255,0),
                        route_iface128);

        sim.run();


    }

}

The problem I am facing is when I call sim.run(), the program throws me NullPointerException error. I am a newbie in JNS. Kindly guide if how can I successfully create a file foe javis to Simulate with the help of above code. I am using Eclipse IDE. Thanks in advance.

1
  • Have a look at the stack trace of the NullPointerException. What line of your code appears in the stack trace? Commented Feb 28, 2015 at 20:00

1 Answer 1

1

try setting a trace instance

sim.setTrace(new JavisTrace("output.txt"));

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.