Intermediate node not forwading all received packet during routing - unetstack

I want to send packets from source node 3 to the sink node 1, through intermediate node 2. Accordingly next-hop is configured in simulation script. Data packets are sent from source node 3 for every 2000 ms (2 seconds), for a duration of 2 minutes. Node 3 send 58 packets and all packets successfully received by node 2. But, Node 2 is forwarding only 4 packets to node 1 and we are not able to find packet forwarding entry of remaining packets.
Kindly tell me, why node 2 is not forwarding all received packets and how we can overcome this issue.
For same topology, when node 3 is sending packets for every 10000 ms (10 seconds), all packets are received and forwarded by intermediate node 2. Also all packets are received at sink node 1.
Simulation script:
//! Simulation:
///////////////////////////////////////////////////////////////////////////////
///
/// To run simulation:
/// collision study
///
///////////////////////////////////////////////////////////////////////////////
import org.arl.fjage.*
import org.arl.unet.*
import org.arl.unet.phy.*
import org.arl.unet.sim.*
import org.arl.unet.sim.channels.*
import static org.arl.unet.Services.*
import static org.arl.unet.phy.Physical.*
import org.arl.unet.net.*
import org.arl.unet.DatagramReq
import org.arl.fjage.*
import org.arl.unet.sim.channels.*
channel.model = ProtocolChannelModel;
platform = org.arl.fjage.RealTimePlatform;
channel.soundSpeed = 1500.mps // c
channel.communicationRange = 100.m // Rc
channel.detectionRange = 125.m // Rd
channel.interferenceRange = 150.m // Ri
channel.pDetection = 1 // pd
channel.pDecoding = 1 // pc
modem.dataRate = [600.bps, 7200.bps]
///////////////////////////////////////////////////////////////////////////////
println '''
Node 1, 2, 3
sink: 1
Intermediate node: 2
Source: 3
'''
def packet_interval = 2000
simulate 2.minutes, {
def n1 = node '1', remote: 1101, address: 1, location: [ 0.m, 0.m, 0.m], shell: true, stack:"$home/etc/initrc-stack"
def n2 = node '2', remote: 1102, address: 2, location: [ 0.m, 0.m, -90.m], shell: 5102, stack: "$home/etc/initrc-stack"
n2.startup = {
def router = agentForService Services.ROUTING
router.send new RouteDiscoveryNtf(to: 1, nextHop: 1, reliability: false)
}
def n3 = node '3', remote: 1103, address: 3, location: [0.m, 0.m, -150.m], shell: 5103, stack: "$home/etc/initrc-stack"
n3.startup = {
def router = agentForService Services.ROUTING
router.send new RouteDiscoveryNtf(to: 1, nextHop: 2, reliability: false)
add new TickerBehavior(packet_interval, {
router << new DatagramReq(to: 1, data:[1,2,3,4])
})
}
}
trace.nam:
# BEGIN SIMULATION 1
n -t 1566278862.018000 -s 3 -x 0.000000 -y 0.000000 -Z -150.000000 -a 3
+ -t 1566278862.022000 -s 3 -d 2 -i 1510346961 -p 1 -x {3.0 2.2 -1 ------- null}
n -t 1566278862.025000 -s 1 -x 0.000000 -y 0.000000 -Z 0.000000 -a 1
n -t 1566278862.028000 -s 2 -x 0.000000 -y 0.000000 -Z -90.000000 -a 2
- -t 1566278862.078000 -s 3 -d 2 -i 1510346961 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278862.178000 -s 3 -d 1 -i 1510346961 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278862.313000 -s 3 -d 2 -i 1510346961 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278862.406000 -s 2 -d 1 -i 1469617069 -p 1 -x {2.0 1.2 -1 ------- null}
- -t 1566278862.458000 -s 2 -d 1 -i 1469617069 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1566278862.672000 -s 2 -d 3 -i 1469617069 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1566278862.692000 -s 2 -d 1 -i 1469617069 -p 1 -x {2.0 1.2 -1 ------- null}
+ -t 1566278863.958000 -s 3 -d 2 -i 20584737 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278864.014000 -s 3 -d 2 -i 20584737 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278864.114000 -s 3 -d 1 -i 20584737 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278864.226000 -s 3 -d 2 -i 20584737 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278864.514000 -s 2 -d 1 -i 1477872544 -p 1 -x {2.0 1.2 -1 ------- null}
- -t 1566278864.566000 -s 2 -d 1 -i 1477872544 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1566278864.780000 -s 2 -d 3 -i 1477872544 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1566278864.799000 -s 2 -d 1 -i 1477872544 -p 1 -x {2.0 1.2 -1 ------- null}
+ -t 1566278867.766000 -s 3 -d 2 -i 338049703 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278867.818000 -s 3 -d 2 -i 338049703 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278867.919000 -s 3 -d 1 -i 338049703 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278868.031000 -s 3 -d 2 -i 338049703 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278870.132000 -s 2 -d 1 -i -1449690937 -p 1 -x {2.0 1.2 -1 ------- null}
- -t 1566278870.188000 -s 2 -d 1 -i -1449690937 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1566278870.401000 -s 2 -d 3 -i -1449690937 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1566278870.421000 -s 2 -d 1 -i -1449690937 -p 1 -x {2.0 1.2 -1 ------- null}
+ -t 1566278870.440000 -s 3 -d 2 -i 978676095 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278870.492000 -s 3 -d 2 -i 978676095 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278870.592000 -s 3 -d 1 -i 978676095 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278870.706000 -s 3 -d 2 -i 978676095 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278871.579000 -s 2 -d 1 -i 1601755918 -p 1 -x {2.0 1.2 -1 ------- null}
- -t 1566278871.631000 -s 2 -d 1 -i 1601755918 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1566278871.844000 -s 2 -d 3 -i 1601755918 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1566278871.865000 -s 2 -d 1 -i 1601755918 -p 1 -x {2.0 1.2 -1 ------- null}
+ -t 1566278872.338000 -s 3 -d 2 -i 956833424 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278872.393000 -s 3 -d 2 -i 956833424 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278872.493000 -s 3 -d 1 -i 956833424 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278872.606000 -s 3 -d 2 -i 956833424 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278873.558000 -s 3 -d 2 -i -1963328564 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278873.612000 -s 3 -d 2 -i -1963328564 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278873.713000 -s 3 -d 1 -i -1963328564 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278873.825000 -s 3 -d 2 -i -1963328564 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278876.317000 -s 3 -d 2 -i -1928143299 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278876.370000 -s 3 -d 2 -i -1928143299 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278876.470000 -s 3 -d 1 -i -1928143299 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278876.582000 -s 3 -d 2 -i -1928143299 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278877.936000 -s 3 -d 2 -i -1254987451 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278877.990000 -s 3 -d 2 -i -1254987451 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278878.090000 -s 3 -d 1 -i -1254987451 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278878.202000 -s 3 -d 2 -i -1254987451 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278878.609000 -s 3 -d 2 -i -755199852 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278878.663000 -s 3 -d 2 -i -755199852 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278878.763000 -s 3 -d 1 -i -755199852 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278878.877000 -s 3 -d 2 -i -755199852 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278879.928000 -s 3 -d 2 -i -568886021 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278879.982000 -s 3 -d 2 -i -568886021 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278880.082000 -s 3 -d 1 -i -568886021 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278880.196000 -s 3 -d 2 -i -568886021 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278881.923000 -s 3 -d 2 -i -1240063810 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278881.979000 -s 3 -d 2 -i -1240063810 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278882.078000 -s 3 -d 1 -i -1240063810 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278882.193000 -s 3 -d 2 -i -1240063810 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278883.928000 -s 3 -d 2 -i 1061529248 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278883.981000 -s 3 -d 2 -i 1061529248 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278884.081000 -s 3 -d 1 -i 1061529248 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278884.194000 -s 3 -d 2 -i 1061529248 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278885.921000 -s 3 -d 2 -i 209456711 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278885.973000 -s 3 -d 2 -i 209456711 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278886.073000 -s 3 -d 1 -i 209456711 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278886.186000 -s 3 -d 2 -i 209456711 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278887.922000 -s 3 -d 2 -i 415325080 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278887.974000 -s 3 -d 2 -i 415325080 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278888.074000 -s 3 -d 1 -i 415325080 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278888.187000 -s 3 -d 2 -i 415325080 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278889.921000 -s 3 -d 2 -i -797442469 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278889.976000 -s 3 -d 2 -i -797442469 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278890.076000 -s 3 -d 1 -i -797442469 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278890.188000 -s 3 -d 2 -i -797442469 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278891.922000 -s 3 -d 2 -i -545180830 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278891.975000 -s 3 -d 2 -i -545180830 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278892.074000 -s 3 -d 1 -i -545180830 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278892.188000 -s 3 -d 2 -i -545180830 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278893.921000 -s 3 -d 2 -i 595306029 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278893.975000 -s 3 -d 2 -i 595306029 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278894.074000 -s 3 -d 1 -i 595306029 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278894.187000 -s 3 -d 2 -i 595306029 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278895.924000 -s 3 -d 2 -i -631655884 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278895.978000 -s 3 -d 2 -i -631655884 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278896.079000 -s 3 -d 1 -i -631655884 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278896.191000 -s 3 -d 2 -i -631655884 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278897.922000 -s 3 -d 2 -i -1096585940 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278897.975000 -s 3 -d 2 -i -1096585940 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278898.074000 -s 3 -d 1 -i -1096585940 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278898.187000 -s 3 -d 2 -i -1096585940 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278899.922000 -s 3 -d 2 -i -1197186288 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278899.975000 -s 3 -d 2 -i -1197186288 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278900.074000 -s 3 -d 1 -i -1197186288 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278900.187000 -s 3 -d 2 -i -1197186288 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278901.921000 -s 3 -d 2 -i -1068730569 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278901.976000 -s 3 -d 2 -i -1068730569 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278902.075000 -s 3 -d 1 -i -1068730569 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278902.188000 -s 3 -d 2 -i -1068730569 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278903.920000 -s 3 -d 2 -i 1290028030 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278903.972000 -s 3 -d 2 -i 1290028030 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278904.073000 -s 3 -d 1 -i 1290028030 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278904.185000 -s 3 -d 2 -i 1290028030 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278905.921000 -s 3 -d 2 -i 888921772 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278905.976000 -s 3 -d 2 -i 888921772 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278906.077000 -s 3 -d 1 -i 888921772 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278906.189000 -s 3 -d 2 -i 888921772 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278907.920000 -s 3 -d 2 -i 385846462 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278907.973000 -s 3 -d 2 -i 385846462 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278908.072000 -s 3 -d 1 -i 385846462 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278908.185000 -s 3 -d 2 -i 385846462 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278909.922000 -s 3 -d 2 -i 1344483650 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278909.975000 -s 3 -d 2 -i 1344483650 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278910.074000 -s 3 -d 1 -i 1344483650 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278910.187000 -s 3 -d 2 -i 1344483650 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278911.920000 -s 3 -d 2 -i -1706543636 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278911.973000 -s 3 -d 2 -i -1706543636 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278912.072000 -s 3 -d 1 -i -1706543636 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278912.185000 -s 3 -d 2 -i -1706543636 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278913.921000 -s 3 -d 2 -i 140282931 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278913.974000 -s 3 -d 2 -i 140282931 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278914.075000 -s 3 -d 1 -i 140282931 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278914.187000 -s 3 -d 2 -i 140282931 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278915.923000 -s 3 -d 2 -i -661154220 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278915.977000 -s 3 -d 2 -i -661154220 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278916.076000 -s 3 -d 1 -i -661154220 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278916.190000 -s 3 -d 2 -i -661154220 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278917.920000 -s 3 -d 2 -i 1467831633 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278917.972000 -s 3 -d 2 -i 1467831633 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278918.072000 -s 3 -d 1 -i 1467831633 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278918.185000 -s 3 -d 2 -i 1467831633 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278919.922000 -s 3 -d 2 -i -2138311483 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278919.975000 -s 3 -d 2 -i -2138311483 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278920.074000 -s 3 -d 1 -i -2138311483 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278920.187000 -s 3 -d 2 -i -2138311483 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278921.923000 -s 3 -d 2 -i 89525941 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278921.976000 -s 3 -d 2 -i 89525941 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278922.077000 -s 3 -d 1 -i 89525941 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278922.189000 -s 3 -d 2 -i 89525941 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278923.922000 -s 3 -d 2 -i 2125554706 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278923.977000 -s 3 -d 2 -i 2125554706 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278924.077000 -s 3 -d 1 -i 2125554706 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278924.189000 -s 3 -d 2 -i 2125554706 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278925.923000 -s 3 -d 2 -i 1526828944 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278925.977000 -s 3 -d 2 -i 1526828944 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278926.078000 -s 3 -d 1 -i 1526828944 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278926.190000 -s 3 -d 2 -i 1526828944 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278927.920000 -s 3 -d 2 -i 21936102 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278927.972000 -s 3 -d 2 -i 21936102 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278928.073000 -s 3 -d 1 -i 21936102 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278928.185000 -s 3 -d 2 -i 21936102 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278929.921000 -s 3 -d 2 -i -1978981663 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278929.974000 -s 3 -d 2 -i -1978981663 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278930.073000 -s 3 -d 1 -i -1978981663 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278930.186000 -s 3 -d 2 -i -1978981663 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278931.922000 -s 3 -d 2 -i 1673126869 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278931.976000 -s 3 -d 2 -i 1673126869 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278932.077000 -s 3 -d 1 -i 1673126869 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278932.190000 -s 3 -d 2 -i 1673126869 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278933.922000 -s 3 -d 2 -i 1815795963 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278933.976000 -s 3 -d 2 -i 1815795963 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278934.075000 -s 3 -d 1 -i 1815795963 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278934.188000 -s 3 -d 2 -i 1815795963 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278935.920000 -s 3 -d 2 -i -910914134 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278935.975000 -s 3 -d 2 -i -910914134 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278936.074000 -s 3 -d 1 -i -910914134 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278936.187000 -s 3 -d 2 -i -910914134 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278937.923000 -s 3 -d 2 -i 1993253417 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278937.978000 -s 3 -d 2 -i 1993253417 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278938.078000 -s 3 -d 1 -i 1993253417 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278938.190000 -s 3 -d 2 -i 1993253417 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278939.922000 -s 3 -d 2 -i 1040717625 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278939.976000 -s 3 -d 2 -i 1040717625 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278940.075000 -s 3 -d 1 -i 1040717625 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278940.188000 -s 3 -d 2 -i 1040717625 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278941.923000 -s 3 -d 2 -i 478839984 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278941.977000 -s 3 -d 2 -i 478839984 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278942.076000 -s 3 -d 1 -i 478839984 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278942.190000 -s 3 -d 2 -i 478839984 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278943.923000 -s 3 -d 2 -i -1633779462 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278943.977000 -s 3 -d 2 -i -1633779462 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278944.076000 -s 3 -d 1 -i -1633779462 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278944.188000 -s 3 -d 2 -i -1633779462 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278945.923000 -s 3 -d 2 -i -205695088 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278945.977000 -s 3 -d 2 -i -205695088 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278946.076000 -s 3 -d 1 -i -205695088 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278946.190000 -s 3 -d 2 -i -205695088 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278947.926000 -s 3 -d 2 -i 478510002 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278947.980000 -s 3 -d 2 -i 478510002 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278948.079000 -s 3 -d 1 -i 478510002 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278948.192000 -s 3 -d 2 -i 478510002 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278949.921000 -s 3 -d 2 -i -560218168 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278949.975000 -s 3 -d 2 -i -560218168 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278950.074000 -s 3 -d 1 -i -560218168 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278950.189000 -s 3 -d 2 -i -560218168 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278951.921000 -s 3 -d 2 -i 1812369485 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278951.974000 -s 3 -d 2 -i 1812369485 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278952.073000 -s 3 -d 1 -i 1812369485 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278952.186000 -s 3 -d 2 -i 1812369485 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278953.923000 -s 3 -d 2 -i -1095753763 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278953.977000 -s 3 -d 2 -i -1095753763 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278954.077000 -s 3 -d 1 -i -1095753763 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278954.189000 -s 3 -d 2 -i -1095753763 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278955.922000 -s 3 -d 2 -i -1626355916 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278955.976000 -s 3 -d 2 -i -1626355916 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278956.076000 -s 3 -d 1 -i -1626355916 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278956.189000 -s 3 -d 2 -i -1626355916 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278957.920000 -s 3 -d 2 -i -1209415375 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278957.973000 -s 3 -d 2 -i -1209415375 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278958.072000 -s 3 -d 1 -i -1209415375 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278958.185000 -s 3 -d 2 -i -1209415375 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278959.922000 -s 3 -d 2 -i -850955712 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278959.977000 -s 3 -d 2 -i -850955712 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278960.077000 -s 3 -d 1 -i -850955712 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278960.190000 -s 3 -d 2 -i -850955712 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278961.923000 -s 3 -d 2 -i 1468909939 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278961.977000 -s 3 -d 2 -i 1468909939 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278962.076000 -s 3 -d 1 -i 1468909939 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278962.188000 -s 3 -d 2 -i 1468909939 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278963.921000 -s 3 -d 2 -i -876107173 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278963.975000 -s 3 -d 2 -i -876107173 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278964.075000 -s 3 -d 1 -i -876107173 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278964.187000 -s 3 -d 2 -i -876107173 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278965.923000 -s 3 -d 2 -i -2064973483 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278965.976000 -s 3 -d 2 -i -2064973483 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278966.077000 -s 3 -d 1 -i -2064973483 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278966.189000 -s 3 -d 2 -i -2064973483 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278967.920000 -s 3 -d 2 -i -283570526 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278967.972000 -s 3 -d 2 -i -283570526 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278968.072000 -s 3 -d 1 -i -283570526 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278968.184000 -s 3 -d 2 -i -283570526 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278969.920000 -s 3 -d 2 -i 1841965510 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278969.971000 -s 3 -d 2 -i 1841965510 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278970.073000 -s 3 -d 1 -i 1841965510 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278970.185000 -s 3 -d 2 -i 1841965510 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278971.920000 -s 3 -d 2 -i -108132519 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278971.972000 -s 3 -d 2 -i -108132519 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278972.071000 -s 3 -d 1 -i -108132519 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278972.183000 -s 3 -d 2 -i -108132519 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278973.922000 -s 3 -d 2 -i -1156365847 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278973.975000 -s 3 -d 2 -i -1156365847 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278974.075000 -s 3 -d 1 -i -1156365847 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278974.186000 -s 3 -d 2 -i -1156365847 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278975.920000 -s 3 -d 2 -i -2135535334 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278975.973000 -s 3 -d 2 -i -2135535334 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278976.074000 -s 3 -d 1 -i -2135535334 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278976.186000 -s 3 -d 2 -i -2135535334 -p 1 -x {3.0 2.2 -1 ------- null}
+ -t 1566278977.922000 -s 3 -d 2 -i -945762044 -p 1 -x {3.0 2.2 -1 ------- null}
- -t 1566278977.976000 -s 3 -d 2 -i -945762044 -p 1 -x {3.0 2.2 -1 ------- null}
d -t 1566278978.076000 -s 3 -d 1 -i -945762044 -p 1 -x {3.0 2.2 -1 ------- null} -y NOT_DETECTED
r -t 1566278978.188000 -s 3 -d 2 -i -945762044 -p 1 -x {3.0 2.2 -1 ------- null}
# STATS: q=63, t=63, r=63, d=0, O=0.089, L=0.089, D=0.094, T=0.089
# END SIMULATION 1

