Could you help me according to simple UDP broadcast ?

189 views
Skip to first unread message

Chakkaphong St.

unread,
Dec 5, 2010, 8:39:56 AM12/5/10
to omn...@googlegroups.com

Hello,

I am really new for OMNET and I want to simulate a very simple UDP broadcast from one host to other two host. I have modified the original source code by refering to you code below. However, it still does not work. Thus, I have two questions to ask you. I will really appreciate your help.

The fisrt question is how you set the destination address for UDPApp in .ini file. I cannot set it either blank or "255.255.255.255" I have to set it to one existing host such as (*.host[0].udpApp[0].destAddresses = "host[1]") and when I run a simulation the UDP packet will send to such host only. UDP packet is considered as noise for host[2]. My UDPBasicApp::sendPacket() is as below

void UDPBasicApp::sendPacket()
{
    cPacket *payload = createPacket();

    IPvXAddress destAddr = IPAddress::ALLONES_ADDRESS;
    sendToUDP(payload, localPort, destAddr, destPort);

    numSent++;
}

void UDPAppBase::sendToUDP(cPacket *msg, int srcPort, const IPvXAddress& destAddr, int destPort)
{
    msg->setKind(UDP_C_DATA);
    UDPControlInfo *ctrl = new UDPControlInfo();
    ctrl->setSrcPort(srcPort);
    ctrl->setDestAddr(destAddr);
    ctrl->setDestPort(destPort);

    ctrl->setInterfaceId(101);

    msg->setControlInfo(ctrl);
    EV << "***tor*** Sending packet: ";
    printPacket(msg);

    send(msg, "udpOut");
}

However when the program calls printPacket(msg); the destionation address is IP address of Host[1] rather than Broadcast address. What did I do wrong or Do I miss anything?

 

The second question is I am not sure whether you have modified UDPBasicApp::initialize(int stage)or not. Because there is few line to retrive value of destAddresses from .ini file. Should I get rid of them as shown below?

void UDPBasicApp::initialize(int stage)
{
    // because of IPAddressResolver, we need to wait until interfaces are registered,
    // address auto-assignment takes place etc.
 //bindToPort(localPort);//*****tor*** add

    if (stage!=3)
        return;

    counter = 0;
    numSent = 0;
    numReceived = 0;
    WATCH(numSent);
    WATCH(numReceived);

    localPort = par("localPort");
    destPort = par("destPort");

    //const char *destAddrs = par("destAddresses");
    //cStringTokenizer tokenizer(destAddrs);

    //const char *token;
    //while ((token = tokenizer.nextToken())!=NULL)
    //    destAddresses.push_back(IPAddressResolver().resolve(token));

    //if (destAddresses.empty())
    //    return;
     bindToPort(localPort);

    cMessage *timer = new cMessage("sendTimer");
    scheduleAt((double)par("messageFreq"), timer);
}
 
Even I modified UDPBasicApp::initialize(int stage) as shown above and removed *.host[0].udpApp[0].destAddresses = "host[1]" out of .ini file, it seems there is no communication at all (no packet sent at all).
 
What should I do? Could you give me a suggestion. Any suggestions are value for me.

Thank you in advanced.

Regards,

Chakky

