public static void main(String[] args)
    {
        System.out.println("Starting network example ...");

        try
        {
            if (args.length < 1) {
                System.out.println("Usage: java RateExample network.txt");
                return;
            }

            // get the network topology
            String filename = args[0];

            //////////////////////////////////////////
            // First step: Initialize the GridSim package. It should be called
            // before creating any entities. We can't run this example without
            // initializing GridSim first. We will get run-time exception
            // error.
            int num_user = 3;   // number of grid users
            Calendar calendar = Calendar.getInstance();

            // a flag that denotes whether to trace GridSim events or not.
            boolean trace_flag = false;

            // Initialize the GridSim package
            System.out.println("Initializing GridSim package");
            GridSim.init(num_user, calendar, trace_flag);

            //////////////////////////////////////////
            // Second step: Builds the network topology among Routers.

            // use RateControlled packet scheduler. Hence, determine the
            // percentage bandwidth allocation for each Type of Service (ToS).
            // For example, ToS = 0 will get 10%, ToS = 1 will get 35%, etc
            double[] percentage = {10, 35, 55};  // % of total bandwidth
            System.out.println("Reading network from " + filename);
            LinkedList routerList = NetworkReader.createRate(filename, percentage);

            //////////////////////////////////////////
            // Third step: Creates one or more GridResource entities

            double baud_rate = 100000000;  // 100 Mbps
            double propDelay = 10;   // propagation delay in millisecond
            int mtu = 1500;          // max. transmission unit in byte
            int i = 0;

            // link the resources into R5
            Router router = NetworkReader.getRouter("R5", routerList);

            // more resources can be created by
            // setting totalResource to an appropriate value
            int totalResource = 1;
            ArrayList resList = new ArrayList(totalResource);
            for (i = 0; i < totalResource; i++)
            {
                GridResource res = createGridResource("Res_"+i, baud_rate,
                                                      propDelay, mtu);

                // add a resource into a list
                resList.add(res);

                // link a resource to this router object
                linkNetwork(router, res, percentage);
            }

            //////////////////////////////////////////
            // Fourth step: Creates one or more grid user entities

            // number of Gridlets that will be sent to the resource
            int totalGridlet = 5;

            // create users
            ArrayList userList = new ArrayList(num_user);
            ArrayList userNameList = new ArrayList(); // for background traffic
            for (i = 0; i < num_user; i++)
            {
                String name = "User_" + i;

                // if trace_flag is set to "true", then this experiment will
                // create User_i.csv where i = 0 ... (num_user-1)
                NetUser user = new NetUser(name, totalGridlet, baud_rate,
                                           propDelay, mtu, trace_flag);

                // for each user, determines the Type of Service (ToS)
                // for sending objects over the network. The greater ToS is,
                // the more bandwidth allocation
                int ToS = i;
                if (i > percentage.length) {
                    ToS = 0;
                }
                user.setNetServiceLevel(ToS);

                // link a User to a router object
                if (i == 0) {
                    router = NetworkReader.getRouter("R1", routerList);
                }
                else if (i == 1) {
                    router = NetworkReader.getRouter("R2", routerList);
                }
                else {
                    router = NetworkReader.getRouter("R3", routerList);
                }
                linkNetwork(router, user, percentage);

                // add a user into a list
                userList.add(user);
                userNameList.add(name);
            }

            //////////////////////////////////////////
            // Fifth step: Starts the simulation
            GridSim.startGridSimulation();

            //////////////////////////////////////////
            // Final step: Prints the Gridlets when simulation is over

            // also prints the routing table
            router = NetworkReader.getRouter("R3", routerList);
            router.printRoutingTable();
            router = NetworkReader.getRouter("R4", routerList);
            router.printRoutingTable();

            GridletList glList = null;
            for (i = 0; i < userList.size(); i++)
            {
                NetUser obj = (NetUser) userList.get(i);
                glList = obj.getGridletList();
                printGridletList(glList, obj.get_name(), false);
            }

            System.out.println("\nFinish network example ...");
        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.out.println("Unwanted errors happen");
        }
    }