You are sending frames from node 3 to node 2 every 2 seconds. Your simulation runs for 2 minutes, and node 3 continually transmits during that period. Node 2 continually receives. Given that the modems are half-duplex, node 2 is mostly busy receiving, and therefore doesn't get much of a chance to transmit. The exact behavior will depend on the MAC and link being used, as the MAC may backoff for a short while if the PHY is busy receiving a frame when it tries to relay the earlier frame. Given that everything works well when you set the delay to 10 seconds, that this seems to be the most likely explanation.
You can try slowing increasing the delay to check. You can also try setting link.mac to none to see if that changes the behavior. When the MAC is not set, node 2 will try to relay each frame as soon as the frame is received, as long as it has enough time before the next frame arrives.

Related

Count the occurrence of a pattern from a column of one file in other file

I created a file with one column with a list of patterns (2,196 in total) that I wanna find in other text file which has approximated 400 millions lines.
For example:
file1
abc1
abc2
abc3
abc4
abc5
file2
abc1
abc1
abc1
abc1
abc1
abc2
abc2
abc2
abc2
The desired output:
file3
abc1 5
abc2 2
I can do one by one with awk or grep:
awk '/abc1/{++c}END{print c}' file1 | wc -l > file3
or
grep 'abc1' file1 | wc -l > file3
However, when I try:
cat file1 | xargs -L 1 grep file2 | wc -l > file3
I get an error message:
grep: abc1: No such file or directory
grep: abc2: No such file or directory
etc
I tried:
cat file1 | xargs -L 1 grep '' file2 | wc -l > file3
Also does not work! So what I am doing wrong?
Thank you!
Your cat file1 | xargs -L 1 grep file2… is trying to grep the pattern file2 from the non-existing file abcX. You could start with something like
<file1 xargs -I{} grep "{}" file2
and extend this to
$ <file1 xargs -I{} sh -c 'printf "%s\t%s\n" "{}" $(grep -c "{}" file2)'
abc1 5
abc2 4
abc3 0
abc4 0
abc5 0
but that's not very efficient for a large pattern file.
Using grep, sort and uniq:
$ grep -F -x -f file1 file2 | sort | uniq -c > file3
Output file3:
5 abc1
4 abc2
If you need to reverse the number of matches and the pattern:
grep -F -x -f file1 file2 | sort | uniq -c | awk '{ print $2"\t"$1 }' > file3
Output file3:
abc1 5
abc2 4
Using awk:
awk '
NR==FNR{ a[$0] }
NR!=FNR && $0 in a{ a[$0]++ }
END{ for (i in a){ if (a[i])print i"\t"a[i] }}
' file1 file2 > file3
Output file3:
abc1 5
abc2 4
Simplest solution would be as follows IMHO.
awk 'FNR==NR{a[$0]++;next} ($1 in a){print $1,a[$1]}' Input_file2 Input_file1
Explanation: Adding explanation for above code.
awk ' ##Starting awk program from here.
FNR==NR{ ##Checking condition if FNR==NR which will be TRUE when Input_file2 is being read.
a[$0]++ ##Creating an array named a index is $0 and increment it with 1 each time it goes to line.
next ##next will skip all further statements from here.
}
($1 in a){ ##Checking condition if $1 is present in array a then do following.
print $1,a[$1] ##Printing first field then value of array a with index $1.
}
' Input_file2 Input_file1 ##Mentioning Input_file names here.
Output will be as follows.
abc1 5
abc2 4

