コード例 #1
0
ファイル: simulation.py プロジェクト: jarmillemich/umf-thesis
 def startAndMonitorApps(self, resolution = 5):
     self.serverApps.Stop(Seconds(0))
     self.clientApps.Stop(Seconds(0))
     
     # Set up a stats gathering event
     self.serverAppsLastSample = [0 for i in range(self.serverApps.GetN())]
     self.clientAppsLastSample = [0 for i in range(self.clientApps.GetN())]
     self.monitorApps(resolution)
コード例 #2
0
 def testTimeComparison(self):
     """! Test time comparison
     @param self this object
     @return none
     """
     self.assert_(Seconds(123) == Seconds(123))
     self.assert_(Seconds(123) >= Seconds(123))
     self.assert_(Seconds(123) <= Seconds(123))
     self.assert_(Seconds(124) > Seconds(123))
     self.assert_(Seconds(123) < Seconds(124))
コード例 #3
0
    def testScheduleDestroy(self):
        """! Test schedule destroy
        @param self this object
        @return none
        """
        def callback(args):
            """! Callback function
            @param args
            @return none
            """
            self._args_received = args
            self._cb_time = Simulator.Now()

        Simulator.Destroy()
        self._args_received = None
        self._cb_time = None

        def null():
            pass

        Simulator.Schedule(Seconds(123), null)
        Simulator.ScheduleDestroy(callback, "args")
        Simulator.Run()
        Simulator.Destroy()
        self.assertEqual(self._args_received, "args")
        self.assertEqual(self._cb_time.GetSeconds(), 123.0)
コード例 #4
0
    def testSchedule(self):
        def callback(args):
            self._args_received = args
            self._cb_time = Simulator.Now()

        Simulator.Destroy()
        self._args_received = None
        self._cb_time = None
        Simulator.Schedule(Seconds(123), callback, "args")
        Simulator.Run()
        self.assertEqual(self._args_received, "args")
        self.assertEqual(self._cb_time.GetSeconds(), 123.0)
コード例 #5
0
    def testScheduleWithContext(self):
        def callback(context, args):
            self._context_received = context
            self._args_received = args
            self._cb_time = Simulator.Now()

        Simulator.Destroy()
        self._args_received = None
        self._cb_time = None
        self._context_received = None
        Simulator.ScheduleWithContext(54321, Seconds(123), callback, "args")
        Simulator.Run()
        self.assertEqual(self._context_received, 54321)
        self.assertEqual(self._args_received, "args")
        self.assertEqual(self._cb_time.GetSeconds(), 123.0)
コード例 #6
0
    def testTimeNumericOperations(self):
        """! Test numeric operations
        @param self this object
        @return none
        """
        self.assertEqual(Seconds(10) + Seconds(5), Seconds(15))
        self.assertEqual(Seconds(10) - Seconds(5), Seconds(5))

        v1 = int64x64_t(5.0) * int64x64_t(10)
        self.assertEqual(v1, int64x64_t(50))
コード例 #7
0
ファイル: simulation.py プロジェクト: jarmillemich/umf-thesis
 def monitorApps(self, resolution = 5):
     nApps = self.serverApps.GetN()
     at = [self.serverApps.Get(i).GetTotalRx() for i in range(nApps)]
     delta = [at[i] - self.serverAppsLastSample[i] for i in range(nApps)]
     self.serverAppsLastSample = at
     self.serverAppStats.append(delta)
     
     nApps = self.clientApps.GetN()
     at = [self.clientApps.Get(i).GetTotalBytes() for i in range(nApps)]
     delta = [at[i] - self.clientAppsLastSample[i] for i in range(nApps)]
     self.clientAppsLastSample = at
     self.clientAppStats.append(delta)
     
     #print('at %d got %s' % (ns.core.Simulator.Now().GetSeconds(), delta))
     #print(self.enbNodes.Get(0).GetObject(ns.mobility.MobilityModel.GetTypeId()).GetPosition())
     
     ns.core.Simulator.Schedule(Seconds(float(resolution)), lambda: self.monitorApps(resolution))
コード例 #8
0
ファイル: simulation.py プロジェクト: jarmillemich/umf-thesis
    def run(self, time):
        from tqdm.auto import tqdm
        pbar = tqdm(unit = ' sim seconds', total = int(time))
        
        # Keep track of time
        def logTime():
            now = ns.core.Simulator.Now().GetSeconds()
            pbar.n = int(now)
            pbar.update(0)
            ns.core.Simulator.Schedule(Seconds(1), logTime)
            
        logTime()

        # Start apps
        self.serverApps.Start(MilliSeconds(0))
        self.clientApps.Start(MilliSeconds(0))
        
        ns.core.Simulator.Stop(Seconds(time))
        ns.core.Simulator.Run()
        pbar.n = pbar.total
        pbar.refresh()
コード例 #9
0
 def testScheduleWithContext(self):
     """! Test schedule with context
     @param self this object
     @return none
     """
     def callback(context, args):
         """! Callback
         @param context the cntet
         @param args the arguments
         @return none
         """
         self._context_received = context
         self._args_received = args
         self._cb_time = Simulator.Now()
     Simulator.Destroy()
     self._args_received = None
     self._cb_time = None
     self._context_received = None
     Simulator.ScheduleWithContext(54321, Seconds(123), callback, "args")
     Simulator.Run()
     self.assertEqual(self._context_received, 54321)
     self.assertEqual(self._args_received, "args")
     self.assertEqual(self._cb_time.GetSeconds(), 123.0)
コード例 #10
0
print(left_node_1_address)
right_node_1 = point_to_point_dumbbell_helper.GetRight(0)
right_node_1_address = right_node_1.GetDevice(1).GetAddress()
print(right_node_1_address)

