/** * Method for sending packets for testing purpose. * * @param source Name of the source node. This node MUST be in the AS. * @param target Name of the target node. Might not be in the AS. * @param data Data to send in packet. * @return Result if packet was send */ public static void generatePacket( AutonomousSystem as, String source, String target, Serializable data) throws NetworkException { Node tFrom = as.getNodeByName(source); if (tFrom != null) { tFrom.send(target, data); } else { throw new NetworkException(as, "Node '" + source + "' not known."); } }
/** * Sends an amount of messages between randomly selected node. * * <p>TODO Original version selects AS randomly, too. * * @param pAS Autonomous system, in which messages are send randomly * @param pSend Number of randomly send messages. */ public static void generateRandomSend(AutonomousSystem pAS, int pSend) throws NetworkException { for (int i = 1; i <= pSend; i++) { Node nodeFrom = pAS.getRandomNode(); Node nodeTo = pAS.getRandomNode(); if ((nodeFrom != null) && (nodeTo != null)) { String tFrom = nodeFrom.getName(); String tTo = nodeTo.getName(); generatePacket(pAS, tFrom, tTo, "TEST"); } else { i--; // get a random AS with no nodes inside, so it will be choose an other random AS } } /* LinkedList<String> tASList = new LinkedList<String>(); Iterator<String> it = mASs.keySet().iterator(); while(it.hasNext()) { String key = it.next(); tASList.add(key); } for (int i=1;i<=pSend;i++) { AutonomousSystem ASFrom = mASs.get(tASList.get((int) (Math.random()*tASList.size()))); AutonomousSystem ASTo = mASs.get(tASList.get((int) (Math.random()*tASList.size()))); Node nodeFrom = ASFrom.getRandomNode(); Node nodeTo = ASTo.getRandomNode(); if((nodeFrom!=null) && (nodeTo!=null)) { String tFrom = nodeFrom.getName(); String tTo = nodeTo.getName(); Logging.Log(this, tFrom+" -> "+tTo); switchToAS(getASbyNode(tFrom).getName()); generatePacket(tFrom, tTo, "TEST"); } else { i--; //get a random AS with no nodes inside, so it will be choose an other random AS } } */ }