Tracing packets from source to destination for multi-hop communication using trace.nam in unetstack

We implemented multi-hop routing protocol for underwater communication. Now we want to evaluate the performance of that routing protocol using parameters like- end to end delay, hop-count etc. We analyzed trace.nam to trace the packets from source to destination. Once a packet is originated from source, forwarded to next hop like that it will reach destination after multiple forwarding. But the problem is packet id at each forwarding node is changes. Due to this difficult to trace the packet and collect statistics (suppose 100 packet sent).
Not finding common parameter value in trace file to trace packets.
# BEGIN SIMULATION 1
n -t 1559191523.506000 -s 1 -x 0.000000 -y 0.000000 -Z 0.000000 -a 1
+ -t 1559191523.510000 -s 1 -d 0 -i 250111054 -p 0 -x {1.0 0.4 -1 ------- null}
n -t 1559191523.511000 -s 2 -x 0.000000 -y 0.000000 -Z -35.000000 -a 2
n -t 1559191523.513000 -s 3 -x 0.000000 -y 0.000000 -Z -75.000000 -a 3
n -t 1559191523.514000 -s 5 -x 0.000000 -y 99.000000 -Z -118.000000 -a 5
n -t 1559191523.514000 -s 4 -x 0.000000 -y 0.000000 -Z -120.000000 -a 4
- -t 1559191523.564000 -s 1 -d 0 -i 250111054 -p 0 -x {1.0 0.4 -1 ------- null}
r -t 1559191523.958000 -s 1 -d 2 -i 250111054 -p 0 -x {1.0 0.4 -1 ------- null}
r -t 1559191523.969000 -s 1 -d 3 -i 250111054 -p 0 -x {1.0 0.4 -1 ------- null}
d -t 1559191524.005000 -s 1 -d 4 -i 250111054 -p 0 -x {1.0 0.4 -1 ------- null} -y BAD_FRAME
d -t 1559191524.021000 -s 1 -d 5 -i 250111054 -p 0 -x {1.0 0.4 -1 ------- null} -y BAD_FRAME
+ -t 1559191550.251000 -s 2 -d 0 -i 270543411 -p 0 -x {2.0 0.4 -1 ------- null}
- -t 1559191550.302000 -s 2 -d 0 -i 270543411 -p 0 -x {2.0 0.4 -1 ------- null}
r -t 1559191550.678000 -s 2 -d 1 -i 270543411 -p 0 -x {2.0 0.4 -1 ------- null}
r -t 1559191550.683000 -s 2 -d 3 -i 270543411 -p 0 -x {2.0 0.4 -1 ------- null}
r -t 1559191550.713000 -s 2 -d 4 -i 270543411 -p 0 -x {2.0 0.4 -1 ------- null}
d -t 1559191550.742000 -s 2 -d 5 -i 270543411 -p 0 -x {2.0 0.4 -1 ------- null} -y BAD_FRAME
+ -t 1559191551.741000 -s 3 -d 0 -i 236268410 -p 0 -x {3.0 0.4 -1 ------- null}
- -t 1559191551.792000 -s 3 -d 0 -i 236268410 -p 0 -x {3.0 0.4 -1 ------- null}
r -t 1559191552.174000 -s 3 -d 2 -i 236268410 -p 0 -x {3.0 0.4 -1 ------- null}
r -t 1559191552.178000 -s 3 -d 4 -i 236268410 -p 0 -x {3.0 0.4 -1 ------- null}
r -t 1559191552.196000 -s 3 -d 1 -i 236268410 -p 0 -x {3.0 0.4 -1 ------- null}
d -t 1559191552.220000 -s 3 -d 5 -i 236268410 -p 0 -x {3.0 0.4 -1 ------- null} -y BAD_FRAME
+ -t 1559191586.676000 -s 4 -d 0 -i -694431325 -p 0 -x {4.0 0.4 -1 ------- null}
- -t 1559191586.728000 -s 4 -d 0 -i -694431325 -p 0 -x {4.0 0.4 -1 ------- null}
r -t 1559191587.112000 -s 4 -d 3 -i -694431325 -p 0 -x {4.0 0.4 -1 ------- null}
r -t 1559191587.139000 -s 4 -d 2 -i -694431325 -p 0 -x {4.0 0.4 -1 ------- null}
r -t 1559191587.149000 -s 4 -d 5 -i -694431325 -p 0 -x {4.0 0.4 -1 ------- null}
d -t 1559191587.161000 -s 4 -d 1 -i -694431325 -p 0 -x {4.0 0.4 -1 ------- null} -y BAD_FRAME
+ -t 1559191626.953000 -s 5 -d 0 -i -1642203870 -p 0 -x {5.0 0.4 -1 ------- null}
- -t 1559191627.005000 -s 5 -d 0 -i -1642203870 -p 0 -x {5.0 0.4 -1 ------- null}
r -t 1559191627.425000 -s 5 -d 4 -i -1642203870 -p 0 -x {5.0 0.4 -1 ------- null}
d -t 1559191627.430000 -s 5 -d 3 -i -1642203870 -p 0 -x {5.0 0.4 -1 ------- null} -y BAD_FRAME
d -t 1559191627.446000 -s 5 -d 2 -i -1642203870 -p 0 -x {5.0 0.4 -1 ------- null} -y BAD_FRAME
d -t 1559191627.462000 -s 5 -d 1 -i -1642203870 -p 0 -x {5.0 0.4 -1 ------- null} -y BAD_FRAME
+ -t 1559191741.605000 -s 5 -d 4 -i -1230929328 -p 1 -x {5.0 4.2 -1 ------- null}
- -t 1559191741.655000 -s 5 -d 4 -i -1230929328 -p 1 -x {5.0 4.2 -1 ------- null}
r -t 1559191742.268000 -s 5 -d 4 -i -1230929328 -p 1 -x {5.0 4.2 -1 ------- null}
d -t 1559191742.274000 -s 5 -d 3 -i -1230929328 -p 1 -x {5.0 4.2 -1 ------- null} -y BAD_FRAME
d -t 1559191742.287000 -s 5 -d 2 -i -1230929328 -p 1 -x {5.0 4.2 -1 ------- null} -y BAD_FRAME
+ -t 1559191742.300000 -s 4 -d 5 -i -2045618010 -p 0 -x {4.0 5.2 -1 ------- null}
d -t 1559191742.306000 -s 5 -d 1 -i -1230929328 -p 1 -x {5.0 4.2 -1 ------- null} -y BAD_FRAME
+ -t 1559191742.316000 -s 4 -d 2 -i -1660400851 -p 1 -x {4.0 2.2 -1 ------- null}
- -t 1559191742.351000 -s 4 -d 5 -i -2045618010 -p 0 -x {4.0 5.2 -1 ------- null}
r -t 1559191742.736000 -s 4 -d 3 -i -2045618010 -p 0 -x {4.0 5.2 -1 ------- null}
- -t 1559191742.756000 -s 4 -d 2 -i -1660400851 -p 1 -x {4.0 2.2 -1 ------- null}
r -t 1559191742.762000 -s 4 -d 2 -i -2045618010 -p 0 -x {4.0 5.2 -1 ------- null}
r -t 1559191742.772000 -s 4 -d 5 -i -2045618010 -p 0 -x {4.0 5.2 -1 ------- null}
d -t 1559191742.786000 -s 4 -d 1 -i -2045618010 -p 0 -x {4.0 5.2 -1 ------- null} -y BAD_FRAME
r -t 1559191743.330000 -s 4 -d 3 -i -1660400851 -p 1 -x {4.0 2.2 -1 ------- null}
r -t 1559191743.357000 -s 4 -d 2 -i -1660400851 -p 1 -x {4.0 2.2 -1 ------- null}
+ -t 1559191743.358000 -s 2 -d 4 -i 1941993078 -p 0 -x {2.0 4.2 -1 ------- null}
+ -t 1559191743.362000 -s 2 -d 1 -i 1563463759 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1559191743.365000 -s 4 -d 5 -i -1660400851 -p 1 -x {4.0 2.2 -1 ------- null}
d -t 1559191743.380000 -s 4 -d 1 -i -1660400851 -p 1 -x {4.0 2.2 -1 ------- null} -y BAD_FRAME
- -t 1559191743.410000 -s 2 -d 4 -i 1941993078 -p 0 -x {2.0 4.2 -1 ------- null}
r -t 1559191743.787000 -s 2 -d 1 -i 1941993078 -p 0 -x {2.0 4.2 -1 ------- null}
r -t 1559191743.791000 -s 2 -d 3 -i 1941993078 -p 0 -x {2.0 4.2 -1 ------- null}
- -t 1559191743.813000 -s 2 -d 1 -i 1563463759 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1559191743.821000 -s 2 -d 4 -i 1941993078 -p 0 -x {2.0 4.2 -1 ------- null}
d -t 1559191743.849000 -s 2 -d 5 -i 1941993078 -p 0 -x {2.0 4.2 -1 ------- null} -y BAD_FRAME
r -t 1559191744.383000 -s 2 -d 1 -i 1563463759 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1559191744.387000 -s 2 -d 3 -i 1563463759 -p 1 -x {2.0 1.2 -1 ------- null}
+ -t 1559191744.388000 -s 1 -d 2 -i 1520738108 -p 0 -x {1.0 2.2 -1 ------- null}
r -t 1559191744.416000 -s 2 -d 4 -i 1563463759 -p 1 -x {2.0 1.2 -1 ------- null}
- -t 1559191744.440000 -s 1 -d 2 -i 1520738108 -p 0 -x {1.0 2.2 -1 ------- null}
d -t 1559191744.446000 -s 2 -d 5 -i 1563463759 -p 1 -x {2.0 1.2 -1 ------- null} -y BAD_FRAME
r -t 1559191744.817000 -s 1 -d 2 -i 1520738108 -p 0 -x {1.0 2.2 -1 ------- null}
r -t 1559191744.843000 -s 1 -d 3 -i 1520738108 -p 0 -x {1.0 2.2 -1 ------- null}
d -t 1559191744.874000 -s 1 -d 4 -i 1520738108 -p 0 -x {1.0 2.2 -1 ------- null} -y BAD_FRAME
d -t 1559191744.897000 -s 1 -d 5 -i 1520738108 -p 0 -x {1.0 2.2 -1 ------- null} -y BAD_FRAME
+ -t 1559191798.872000 -s 4 -d 2 -i 706565595 -p 1 -x {4.0 2.2 -1 ------- null}
- -t 1559191798.925000 -s 4 -d 2 -i 706565595 -p 1 -x {4.0 2.2 -1 ------- null}
r -t 1559191799.500000 -s 4 -d 3 -i 706565595 -p 1 -x {4.0 2.2 -1 ------- null}
r -t 1559191799.527000 -s 4 -d 2 -i 706565595 -p 1 -x {4.0 2.2 -1 ------- null}
+ -t 1559191799.530000 -s 2 -d 4 -i -476134347 -p 0 -x {2.0 4.2 -1 ------- null}
r -t 1559191799.535000 -s 4 -d 5 -i 706565595 -p 1 -x {4.0 2.2 -1 ------- null}
+ -t 1559191799.536000 -s 2 -d 1 -i -70258 -p 1 -x {2.0 1.2 -1 ------- null}
d -t 1559191799.548000 -s 4 -d 1 -i 706565595 -p 1 -x {4.0 2.2 -1 ------- null} -y BAD_FRAME
- -t 1559191799.582000 -s 2 -d 4 -i -476134347 -p 0 -x {2.0 4.2 -1 ------- null}
r -t 1559191799.958000 -s 2 -d 1 -i -476134347 -p 0 -x {2.0 4.2 -1 ------- null}
r -t 1559191799.961000 -s 2 -d 3 -i -476134347 -p 0 -x {2.0 4.2 -1 ------- null}
- -t 1559191799.985000 -s 2 -d 1 -i -70258 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1559191799.992000 -s 2 -d 4 -i -476134347 -p 0 -x {2.0 4.2 -1 ------- null}
d -t 1559191800.020000 -s 2 -d 5 -i -476134347 -p 0 -x {2.0 4.2 -1 ------- null} -y BAD_FRAME
r -t 1559191800.552000 -s 2 -d 1 -i -70258 -p 1 -x {2.0 1.2 -1 ------- null}
+ -t 1559191800.554000 -s 1 -d 2 -i -924478001 -p 0 -x {1.0 2.2 -1 ------- null}
r -t 1559191800.555000 -s 2 -d 3 -i -70258 -p 1 -x {2.0 1.2 -1 ------- null}
r -t 1559191800.588000 -s 2 -d 4 -i -70258 -p 1 -x {2.0 1.2 -1 ------- null}
- -t 1559191800.605000 -s 1 -d 2 -i -924478001 -p 0 -x {1.0 2.2 -1 ------- null}
d -t 1559191800.615000 -s 2 -d 5 -i -70258 -p 1 -x {2.0 1.2 -1 ------- null} -y BAD_FRAME
r -t 1559191800.982000 -s 1 -d 2 -i -924478001 -p 0 -x {1.0 2.2 -1 ------- null}
r -t 1559191801.009000 -s 1 -d 3 -i -924478001 -p 0 -x {1.0 2.2 -1 ------- null}
d -t 1559191801.041000 -s 1 -d 4 -i -924478001 -p 0 -x {1.0 2.2 -1 ------- null} -y BAD_FRAME
d -t 1559191801.063000 -s 1 -d 5 -i -924478001 -p 0 -x {1.0 2.2 -1 ------- null} -y BAD_FRAME
In the above trace.nam from line no. 1-36 beacons to set-up routing table.
Traces from line no. 39-98 indicating data packet forwarding originated at node 4 and 5.
The trace.nam file in UnetSim currently only logs PHY frames. If you are analyzing higher layer protocols, this may not be the ideal log file to work from. It is perhaps better that you log your packets to log-0.txt in your agent using log.info() and use that for your analysis instead.

