diff --git a/Random_Mesh_Analyser/Packet.m b/Random_Mesh_Analyser/Packet.m index e41b953..88bee64 100644 --- a/Random_Mesh_Analyser/Packet.m +++ b/Random_Mesh_Analyser/Packet.m @@ -15,6 +15,7 @@ hop_count; wait_times; + delivered = 1; %Reached end node, or lost in blocking? end properties(Dependent=true) @@ -68,8 +69,10 @@ age = current_time - round(obj.birth_time); end - function destroy(obj) - notify(obj, 'deletePacket'); + function destroy(obj, exception) + obj.delivered = ~exception; + notify(obj, 'deletePacket'); + clear obj; end end diff --git a/Random_Mesh_Analyser/Queue.m b/Random_Mesh_Analyser/Queue.m index 282ab9b..67f89d5 100644 --- a/Random_Mesh_Analyser/Queue.m +++ b/Random_Mesh_Analyser/Queue.m @@ -47,6 +47,7 @@ function add( obj, el ) if((obj.nextInsert - obj.nextRemove) == obj.capacity) %Queue is full. Reject! notify(obj, 'Drop'); + el.destroy(1); %Exception is true %error('Queue is full'); return; end diff --git a/Random_Mesh_Analyser/Scheduler.m b/Random_Mesh_Analyser/Scheduler.m index 8fe141c..0084c70 100644 --- a/Random_Mesh_Analyser/Scheduler.m +++ b/Random_Mesh_Analyser/Scheduler.m @@ -6,7 +6,10 @@ servers; free_servers; queue; - free_server_count; + free_server_count; + + num_dropped; + num_admitted; end % properties (Dependent=true) @@ -24,10 +27,12 @@ obj.free_servers = stations; obj.queue = queue; obj.free_server_count = length(obj.free_servers); + end function routeToServer(obj, queue) %current_time = SimScheduler.getScheduler().getTime(); + obj.num_admitted = obj.num_admitted +1; %dequeue from object and assign to a server if(obj.free_server_count > 0) @@ -42,9 +47,15 @@ function routeToServer(obj, queue) end end + function dropPacket(obj, queue) + obj.num_dropped = obj.num_dropped +1; + end + function obj = JoinQueue(self, queue) - obj = addlistener(queue, 'Enqueue',... + obj(1) = addlistener(queue, 'Enqueue',... @(src, ~)self.routeToServer(src)); + obj(2) = addlistener(queue, 'Drop',... + @(src, ~)self.dropPacket(src)); end function runScheduler(obj, station, ~) @@ -67,6 +78,10 @@ function runScheduler(obj, station, ~) obj = addlistener(station, 'serviceDone',... @(src, data)self.runScheduler(src, data)); end + + function p = getBlockingProbability(obj) + p = obj.num_dropped/(obj.num_dropped + obj.num_admitted); + end end end diff --git a/Random_Mesh_Analyser/SimScheduler.m b/Random_Mesh_Analyser/SimScheduler.m index 6af0f0f..a77de2e 100644 --- a/Random_Mesh_Analyser/SimScheduler.m +++ b/Random_Mesh_Analyser/SimScheduler.m @@ -7,6 +7,9 @@ packet_lifetimes; packet_hopcounts; packet_wait_times; + + num_packets_dropped = 0; + num_packets_delivered = 0; end properties (Access = private) @@ -122,7 +125,11 @@ function PacketStatUpdate(obj, packet) round(packet.hop_count)]; obj.packet_wait_times = [obj.packet_wait_times, ... packet.wait_times]; - clear packet; + if(~packet.delivered) + obj.num_packets_dropped = obj.num_packets_dropped +1; + else + obj.num_packets_delivered = obj.num_packets_delivered +1; + end end function hdl = RegisterPacketDestroy(obj, packet) @@ -234,7 +241,34 @@ function visualizeServiceTime(obj, scope, id) end end - + function p = getBlockingProbability(obj, scope, id) + if(strcmp(scope,'local')) + for i=1:length(obj.systems) + if(obj.systems{i}.id == id) + p = obj.systems{i}.getBlockingProbability(); + fprintf('\n[Server %d]: Blocking Probability: %d',... + obj.systems{i}.id, p); + break; + end + end + elseif(strcmp(scope,'network')) + p = obj.num_packets_dropped/(obj.num_packets_dropped + ... + obj.num_packets_delivered); + fprintf('\nNetwork: Blocking Probability: %d', p); + else %Display all. + for i=1:length(obj.systems) + if(obj.systems{i}.id == id) + p = obj.systems{i}.getBlockingProbability(); + fprintf('\n[Server %d]: Blocking Probability: %d',... + obj.systems{i}.id, p); + break; + end + end + p = obj.num_packets_dropped/(obj.num_packets_dropped + ... + obj.num_packets_delivered); + fprintf('\nNetwork: Blocking Probability: %d', p); + end + end end diff --git a/Random_Mesh_Analyser/System.m b/Random_Mesh_Analyser/System.m index 2c4143e..bfae108 100644 --- a/Random_Mesh_Analyser/System.m +++ b/Random_Mesh_Analyser/System.m @@ -6,7 +6,7 @@ stations; scheduler; transmitter; - streams; + streams; end properties (Transient) @@ -35,6 +35,7 @@ %Attach scheduler to queue obj.queue_handle = obj.scheduler.JoinQueue(obj.queue); + %Attach scheduler and transmitter to servers for i=1:length(obj.stations) obj.server_handles{i} = ... @@ -90,6 +91,10 @@ function installAdjacencies(obj, neighbours, drop_policy) utilization(i) = 1 - (obj.stations{i}.idle_period/SimScheduler.getScheduler().getTime()); end end + + function p = getBlockingProbabilities(obj) + p = obj.scheduler.getBlockingProbability(); + end end end diff --git a/Random_Mesh_Analyser/Transmit.m b/Random_Mesh_Analyser/Transmit.m index 2e2c67c..1a7696a 100644 --- a/Random_Mesh_Analyser/Transmit.m +++ b/Random_Mesh_Analyser/Transmit.m @@ -38,14 +38,14 @@ function transmit(obj) %drop packet %fprintf('\n[%d][System %d]:Drop packet.',... % current_time, obj.id); - packet.destroy(); + packet.destroy(0); end else %If we can't drop, then determine if we have neighbours or not. if(isempty(obj.neighbours)) %drop packet %fprintf('\n[%d][System %d]:Drop packet.',... % current_time, obj.id); - packet.destroy(); + packet.destroy(0); else obj.neighbours{egress}.system.enqueue(packet); end diff --git a/Random_Mesh_Analyser/simulateSystem.m b/Random_Mesh_Analyser/simulateSystem.m index 370aa4f..697a34c 100644 --- a/Random_Mesh_Analyser/simulateSystem.m +++ b/Random_Mesh_Analyser/simulateSystem.m @@ -19,7 +19,7 @@ %Install Systems on Grid drop_policy = 'left'; %for no drop in non-edge nodes, or 'random'. -topology.installSystems(0, 2, drop_policy, [3 3]); %capacity(inf), num_servers per system, policy, rates +topology.installSystems(20, 2, drop_policy, [3 3]); %capacity(inf), num_servers per system, policy, rates %Install Adjacencies topology.installAdjacencies(); @@ -63,6 +63,7 @@ scheduler.getUtilization('network',0); +scheduler.getBlockingProbability('network',0); %Cleanup the system. scheduler.destroy(); topology.destroy();