Beispiel #1
0
        public static void receptionNotify(ulong destId, ulong srcId, int msgId, int status)
        {
            string statusString = status == OmnetSimulation.RECEPTION_OK ? "OK" : status == OmnetSimulation.RECEPTION_IGNORED ? "IGNORED" : status == OmnetSimulation.RECEPTION_BITERROR ? "BITERROR" : "UNKNOWN";

            Console.WriteLine("C# : receptionNotify is called with destID=" + destId + " srcId=" + srcId + " msgId=" + msgId + " status=" + statusString);

            //Example
            Console.WriteLine("Time: " + OmnetSimulation.Instance().GetGlobalTime() + "ps");
            if (status == OmnetSimulation.RECEPTION_OK)
            {
                if (destId == 7)
                {
                    OmnetSimulation.Instance().Send(7, srcId, 10, 123);
                }
                if (destId == 8)
                {
                    OmnetSimulation.Instance().Send(8, srcId, 10, 123);
                }
                if (destId == 9)
                {
                    OmnetSimulation.Instance().Send(9, srcId, 10, 123);
                }
                if (destId == 10)
                {
                    OmnetSimulation.Instance().Send(10, srcId, 10, 123);
                }
                if (destId == 11)
                {
                    OmnetSimulation.Instance().Send(11, srcId, 10, 123);
                }
            }
        }
Beispiel #2
0
        public static void initSimulation()
        {
            Console.WriteLine("C# : initSimulation is called");

            //Example

            OmnetSimulation.Instance().CreateNode(1, OmnetSimulation.ACCESSPOINT_TYPE);
            OmnetSimulation.Instance().CreateNode(2, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(3, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(4, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(5, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(6, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(7, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(8, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(9, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(10, OmnetSimulation.PHYNODE_RESPONDING_TYPE);

            OmnetSimulation.Instance().CreateNode(11, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(12, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(13, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(14, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(15, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(16, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(17, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(18, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(19, OmnetSimulation.PHYNODE_IGNORING_TYPE);
            OmnetSimulation.Instance().CreateNode(20, OmnetSimulation.PHYNODE_RESPONDING_TYPE);


            OmnetSimulation.Instance().GetGlobalTime();
        }
Beispiel #3
0
        public static void simulationReady()
        {
            Console.WriteLine("C# : simulationReady is called");

            //Example
            OmnetSimulation.Instance().Send(1, OmnetSimulation.BROADCAST_ADDR, 10, 123);
            Console.WriteLine("Time: " + OmnetSimulation.Instance().GetGlobalTime() + "ps");
            OmnetSimulation.Instance().SetGlobalTimerSeconds(5);
        }
Beispiel #4
0
        public static void globalTimerNotify()
        {
            Console.WriteLine("C# : globalTimerNotify is called");

            //Example
            // OmnetSimulation.Instance().Send(1, 2, 10, 123);
            Console.WriteLine("Time: " + OmnetSimulation.Instance().GetGlobalTime() + "ps");
            // OmnetSimulation.Instance().SetGlobalTimerSeconds(2);
            Instance.OmnetGlobalTimerNotify?.Invoke();
        }
Beispiel #5
0
 public static void globalTimerNotify()
 {
     cnt++;
     Console.WriteLine("C# : globalTimerNotify is called");
     Console.WriteLine("Count: " + cnt);
     if (cnt < 100)
     {
         OmnetSimulation.Instance().Send(1, OmnetSimulation.BROADCAST_ADDR, 10, 123);
         Console.WriteLine("Time: " + OmnetSimulation.Instance().GetGlobalTime() + "ps");
         OmnetSimulation.Instance().SetGlobalTimerSeconds(5);
         Console.WriteLine("Count: " + cnt);
     }
 }
Beispiel #6
0
        public static void initSimulation()
        {
            if (SynchronizationContext.Current == null)
            {
                var context = new ExecuteNowSynchronizationContext();
                SynchronizationContext.SetSynchronizationContext(context);
            }
            OmnetSimulation.SynchronizationContext = SynchronizationContext.Current;
            Console.WriteLine("C# : initSimulation is called");

            Instance.TimeAtStart           = OmnetSimulation.Instance().GetGlobalTime();
            Instance.DateTimeOffsetAtStart = DateTime.Now;

            //Example
            // OmnetSimulation.Instance().CreateNode(1);
            // OmnetSimulation.Instance().CreateNode(2);
            // OmnetSimulation.Instance().GetGlobalTime();
            // Context = new BulkExecutingSynchronizationContext();
            // SynchronizationContext.SetSynchronizationContext(Context);

            Console.WriteLine("Received init from omnet++.");
            // Create and configure the actor system.
            CreateConfiguredActorSystem();
            // Context.EnterControlledExecutionMode();

            Console.WriteLine("Created actor system.");

            // Create and configure the PhyNet runtime.
            // This loads plugins etc.
            var approot = Sys.ActorOf(PhyNetContainer.Props.WithDispatcher("calling-thread-dispatcher"), "approot");
            var config  = PhyNetContainer.GetConfigFromString("{\r\n\t\"plugins\": [\r\n\t\t\"" + typeof(Plugin).AssemblyQualifiedName + "\"\r\n\t] \r\n}");

            approot.Tell(new PhyNetContainer.Configure(config));

            // Setup the PhyNet and the plugin.
            // We need to do this before actually triggering the event, because otherwise no listener will exist.
            // TODO Context.ExecuteAll();
            Console.WriteLine("Told Container to configure.");

            // Actually trigger the event.
            Instance.OnOmneTBeforeStart();
            // TODO Context.ExecuteAll();
            Console.WriteLine("Done with init.");
            // Here everything is ready and we can wait for omnet++.
        }