From c35de1b73aaa5ddec6cd3537cf23be2432dfb206 Mon Sep 17 00:00:00 2001 From: TSatyaVasanthReddy Date: Wed, 1 Mar 2017 16:45:07 +0530 Subject: [PATCH 1/2] Added GreedyGeoRouter --- default100 | 147 +++++++++++++++++++ src/core/DTNHost.java | 24 ++++ src/core/Message.java | 28 ++++ src/routing/GreedyGeoRouter.java | 233 +++++++++++++++++++++++++++++++ 4 files changed, 432 insertions(+) create mode 100644 default100 create mode 100644 src/routing/GreedyGeoRouter.java diff --git a/default100 b/default100 new file mode 100644 index 000000000..e84727c73 --- /dev/null +++ b/default100 @@ -0,0 +1,147 @@ + + +Scenario.name = vasanth_Test%%Group.router%% +Scenario.simulateConnections = true +Scenario.updateInterval = 1.0 +Scenario.endTime = 43000 +Scenario.nrofHostGroups = 100 + + + +btInterface.type = SimpleBroadcastInterface +btInterface.transmitSpeed = 250k +btInterface.transmitRange = 10 + +Group.movementModel = StationaryMovement +Group.router = [EpidemicRouter; MyRouter; SprayAndWaitRouter;] +Group.bufferSize = 5M +Group.nrofInterfaces = 1 +Group.interface1 = btInterface +Group.speed = 0.5, 1.5 +Group.msgTtl = 300 +Group.nodeLocation = 0,0 +Group.nrofHosts = 1 +Group.groupID = VAS + +MovementModel.rngSeed = 1 +#MovementModel.worldSize = 1450, 1340 + +Group1.nodeLocation = 10, 10 +Group2.nodeLocation = 20, 20 +Group3.nodeLocation = 30, 30 +Group4.nodeLocation = 40, 40 +Group5.nodeLocation = 50, 50 +Group6.nodeLocation = 60, 60 +Group7.nodeLocation = 70, 70 +Group8.nodeLocation = 80, 80 +Group9.nodeLocation = 90, 90 +Group10.nodeLocation = 100, 100 +Group11.nodeLocation = 110, 110 +Group12.nodeLocation = 120, 120 +Group13.nodeLocation = 130, 130 +Group14.nodeLocation = 140, 140 +Group15.nodeLocation = 150, 150 +Group16.nodeLocation = 160, 160 +Group17.nodeLocation = 170, 170 +Group18.nodeLocation = 180, 180 +Group19.nodeLocation = 190, 190 +Group20.nodeLocation = 200, 200 +Group21.nodeLocation = 210, 210 +Group22.nodeLocation = 220, 220 +Group23.nodeLocation = 230, 230 +Group24.nodeLocation = 240, 240 +Group25.nodeLocation = 250, 250 +Group26.nodeLocation = 260, 260 +Group27.nodeLocation = 270, 270 +Group28.nodeLocation = 280, 280 +Group29.nodeLocation = 290, 290 +Group30.nodeLocation = 300, 300 +Group31.nodeLocation = 310, 310 +Group32.nodeLocation = 320, 320 +Group33.nodeLocation = 330, 330 +Group34.nodeLocation = 340, 340 +Group35.nodeLocation = 350, 350 +Group36.nodeLocation = 360, 360 +Group37.nodeLocation = 370, 370 +Group38.nodeLocation = 380, 380 +Group39.nodeLocation = 390, 390 +Group40.nodeLocation = 400, 400 +Group41.nodeLocation = 410, 410 +Group42.nodeLocation = 420, 420 +Group43.nodeLocation = 430, 430 +Group44.nodeLocation = 440, 440 +Group45.nodeLocation = 450, 450 +Group46.nodeLocation = 460, 460 +Group47.nodeLocation = 470, 470 +Group48.nodeLocation = 480, 480 +Group49.nodeLocation = 490, 490 +Group50.nodeLocation = 500, 500 +Group51.nodeLocation = 510, 510 +Group52.nodeLocation = 520, 520 +Group53.nodeLocation = 530, 530 +Group54.nodeLocation = 540, 540 +Group55.nodeLocation = 550, 550 +Group56.nodeLocation = 560, 560 +Group57.nodeLocation = 570, 570 +Group58.nodeLocation = 580, 580 +Group59.nodeLocation = 590, 590 +Group60.nodeLocation = 600, 600 +Group61.nodeLocation = 610, 610 +Group62.nodeLocation = 620, 620 +Group63.nodeLocation = 630, 630 +Group64.nodeLocation = 640, 640 +Group65.nodeLocation = 650, 650 +Group66.nodeLocation = 660, 660 +Group67.nodeLocation = 670, 670 +Group68.nodeLocation = 680, 680 +Group69.nodeLocation = 690, 690 +Group70.nodeLocation = 700, 700 +Group71.nodeLocation = 710, 710 +Group72.nodeLocation = 720, 720 +Group73.nodeLocation = 730, 730 +Group74.nodeLocation = 740, 740 +Group75.nodeLocation = 750, 750 +Group76.nodeLocation = 760, 760 +Group77.nodeLocation = 770, 770 +Group78.nodeLocation = 780, 780 +Group79.nodeLocation = 790, 790 +Group80.nodeLocation = 800, 800 +Group81.nodeLocation = 810, 810 +Group82.nodeLocation = 820, 820 +Group83.nodeLocation = 830, 830 +Group84.nodeLocation = 840, 840 +Group85.nodeLocation = 850, 850 +Group86.nodeLocation = 860, 860 +Group87.nodeLocation = 870, 870 +Group88.nodeLocation = 880, 880 +Group89.nodeLocation = 890, 890 +Group90.nodeLocation = 900, 900 +Group91.nodeLocation = 910, 910 +Group92.nodeLocation = 920, 920 +Group93.nodeLocation = 930, 930 +Group94.nodeLocation = 940, 940 +Group95.nodeLocation = 950, 950 +Group96.nodeLocation = 960, 960 +Group97.nodeLocation = 970, 970 +Group98.nodeLocation = 980, 980 +Group99.nodeLocation = 990, 990 + +Group100.nrofHosts = 100 +Group100.movementModel = RandomWaypoint +Events.nrof = 1 +Events1.class = MessageEventGenerator +Events1.interval = 5,15 +Events1.size = 500k,1M +Events1.hosts = 0,199 +Events1.prefix = M + + +Report.nrofReports = 1 +Report.reportDir = reports/ +Report.report1 = MessageStatsReport + +SprayAndWaitRouter.nrofCopies = 6 +SprayAndWaitRouter.binaryMode = true + +Optimization.cellSizeMult = 5 +Optimization.randomizeUpdateOrder = true diff --git a/src/core/DTNHost.java b/src/core/DTNHost.java index 258be0450..d471572d6 100644 --- a/src/core/DTNHost.java +++ b/src/core/DTNHost.java @@ -537,5 +537,29 @@ public boolean equals(DTNHost otherHost) { public int compareTo(DTNHost h) { return this.getAddress() - h.getAddress(); } + /** + * @return the angle in degrees[0-360) between the current host and h + * @param h the Host + */ + public double getAngleofHost(DTNHost h){ + double dy = (h.getLocation().getY() - this.getLocation().getY()); + double dx = (h.getLocation().getX() - this.getLocation().getX()); + if(dx == 0){ + if (dy > 0) { + return 90; + } + else{ + return 270; + } + } + else{ + double inDeg = (float)(Math.atan2(dy,dx)*180)/(float)Math.PI; + if( inDeg < 0){ + return 2*180 + inDeg; + } + return inDeg; + } + + } } diff --git a/src/core/Message.java b/src/core/Message.java index d037b890b..c1a7792c7 100644 --- a/src/core/Message.java +++ b/src/core/Message.java @@ -18,6 +18,10 @@ public class Message implements Comparable { public static final int INFINITE_TTL = -1; private DTNHost from; private DTNHost to; + /** Type of the message*/ + private int msgType; + /**No of Local hops*/ + private int localHops; /** Identifier of the message */ private String id; /** Size of the message (bytes) */ @@ -359,5 +363,29 @@ public String getAppID() { public void setAppID(String appID) { this.appID = appID; } + /** + * @return the msgType + */ + public int getMsgType(){ + return this.msgType; + } + /** + * @param mType the msgType to set + */ + public void setMsgType(int mType){ + this.msgType = mType; + } + /** + * @return the localHops + */ + public int getLocalHops(){ + return this.localHops; + } + /** + * @param nh the localhops to set + */ + public void setLocalHops(int nh){ + this.localHops = nh; + } } diff --git a/src/routing/GreedyGeoRouter.java b/src/routing/GreedyGeoRouter.java new file mode 100644 index 000000000..fece70754 --- /dev/null +++ b/src/routing/GreedyGeoRouter.java @@ -0,0 +1,233 @@ +/* +Author : Satya Vasanth Reddy +*/ +package routing; + +import java.lang.Math; +import core.Settings; +import java.lang.*; +import java.util.*; +import core.Application; +import core.Connection; +import core.DTNHost; +import core.Message; +import core.MessageListener; +import core.SettingsError; +import core.SimClock; +import core.SimError; +import java.util.AbstractMap.SimpleEntry; + +public class GreedyGeoRouter extends ActiveRouter { + public static final int PROXIMITY_THRESHOLD = 15; + //This is the collection of DTNHosts in each of the six sectors around the router + private Map> > sectorMap; + + public GreedyGeoRouter(Settings s) { + super(s); + } + + protected GreedyGeoRouter(GreedyGeoRouter r) { + super(r); + this.sectorMap = new HashMap> >(); + } + + @Override + public void update() { + + super.update(); + if (exchangeDeliverableMessages() != null) { + return; // started a transfer, don't try others (yet) + } + //Update the Sector Map + updateSectorMap(); + List messages = + new ArrayList(this.getMessageCollection()); + if(messages.size()>0) + { + startProtocol(messages); + } + } + + + @Override + public GreedyGeoRouter replicate() { + return new GreedyGeoRouter(this); + } + /** + *Returns the Eucledian distance between two hosts + *@param Host1 + *@param Host2 + */ + public double getDistance(DTNHost h1,DTNHost h2){ + double dx = h1.getLocation().getX() - h2.getLocation().getX(); + double dy = h1.getLocation().getY() - h2.getLocation().getY(); + return Math.sqrt(dx*dx + dy*dy); + } + /** + *Returns the sector number of Host2 in clock-wise direction relative to the Host + *@param Host2 + */ + public int getSector(DTNHost h2){ + DTNHost h1 = getHost(); + return (int)(h1.getAngleofHost(h2)/60); + } + + public void updateSectorMap(){ + sectorMap = new HashMap> >(); + DTNHost to; + int sector; + DTNHost h = getHost(); + + for (Connection con : getConnections()) { + + to = con.getOtherNode(getHost()); + sector = getSector(to); + if (!sectorMap.containsKey(sector)){ + sectorMap.put(sector, new HashSet>()); + } + sectorMap.get(sector).add(new AbstractMap.SimpleEntry(to, con)); + } + + } + /** + *Returns the AbstractMap.SimpleEntry of Host and Connection information closer to the destination in a given sector + *@param Destination Host + *@param sector number of the destination relative to current host + *@param The distance between current host and destination + */ + public AbstractMap.SimpleEntry getACloserHostFromSector(DTNHost destination, int sector, int maxD){ + //System.out.println("getACloserHostFromSector: sector "+sector+", destination "+destination.getAddress()); + Collection> sectorList = sectorMap.get(sector); + DTNHost h ; + Connection con ; + if(sectorList==null){ + return null; + } + for(AbstractMap.SimpleEntry entry : sectorList){ + h = entry.getKey(); + con = entry.getValue(); + if(getDistance(h, destination) <= maxD){ + return entry; + } + } + return null; + } + /** + *Returns the AbstractMap.SimpleEntry of Host and Connection information closer to the destination. + *@param Destination Host + */ + + public AbstractMap.SimpleEntry getACloserHost(DTNHost destination){ + int sector = getSector(destination); + int sl,sr; + int maxD = (int)getDistance(getHost(), destination); + AbstractMap.SimpleEntry retVal; + //System.out.println("getACloserHost "+maxD); + for(int i=0;i<3;i++){ + sl = (sector + i)%6; + sr = (sector +6 - i)%6; + retVal = getACloserHostFromSector(destination, sl, maxD); + if(retVal != null){ + return retVal; + } + if(sl != sr){ + retVal = getACloserHostFromSector(destination, sr, maxD); + if(retVal != null){ + return retVal; + } + } + } + return null; + } + /** + *Returns if the destination has a connection with the current host + *@param Destination Host + */ + + public Connection isDestinationConnected(DTNHost d){ + DTNHost n; + //System.out.println("isDestinationConnected "+d.getAddress()); + for (Connection con : getConnections()) { + n = con.getOtherNode(getHost()); + if (d.compareTo(n) == 0){ + //System.out.println("DTNHost is connected"); + return con; + } + } + return null; + } + /** + *Returns if the destination is closer to the current host + *@param Destination Host + */ + public boolean isDestinationClose(DTNHost d){ + if (getDistance(this.getHost(), d) <= PROXIMITY_THRESHOLD){ + //System.out.println("Yes"); + //System.out.println("isDestinationClose ?"+this.getHost().getAddress()+" "+d.getAddress()); + + return true; + } + //System.out.println("No"); + return false; + } + /** + *Broadcasts the message to all its connections + *@param Message to be broadcasted + *@param Message mode + */ + public void localBroadCastMessage(Message m, int mode){ + m.setMsgType(mode); + DTNHost to; + //todo + for (Connection con : getConnections()) { + to = con.getOtherNode(getHost()); + //System.out.println("localBroadcast Message "+m.getId()+" "+m.getTo().getAddress()+" "+m.getFrom().getAddress()+" "+this.getHost().getAddress()+" "+to.getAddress()); + + startTransfer(m,con); + } + return; + } + + /** + *Sends the message to the destination host depending on the type of the message and the mode + *@param Message ID + *@param Destination Host + */ + + @Override + public void sendMessage(String id, DTNHost to) { + Message m = getMessage(id); + Connection con; + if((con=isDestinationConnected(to))!=null){ + startTransfer(m, con); + return; + } + int h; + if(m.getMsgType() == 1){ + h = m.getLocalHops(); + if (h==1){ + return; + } + m.setLocalHops(h-1); + localBroadCastMessage(m, 1); + return; + } + if(isDestinationClose(to)){ + m.setLocalHops(2); + localBroadCastMessage(m, 1); + return; + } + AbstractMap.SimpleEntry tup = getACloserHost(to); + if(tup == null){ + + return; + } + startTransfer(m, tup.getValue()); + } + + public void startProtocol(List messages){ + for(Message m : messages){ + sendMessage(m.getId(),m.getTo()); + } + } +} From 27d3b438ba7e9b8e574a155c0ebaf134256c53a6 Mon Sep 17 00:00:00 2001 From: TSatyaVasanthReddy Date: Wed, 1 Mar 2017 16:49:58 +0530 Subject: [PATCH 2/2] Added GeoGreedy router module --- default100 | 147 ----------------------------------------------------- 1 file changed, 147 deletions(-) delete mode 100644 default100 diff --git a/default100 b/default100 deleted file mode 100644 index e84727c73..000000000 --- a/default100 +++ /dev/null @@ -1,147 +0,0 @@ - - -Scenario.name = vasanth_Test%%Group.router%% -Scenario.simulateConnections = true -Scenario.updateInterval = 1.0 -Scenario.endTime = 43000 -Scenario.nrofHostGroups = 100 - - - -btInterface.type = SimpleBroadcastInterface -btInterface.transmitSpeed = 250k -btInterface.transmitRange = 10 - -Group.movementModel = StationaryMovement -Group.router = [EpidemicRouter; MyRouter; SprayAndWaitRouter;] -Group.bufferSize = 5M -Group.nrofInterfaces = 1 -Group.interface1 = btInterface -Group.speed = 0.5, 1.5 -Group.msgTtl = 300 -Group.nodeLocation = 0,0 -Group.nrofHosts = 1 -Group.groupID = VAS - -MovementModel.rngSeed = 1 -#MovementModel.worldSize = 1450, 1340 - -Group1.nodeLocation = 10, 10 -Group2.nodeLocation = 20, 20 -Group3.nodeLocation = 30, 30 -Group4.nodeLocation = 40, 40 -Group5.nodeLocation = 50, 50 -Group6.nodeLocation = 60, 60 -Group7.nodeLocation = 70, 70 -Group8.nodeLocation = 80, 80 -Group9.nodeLocation = 90, 90 -Group10.nodeLocation = 100, 100 -Group11.nodeLocation = 110, 110 -Group12.nodeLocation = 120, 120 -Group13.nodeLocation = 130, 130 -Group14.nodeLocation = 140, 140 -Group15.nodeLocation = 150, 150 -Group16.nodeLocation = 160, 160 -Group17.nodeLocation = 170, 170 -Group18.nodeLocation = 180, 180 -Group19.nodeLocation = 190, 190 -Group20.nodeLocation = 200, 200 -Group21.nodeLocation = 210, 210 -Group22.nodeLocation = 220, 220 -Group23.nodeLocation = 230, 230 -Group24.nodeLocation = 240, 240 -Group25.nodeLocation = 250, 250 -Group26.nodeLocation = 260, 260 -Group27.nodeLocation = 270, 270 -Group28.nodeLocation = 280, 280 -Group29.nodeLocation = 290, 290 -Group30.nodeLocation = 300, 300 -Group31.nodeLocation = 310, 310 -Group32.nodeLocation = 320, 320 -Group33.nodeLocation = 330, 330 -Group34.nodeLocation = 340, 340 -Group35.nodeLocation = 350, 350 -Group36.nodeLocation = 360, 360 -Group37.nodeLocation = 370, 370 -Group38.nodeLocation = 380, 380 -Group39.nodeLocation = 390, 390 -Group40.nodeLocation = 400, 400 -Group41.nodeLocation = 410, 410 -Group42.nodeLocation = 420, 420 -Group43.nodeLocation = 430, 430 -Group44.nodeLocation = 440, 440 -Group45.nodeLocation = 450, 450 -Group46.nodeLocation = 460, 460 -Group47.nodeLocation = 470, 470 -Group48.nodeLocation = 480, 480 -Group49.nodeLocation = 490, 490 -Group50.nodeLocation = 500, 500 -Group51.nodeLocation = 510, 510 -Group52.nodeLocation = 520, 520 -Group53.nodeLocation = 530, 530 -Group54.nodeLocation = 540, 540 -Group55.nodeLocation = 550, 550 -Group56.nodeLocation = 560, 560 -Group57.nodeLocation = 570, 570 -Group58.nodeLocation = 580, 580 -Group59.nodeLocation = 590, 590 -Group60.nodeLocation = 600, 600 -Group61.nodeLocation = 610, 610 -Group62.nodeLocation = 620, 620 -Group63.nodeLocation = 630, 630 -Group64.nodeLocation = 640, 640 -Group65.nodeLocation = 650, 650 -Group66.nodeLocation = 660, 660 -Group67.nodeLocation = 670, 670 -Group68.nodeLocation = 680, 680 -Group69.nodeLocation = 690, 690 -Group70.nodeLocation = 700, 700 -Group71.nodeLocation = 710, 710 -Group72.nodeLocation = 720, 720 -Group73.nodeLocation = 730, 730 -Group74.nodeLocation = 740, 740 -Group75.nodeLocation = 750, 750 -Group76.nodeLocation = 760, 760 -Group77.nodeLocation = 770, 770 -Group78.nodeLocation = 780, 780 -Group79.nodeLocation = 790, 790 -Group80.nodeLocation = 800, 800 -Group81.nodeLocation = 810, 810 -Group82.nodeLocation = 820, 820 -Group83.nodeLocation = 830, 830 -Group84.nodeLocation = 840, 840 -Group85.nodeLocation = 850, 850 -Group86.nodeLocation = 860, 860 -Group87.nodeLocation = 870, 870 -Group88.nodeLocation = 880, 880 -Group89.nodeLocation = 890, 890 -Group90.nodeLocation = 900, 900 -Group91.nodeLocation = 910, 910 -Group92.nodeLocation = 920, 920 -Group93.nodeLocation = 930, 930 -Group94.nodeLocation = 940, 940 -Group95.nodeLocation = 950, 950 -Group96.nodeLocation = 960, 960 -Group97.nodeLocation = 970, 970 -Group98.nodeLocation = 980, 980 -Group99.nodeLocation = 990, 990 - -Group100.nrofHosts = 100 -Group100.movementModel = RandomWaypoint -Events.nrof = 1 -Events1.class = MessageEventGenerator -Events1.interval = 5,15 -Events1.size = 500k,1M -Events1.hosts = 0,199 -Events1.prefix = M - - -Report.nrofReports = 1 -Report.reportDir = reports/ -Report.report1 = MessageStatsReport - -SprayAndWaitRouter.nrofCopies = 6 -SprayAndWaitRouter.binaryMode = true - -Optimization.cellSizeMult = 5 -Optimization.randomizeUpdateOrder = true