addition of two array elements and put it in third array in bash

I am not getting any convenient code for :
I want to add three arrays into new one and add this new array value to a new column of a csv. My code so far:
sar -f -r > test.txt
sed -i 's/AM/ /g;s/PM/ /g' test.txt
IFS=$'\n'
arr1=($(cat test.txt | awk '{print $2}'| tail -n +3 | egrep -v 'kb'))
unset IFS
echo -e "${arr1[#]/%/$'\n'}"
sar -f -r > test1.txt
sed -i 's/AM/ /g;s/PM/ /g' test1.txt
IFS=$'\n'
arr2=($(cat test1.txt | awk '{print $5}'| tail -n +3 | egrep -v 'kb'))
unset IFS
echo -e "${arr2[#]/%/$'\n'}"
sar -f -r > test2.txt
sed -i 's/AM/ /g;s/PM/ /g' test2.txt
IFS=$'\n'
arr3=($(cat test2.txt | awk '{print $6}'| tail -n +3 | egrep -v 'kb'))
unset IFS
echo -e "${arr3[#]/%/$'\n'}"

bash scripting , loop not looping

I wrote a while loop to search inside files and append the output to a text file , but it seems like it's reading only the first line of that text file . How do I fix it ?
while read line
do
x=`echo $line`
y=`grep $x: /etc/group | cut -d ":" -f 3`
grep $y /etc/passwd | cut -d ":" -f 1 >> users
grep $y /etc/group | cut -d ":" -f 4 | tr "," "\n" >> users
done < filename
Perhaps you need to wrap $x and $y in quotes, as otherwise grep may interpret anything after the first space as the name of the file to be searched:
#!/bin/bash
while read line
do
x=`echo $line`
y=`grep "$x:" /etc/group | cut -d ":" -f 3`
grep "$y" /etc/passwd | cut -d ":" -f 1 >> users
grep "$y" /etc/group | cut -d ":" -f 4 | tr "," "\n" >> users
done < filename
This might be a bit safer as some of the grep statements may pick up the wrong fields (i.e. it does not check for the correct field):
while read GROUP
do
GROUP_ID=`grep ^$GROUP: /etc/group | cut -d ":" -f 3`
USER_ENT=`grep -e '\(.*:\)\{3\}'$GROUP_ID':' /etc/passwd`
[ $? -eq 0 ] && cut -d ":" -f 1 <<<$USER_ENT
GROUP_ENT=`grep -e '\(.*:\)\{2\}'$GROUP_ID':' /etc/group`
[ $? -eq 0 ] && cut -d ":" -f 4 <<<$GROUP_ENT | tr "," "\n" | grep -v ^$
done < $FILE_NAME | sort | uniq >users