On 27 พ.ย. 2009, 09:39, Charlie <pgpenprue...@gmail.com> wrote:
> Yes, I use IPAddress::ALLONES_ADDRESS. Y type you my c++ code (the
> sending functions):
>
> void SendingSignature::sendPacket()
> {
>         SignedMsg *payload = createPacket();
>     //IPvXAddress destAddr = chooseDestAddr();
>         IPvXAddress destAddr = IPAddress::ALLONES_ADDRESS;
>     sendToUDP(payload, localPort, destAddr, destPort);
>
>     numSent++;
>
> }
>
> //funcion para el envio porBroadcast!!
> void SendingSignature::sendToUDP(SignedMsg *msg, int srcPort, const
> IPvXAddress& destAddr, int destPort)
> {
>     // send message to UDP, with the appropriate control info attached
>     msg->setKind(UDP_C_DATA);
>
>     UDPControlInfo *ctrl = new UDPControlInfo();
>     ctrl->setSrcPort(srcPort);
>     ctrl->setDestAddr(destAddr);
>     ctrl->setDestPort(destPort);
>     ctrl->setInterfaceId(101);
>
>     msg->setControlInfo(ctrl);
>
>     EV << "Sending packet: ";
>     printPacket(msg);
>     const ECP::Point& q = msg->getP();
>     EV << "X = " << q.x << endl;
>     EV << "Y = " << q.y << endl;
>     EV << "Mensaje = " << msg->getMsg() << endl;
>     //EV << "Firma = " << hex << msg->getSignature() << dec << endl;
>
>     send(msg, "udpOut");
>
> }
>
> void SendingSignature::handleMessage(cMessage *msg)
> {
>     if (msg->isSelfMessage())
>     {
>         // send, then reschedule next sending
>         sendPacket();
>         scheduleAt(simTime()+(double)par("messageFreq"), msg);
>     }
>     else
>     {
>         // process incoming packet
>         processPacket(check_and_cast<SignedMsg *>(msg));
>     }
>
>     if (ev.isGUI())
>     {
>         char buf[40];
>         sprintf(buf, "rcvd: %d pks\nsent: %d pks", numReceived,
> numSent);
>         getDisplayString().setTagArg("t",0,buf);
>     }
>
> }
>
> I'm grateful for your rapid answers!
>
> Regards.
>
> On 27 nov, 10:29, "Alfonso Ariza" <aariza...@hotmail.com> wrote:
>
>
>
> > The IP.cc code doesn't read correctly thebroadcastaddress.  How are you
> > setting thebroadcastaddress? Whit IPAddress::ALLONES_ADDRESS?
>
> > --------------------------------------------------
> > From: "Charlie" <pgpenprue...@gmail.com>
> > Sent: Friday, November 27, 2009 10:08 AM
> > To: "omnetpp" <omn...@googlegroups.com>
> > Subject: [Omnetpp-l] Re:Broadcastin INETMANET for Omnet 4 fixed?]
>
> > > I type you all that it appears me in the screen from I send the UDP
> > > packet to the first host drops the packet:
>
> > > ** Event #55  T=40  scenario.host[0].sendingSignature
> > > (SendingSignature, id=140), on selfmsg `sendTimer' (cMessage, id=101)
> > > Sending packet: (SignedMsg)  (99 bytes)
> > > <unspec> :5555 --> 255.255.255.255:5555
> > > X = 707429722658001420376168397060274978687491711591.
> > > Y = 1016494856058831609021684853563590114806406477202.
> > > Mensaje = Hola Mundo!!.
> > > ** Event #56  T=40  scenario.manager (TraCIScenarioManager, id=3), on
> > > selfmsg `step' (cMessage, id=0)
> > > Triggering TraCI server simulation advance to t=40
> > > Writing TraCI message of 11 bytes
> > > Reading TraCI message of 307 bytes
> > > module 0 moving to 4327,5374
> > > nextPosition 4327 5374 6e9efe94-1c70-4bbd-8a8d-1a6ad697b03b 5.50524
> > > 2.42738 5.56
> > > module 1 moving to 4339,5389
> > > nextPosition 4339 5389 6e9efe94-1c70-4bbd-8a8d-1a6ad697b03b 5.49452
> > > 2.42738 5.56
> > > module 2 moving to 4353,5404
> > > nextPosition 4353 5404 6e9efe94-1c70-4bbd-8a8d-1a6ad697b03b 5.55956
> > > 2.42738 5.56
> > > module 3 moving to 4366,5420
> > > nextPosition 4366 5420 6e9efe94-1c70-4bbd-8a8d-1a6ad697b03b 5.55876
> > > 2.42738 5.56
> > > ** Event #57  T=40  scenario.host[0].udp (UDP, id=135), on `
> > > {}' (SignedMsg, id=135)
> > > Sending app packet  over IPv4.
> > > ** Event #58  T=40  scenario.host[0].networkLayer.ip (IP, id=141), on `
> > > {}' (UDPPacket, id=136)
> > > ** Event #59  T=40.00001  scenario.host[0].networkLayer.ip (IP,
> > > id=141), on selfmsg `end-service' (cMessage, id=91)
> > > onOutboundDataPacket destAddr == myAddr (167772290)
> > > Routing datagram `' with dest=255.255.255.255: using manually
> > > specified output interface wlan
> > > output interface is wlan, next-hop address: <unspec>
> > > ** Event #60  T=40.00001  scenario.host[0].networkLayer.arp (ARP,
> > > id=142), on `{}' (IPDatagram, id=137)
> > > Packet (IPDatagram) arrived from higher layer, no next-hop address,
> > > using destination address 255.255.255.255 (proxy ARP)
> > > Starting ARP resolution for 255.255.255.255
> > > ** Event #61  T=40.00001  scenario.host[0].wlan.mac (Mac80211,
> > > id=146), on `arpREQ' (ARPPacket, id=138)
> > > packet (ARPPacket)arpREQ received from higher layer, dest=FF-FF-FF-FF-
> > > FF-FF, encapsulated
> > > beginning new contention cycle
> > > trying to send without backoff...
> > > state IDLE --> CONTEND
> > > ** Event #62  T=40.00006  scenario.host[0].wlan.mac (Mac80211,
> > > id=146), on selfmsg `contention' (cMessage, id=94)
> > > processing self message with type = CONTENTION
> > > end contention period
> > > sending down (Mac80211Pkt)arpREQ
> > > state CONTEND --> BUSY
> > > ** Event #63  T=40.00006  scenario.host[0].wlan.snrEval (SnrEval80211,
> > > id=148), on `arpREQ' (Mac80211Pkt, id=141)
> > > bits without header: 496, bits header: 192
> > > sending, changing RadioState to TRANSMIT
> > > ** Notification at T=40.00006 to scenario.host[0].wlan.mac: RADIO-
> > > STATE TRANSMIT, channel #0, -1e-06Mbps
> > > ** Radio state update in Mac80211: TRANSMIT, channel #0, -1e-06Mbps
> > > (at T=40.00006)
> > > ** Event #64  T=40.000060064031  scenario.host[1].wlan.snrEval
> > > (SnrEval80211, id=167), on `arpREQ' (AirFrame, id=144)
> > > receiving frame arpREQ
> > > publish new RadioState:RECV
> > > ** Notification at T=40.000060064031 to scenario.host[1].wlan.mac:
> > > RADIO-STATE RECV, channel #0, -1e-06Mbps
> > > ** Radio state update in Mac80211: RECV, channel #0, -1e-06Mbps  (at
> > > T=40.000060064031)
> > > ** Event #65  T=40.000060132329  scenario.host[2].wlan.snrEval
> > > (SnrEval80211, id=186), on `arpREQ' (AirFrame, id=145)
> > > receiving frame arpREQ
> > > publish new RadioState:RECV
> > > ** Notification at T=40.000060132329 to scenario.host[2].wlan.mac:
> > > RADIO-STATE RECV, channel #0, -1e-06Mbps
> > > ** Radio state update in Mac80211: RECV, channel #0, -1e-06Mbps  (at
> > > T=40.000060132329)
> > > ** Event #66  T=40.000060201025  scenario.host[3].wlan.snrEval
> > > (SnrEval80211, id=205), on `arpREQ' (AirFrame, id=146)
> > > receiving frame arpREQ
> > > publish new RadioState:RECV
> > > ** Notification at T=40.000060201025 to scenario.host[3].wlan.mac:
> > > RADIO-STATE RECV, channel #0, -1e-06Mbps
> > > ** Radio state update in Mac80211: RECV, channel #0, -1e-06Mbps  (at
> > > T=40.000060201025)
> > > ** Event #67  T=40.000297090909  scenario.host[0].wlan.mac (Mac80211,
> > > id=146), on selfmsg `transmission' (cMessage, id=95)
> > > processing self message with type = END_TRANSMISSION
> > > transmission of ACK/BROADCASTis over
> > > beginning new contention cycle
> > > state BUSY --> IDLE
> > > ** Event #68  T=40.000297090909  scenario.host[0].wlan.snrEval
> > > (SnrEval80211, id=148), on selfmsg `{}' (cMessage, id=143)
> > > transmission over, switch to idle mode (state:IDLE)
> > > ** Notification at T=40.000297090909 to scenario.host[0].wlan.mac:
> > > RADIO-STATE IDLE, channel #0, -1e-06Mbps
> > > ** Radio state update in Mac80211: IDLE, channel #0, -1e-06Mbps  (at
> > > T=40.000297090909)
> > > ** Event #69  T=40.00029715494  scenario.host[1].wlan.snrEval
> > > (SnrEval80211, id=167), on selfmsg `{}' (TransmComplete, id=147)
> > > reception of frame over, preparing to send packet to upper layer
> > > packet sent to the decider
> > > new RadioState is IDLE
> > > ** Notification at T=40.00029715494 to scenario.host[1].wlan.mac:
> > > RADIO-STATE IDLE, channel #0, -1e-06Mbps
> > > ** Radio state update in Mac80211: IDLE, channel #0, -1e-06Mbps  (at
> > > T=40.00029715494)
> > > ** Event #70  T=40.00029715494  scenario.host[1].wlan.decider
> > > (Decider80211, id=166), on `arpREQ' (AirFrame, id=144)
> > > packet (Mac80211Pkt)arpREQ () snrMin=72070.1
> > > berHeader: 0 berMPDU: 0
> > > packet was received correctly, it is now handed to upper layer...
> > > ** Event #71  T=40.00029715494  scenario.host[1].wlan.mac (Mac80211,
> > > id=165), on `arpREQ' (Mac80211Pkt, id=150)
> > > frame (Mac80211Pkt)arpREQ received, kind =BROADCAST
> > > handlebroadcast
> > > sending up (ARPPacket)arpREQ
> > > ** Event #72  T=40.00029715494  scenario.host[1].networkLayer.ip (IP,
> > > id=160), on `arpREQ' (ARPPacket, id=151)
> > > ** Event #73  T=40.000297223238  scenario.host[2].wlan.snrEval
> > > (SnrEval80211, id=186), on selfmsg `{}' (TransmComplete, id=148)
> > > reception of frame over, preparing to send packet to upper layer
> > > packet sent to the decider
> > > new RadioState is IDLE
> > > ** Notification at T=40.000297223238 to scenario.host[2].wlan.mac:
> > > RADIO-STATE IDLE, channel #0, -1e-06Mbps
> > > ** Radio state update in Mac80211: IDLE, channel #0, -1e-06Mbps  (at
> > > T=40.000297223238)
> > > ** Event #74  T=40.000297223238  scenario.host[2].wlan.decider
> > > (Decider80211, id=185), on `arpREQ' (AirFrame, id=145)
> > > packet (Mac80211Pkt)arpREQ () snrMin=18144.8
> > > berHeader: 0 berMPDU: 0
> > > packet was received correctly, it is now handed to upper layer...
> > > ** Event #75  T=40.000297223238  scenario.host[2].wlan.mac (Mac80211,
> > > id=184), on `arpREQ' (Mac80211Pkt, id=152)
> > > frame (Mac80211Pkt)arpREQ received, kind =BROADCAST
> > > handlebroadcast
> > > sending up (ARPPacket)arpREQ
> > > ** Event #76  T=40.000297223238  scenario.host[2].networkLayer.ip (IP,
> > > id=179), on `arpREQ' (ARPPacket, id=153)
> > > ** Event #77  T=40.000297291934  scenario.host[3].wlan.snrEval
> > > (SnrEval80211, id=205), on selfmsg `{}' (TransmComplete, id=149)
> > > reception of frame over, preparing to send packet to upper layer
> > > packet sent to the decider
> > > new RadioState is IDLE
> > > ** Notification at T=40.000297291934 to scenario.host[3].wlan.mac:
> > > RADIO-STATE IDLE, channel #0, -1e-06Mbps
> > > ** Radio state update in Mac80211: IDLE, channel #0, -1e-06Mbps  (at- ซ่อนข้อความที่ยกมา -
>


Reply all
Reply to author
Forward
0 new messages