private synchronized void generateBackgroundTraffic()
    {

        // get the next inter-arrival time for these junk packets
        long time = gen_.getNextPacketTime();

        // get the sending pattern
        int pattern = gen_.getPattern();

        // for initial start-up, get the list of all resources first
        if (hasStarted_ == false)
        {
            // get list of resource IDs from GIS
            LinkedList resList = GridSim.getGridResourceList();

            // if the list is empty then schedule the next time
            if (resList == null && list_.size() == 0)
            {
                super.sim_schedule(super.get_id(), time, GridSimTags.JUNK_PKT);
                return;
            }

            hasStarted_ = true;
            list_.addAll(resList);  // add resource IDs into the current list

            // sets the sending pattern
            if (pattern == TrafficGenerator.SEND_ONE_ONLY && random_ == null) {
                random_ = new Random();
            }
        }

        // get the required info for generating this background traffic
        long size = gen_.getNextPacketSize();   // packet size
        long freq = gen_.getNextPacketFreq();   // packet freq
        int type = gen_.getServiceType();       // packet type
        int tag = GridSimTags.JUNK_PKT;         // packet tag


        /*********   // DEBUG info
        System.out.println();
        System.out.println(super.get_name() +
                ": START GENERATE BG traffic... at time "+ GridSim.clock());
        System.out.println(super.get_name() +
                ": NEXT background traffic will start at " + time);
        System.out.println(super.get_name() +
                " num PACKETS = " + numPackets + ", freq = " + freq);
        *********/

        int i = 0;
        int destId = -1;

        // send to one of the entity using uniform distribution
        if (pattern == TrafficGenerator.SEND_ONE_ONLY)
        {
            int index = random_.nextInt( list_.size() );
            destId = ((Integer) list_.get(index)).intValue();

            /*********   // DEBUG info
            System.out.println(super.get_name() + ": Destination id = " +
                destId + " = " + GridSim.getEntityName(destId) );
            *********/

            convertIntoPacket(size, 1, tag, destId, type);


        }
        // send to all resources + other entities
        else if (pattern == TrafficGenerator.SEND_ALL)
        {
            // send to all resources and user entities
            for (int k = 0; k < list_.size(); k++)
            {
                destId = ((Integer) list_.get(k)).intValue();

                /*********   // DEBUG info
                System.out.println(super.get_name() + ": Destination id = " +
                    destId + " = " + GridSim.getEntityName(destId) );
                *********/

                convertIntoPacket(size, 1, tag, destId, type);

            }
        }

        // sends the next junk packets
        super.sim_schedule(super.get_id(), time, GridSimTags.JUNK_PKT);
    }