left_node_2 = point_to_point_dumbbell_helper.GetLeft(1)
left_node_2_address = left_node_2.GetDevice(1).GetAddress()
print(left_node_2_address)
right_node_2 = point_to_point_dumbbell_helper.GetRight(1)
right_node_2_address = right_node_2.GetDevice(1).GetAddress()
print(right_node_2_address)

udp_echo_server_helper = UdpEchoServerHelper(50000)

server = udp_echo_server_helper.Install(left_node_1)
server.Start(Seconds(1.0))
server.Stop(Seconds(10.0))

udp_echo_client_helper = UdpEchoClientHelper(Ipv4Address("10.1.1.1"), 50000)
udp_echo_client_helper.SetAttribute("MaxPackets", UintegerValue(1000))
udp_echo_client_helper.SetAttribute("Interval", TimeValue(Seconds(1.0)))
#udp_echo_client_helper.SetAttribute("Interval", TimeValue(Seconds(0.1)))
#udp_echo_client_helper.SetAttribute("Interval", TimeValue(Seconds(0.01)))
udp_echo_client_helper.SetAttribute("PacketSize", UintegerValue(1024))

#em1 = Ptr()
#em1 = CreateObjectWithAttributes("RanVar", StringValue ("ns3::UniformRandomVariable[Min=0.0,Max=1.0]"), "ErrorRate", DoubleValue (0.01));

#udp_echo_client_helper.SetAttribute("RecieveErrorModel", PointerValue(em1))
client_1 = udp_echo_client_helper.Install(right_node_1)
client_1.Start(Seconds(2.0))
コード例 #11
0
ファイル: simulation.py プロジェクト: jarmillemich/umf-thesis
 def logTime():
     now = ns.core.Simulator.Now().GetSeconds()
     pbar.n = int(now)
     pbar.update(0)
     ns.core.Simulator.Schedule(Seconds(1), logTime)
コード例 #12
0
ファイル: simulation.py プロジェクト: jarmillemich/umf-thesis
 def stopAppsAt(self, dt):
     self.serverApps.Stop(Seconds(float(dt)))
     self.clientApps.Stop(Seconds(float(dt)))
コード例 #13
0
    def testTimeNumericOperations(self):
        self.assertEqual(Seconds(10) + Seconds(5), Seconds(15))
        self.assertEqual(Seconds(10) - Seconds(5), Seconds(5))

        v1 = int64x64_t(5.0) * int64x64_t(10)
        self.assertEqual(v1, int64x64_t(50))
コード例 #14
0
 def testTimeComparison(self):
     self.assert_(Seconds(123) == Seconds(123))
     self.assert_(Seconds(123) >= Seconds(123))
     self.assert_(Seconds(123) <= Seconds(123))
     self.assert_(Seconds(124) > Seconds(123))
     self.assert_(Seconds(123) < Seconds(124))
コード例 #15
0
ファイル: star.py プロジェクト: TakashiSasaki/ns3-motoyoshi
pointToPointStarHelper = PointToPointStarHelper(5, pointToPointHelper)

# Install Internet Stack On All Nodes
internetStackHelper = InternetStackHelper()
pointToPointStarHelper.InstallStack(internetStackHelper)

# Assign IP Address
pointToPointStarHelper.AssignIpv4Addresses(
    Ipv4AddressHelper(Ipv4Address("10.1.1.0"), Ipv4Mask("255.255.255.0")))

# Create A Packet Sink On The Star "Hub" To Recieve Packets
hubLocalAddress = Address(InetSocketAddress(Ipv4Address.GetAny(), 50000))
packetSinkHelper = PacketSinkHelper("ns3::TcpSocketFactory", hubLocalAddress)
hubApp = ApplicationContainer()
hubApp = packetSinkHelper.Install(pointToPointStarHelper.GetHub())
hubApp.Start(Seconds(1.0))
hubApp.Stop(Seconds(10.0))

# Create On-Off Applications To Send TCP To The Hub. One On Each Spoke Node.
onOffHelper = OnOffHelper("ns3::TcpSocketFactory", Address())
onOffHelper.SetAttribute(
    "OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"))
onOffHelper.SetAttribute(
    "OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"))

spokeApps = ApplicationContainer()
spokeCount = pointToPointStarHelper.SpokeCount()

for i in range(spokeCount):
    remoteAddress = AddressValue(
        InetSocketAddress(pointToPointStarHelper.GetHubIpv4Address(i), 50000))
コード例 #16
0
# remote

remoteAddress = AddressValue(
    InetSocketAddress(ipv4InterfaceContainer3.GetAddress(1, 0), 50000))
#remoteAddress(InetSocketAddress(ipv4InterfaceContainer3.GetAddress(1, 0), 50000))

ftp = BulkSendHelper("ns3::TcpSocketFactory", Address())

#ftp max 5MB
ftp.SetAttribute("Remote", remoteAddress)
ftp.SetAttribute("MaxBytes", UintegerValue(5242880))

sourceApp1 = ApplicationContainer()
sourceApp1 = ftp.Install(net1Nodes.Get(0))

sourceApp1.Start(Seconds(2.0))
sourceApp1.Stop(Seconds(4.0))

sourceApp2 = ApplicationContainer()
sourceApp2 = ftp.Install(net2Nodes.Get(1))

sourceApp2.Start(Seconds(2.0))
sourceApp2.Stop(Seconds(4.0))

# sink

sinkAddress = Address(InetSocketAddress(Ipv4Address.GetAny(), 50000))
sinkHelper = PacketSinkHelper("ns3::TcpSocketFactory", sinkAddress)

sinkApps = ApplicationContainer()
sinkApps = sinkHelper.Install(net3Nodes.Get(1))