Define array for walking directories with du

I wrote a basic script to test a recursive du output against a directory or filesystem that selects the largest directory and repeats, then outputs the results neatly. Is there a way I can combine an array and some if/then statements to make this more elegant and continue to recurse until no more directories are matched, then printing the outputs from an array?
#!/bin/bash
dir1=$1
du1=$(du -x --max-depth=1 $dir1 | sort -nr | awk '{ print $2 }' | \
xargs du -hx --max-depth=0 | egrep -v "sys|proc|boot|lost|media|mnt|selinux" | head -10 | tail -n +2)
dir2=$(echo "$du1"|head -1|awk '{print $2}')
du2=$(du -x --max-depth=1 $dir2 | sort -nr | awk '{ print $2 }' | \
xargs du -hx --max-depth=0 | egrep -v "sys|proc|boot|lost|media|mnt|selinux" | head -10 | tail -n +2)
dir3=$(echo "$du2"|head -1|awk '{print $2}')
du3=$(du -x --max-depth=1 $dir3 | sort -nr | awk '{ print $2 }' | \
xargs du -hx --max-depth=0 | egrep -v "sys|proc|boot|lost|media|mnt|selinux" | head -10 | tail -n +2)
dir4=$(echo "$du3"|head -1|awk '{print $2}')
du4=$(du -x --max-depth=1 $dir4 | sort -nr | awk '{ print $2 }' | \
xargs du -hx --max-depth=0 | egrep -v "sys|proc|boot|lost|media|mnt|selinux" | head -10 | tail -n +2)
dir5=$(echo "$du4"|head -1|awk '{print $2}')
du5=$(du -x --max-depth=1 $dir5 | sort -nr | awk '{ print $2 }' | \
xargs du -hx --max-depth=0 | egrep -v "sys|proc|boot|lost|media|mnt|selinux" | head -10 | tail -n +2)
dir6=$(echo "$du5"|head -1|awk '{print $2}')
du6=$(du -x --max-depth=1 $dir6 | sort -nr | awk '{ print $2 }' | \
xargs du -hx --max-depth=0 | egrep -v "sys|proc|boot|lost|media|mnt|selinux" | head -10 | tail -n +2)
echo -e "##LEVEL1##"
paste -d ' ' <(echo "$du1") <(echo "$(file $(echo "$du1" | \
awk '{print $2}')|cut -d' ' -f2- | sed -e 's/[a-zA-Z0-9]/[&/' -e 's/$/]/')")
echo -e "##LEVEL2##"
paste -d ' ' <(echo "$du2") <(echo "$(file $(echo "$du2" | \
awk '{print $2}')|cut -d' ' -f2- | sed -e 's/[a-zA-Z0-9]/[&/' -e 's/$/]/')")
echo -e "##LEVEL3##"
paste -d ' ' <(echo "$du3") <(echo "$(file $(echo "$du3" | \
awk '{print $2}')|cut -d' ' -f2- | sed -e 's/[a-zA-Z0-9]/[&/' -e 's/$/]/')")
echo -e "##LEVEL4##"
paste -d ' ' <(echo "$du4") <(echo "$(file $(echo "$du4" | \
awk '{print $2}')|cut -d' ' -f2- | sed -e 's/[a-zA-Z0-9]/[&/' -e 's/$/]/')")
echo -e "##LEVEL5##"
paste -d ' ' <(echo "$du5") <(echo "$(file $(echo "$du5" | \
awk '{print $2}')|cut -d' ' -f2- | sed -e 's/[a-zA-Z0-9]/[&/' -e 's/$/]/')")
echo -e "##LEVEL6##"
paste -d ' ' <(echo "$du6") <(echo "$(file $(echo "$du6" | \
awk '{print $2}')|cut -d' ' -f2- | sed -e 's/[a-zA-Z0-9]/[&/' -e 's/$/]/')")
Here is an example output:
#./rdu.sh / 2>/dev/null
##LEVEL1##
12G /opt [directory]
1.9G /usr [directory]
452M /var [directory]
352M /root [directory]
179M /home [directory]
116M /lib [directory]
46M /tmp [sticky directory]
28M /sbin [directory]
21M /etc [directory]
##LEVEL2##
8.5G /opt/zenoss [directory]
2.9G /opt/zends [directory]
##LEVEL3##
6.6G /opt/zenoss/perf [directory]
510M /opt/zenoss/ZenPacks [directory]
486M /opt/zenoss/var [directory]
461M /opt/zenoss/lib [directory]
250M /opt/zenoss/log [directory]
85M /opt/zenoss/Products [directory]
49M /opt/zenoss/packs [directory]
31M /opt/zenoss/share [directory]
26M /opt/zenoss/webapps [directory]
##LEVEL4##
6.5G /opt/zenoss/perf/Devices [directory]
59M /opt/zenoss/perf/Daemons [directory]
##LEVEL5##
289M /opt/zenoss/perf/Devices/10.0.4.218 [directory]
288M /opt/zenoss/perf/Devices/10.215.68.9 [directory]
287M /opt/zenoss/perf/Devices/10.0.4.18 [directory]
161M /opt/zenoss/perf/Devices/<removed> [directory]
145M /opt/zenoss/perf/Devices/10.219.68.12 [directory]
143M /opt/zenoss/perf/Devices/VMs-- [directory]
143M /opt/zenoss/perf/Devices/10.0.4.219 [directory]
143M /opt/zenoss/perf/Devices/10.0.4.19 [directory]
136M /opt/zenoss/perf/Devices/10.215.68.8 [directory]
##LEVEL6##
279M /opt/zenoss/perf/Devices/10.0.4.218/ltmvirtualservers [directory]
7.1M /opt/zenoss/perf/Devices/10.0.4.218/os [directory]
888K /opt/zenoss/perf/Devices/10.0.4.218/hw [directory]
840K /opt/zenoss/perf/Devices/10.0.4.218/loadbalancerports [directory]
You code doesn't work on my system, so I cannot test it. But you can do something like this:
function durec {
dir1=$1
level=$2
du1=$(du -x --max-depth=1 $dir1 | sort -nr | awk '{ print $2 }' | \
xargs du -hx --max-depth=0 | egrep -v "sys|proc|boot|lost|media|mnt|selinux" | head -10 | tail -n +2)
echo -e "##LEVEL$level##"
paste -d ' ' <(echo "$du1") <(echo "$(file $(echo "$du1" | \
awk '{print $2}')|cut -d' ' -f2- | sed -e 's/[a-zA-Z0-9]/[&/' -e 's/$/]/')")
let level++
dir2=$(echo "$du1"|head -1|awk '{print $2}')
if [ ! -z "$dir" ]; then
durec $dir2 $level
fi
}
# call the function
durec / 1
Your 1st du counts the whole filesystem. After you counts again and again for each subdir.
This for me seems as a couple of unnecessary counting (read nonsense), because you can save the output from the 1st du and works only on it...
Something like:
root="${1:-.}"
count=${2:-10}
tmp1=/tmp/durec_du.$$
tmp2=/tmp/durec_tmp.$$
trap "rm -f $tmp1 $tmp2;exit" 0 1 2 3 15
#human readable format - need GNU sort
#du -h "$root" | gsort -hr > $tmp1
#KB format
du -k "$root" | sort -nr > $tmp1
cp /dev/null $tmp2
level=0
durec() {
dir=$1
biggest=$(grep " ${dir}/[^/][^/]*$" $tmp1 | tee $tmp2 | head -1 | sed 's/^[0-9BKMGTP][0-9BKMGTP]* //')
# ^^^ ----------------------- one <TAB> character ---------------------------------- ^^^^
# if you have GNU version of sed, and grep replace the <TAB> with \t
[[ -n "$biggest" ]] || return
let level++
echo "##LEVEL$level##"
head -$count $tmp2
durec "$biggest"
}
durec "$root"
The gsort command is the GNU sort. If your standard sort is GNU, replace the gsort with a simple sort. (Need for the -h - sorting the result of du -h.

Resources