prvreader::PrvEvent* prvreader::PrvParser::parseLine() { string line; PrvEvent* prvEvent; if (prvStream){ if(getline(*prvStream,line)){ lineNumber++; if (lineNumber%10000==0){ Message::Debug(to_string(lineNumber)+ " lines processed"); } replace(line.begin(), line.end(), '\t', ' '); std::size_t found = line.find_first_of("("); if ((found!=std::string::npos)&&(found+1<line.length())){ found = line.find_first_of("a", found+1); } if ((found!=std::string::npos)&&(line[found+1]=='t')&&(found+5<line.length())&&(line[found+5]==PRV_HEADER_SEP_MAIN_CHAR)){ line[found+5]='*'; } replace(line.begin(), line.end(), PRV_HEADER_QUOTE_IN_CHAR, GENERIC_SEP_CHAR); replace(line.begin(), line.end(), PRV_HEADER_QUOTE_OUT_CHAR, GENERIC_SEP_CHAR); trim_all(line); if (!line.empty()){ escaped_list_separator<char> sep(GENERIC_ESCAPE_CHAR, PRV_HEADER_SEP_MAIN_CHAR, GENERIC_QUOTE_CHAR); tokenizer<escaped_list_separator<char> > *tokens = new tokenizer<escaped_list_separator<char> >(line, sep); tokenizer<escaped_list_separator<char> >::iterator tokensIterator=tokens->begin(); if (mode==Header){ prvEvent=parseHeader(tokens); mode=Body; }else{ string eventType=*tokensIterator; tokensIterator++; //communicator if (eventType.compare(PRV_BODY_COMMUNICATOR)==0){ prvEvent= new PrvOther(lineNumber, prveventtype::Skip); //communications }else if (eventType.compare(PRV_BODY_COMMUNICATION)==0){ prvEvent=parseCommunications(tokens, lineNumber); }else if (eventType.compare(PRV_BODY_EVENTS)==0){ prvEvent=parseEvents(tokens, lineNumber); }else if (eventType.compare(PRV_BODY_STATE)==0){ prvEvent=parseState(tokens, lineNumber); }else{ prvEvent= new PrvOther(lineNumber, prveventtype::Skip); } } delete tokens; } }else{ prvEvent=new PrvOther(lineNumber, prveventtype::End); } } return prvEvent; }
/** * Parse the NetDMFEvent type, described below. * * An <Event> is the high level container for discrete events. In addition * to StartTime and EndTime (from the Unix epoch) an <Event> has an * EventType attribute. EventType corresponds to the child element type of * the <Event>. Valid EventTypes are : * - Collection - Events that should be grouped * - Movement - Node Movement * - Communication - two or more nodes communicating * Communication Event Types can be further defined in two different ways, as * specified by CommunicationType. Valid CommunicationTypes are : * - Conversation - Communication between two endpoints * - EndPoint - Endpoints for communications * - PacketCapture - Packets captured at a specific node:device * - Application - A simulator-supported traffic generation application (e.g. ping) @verbatim <Result> <Event EventType="Collection" CollectionType="Temporal" Name="Simple OLSR Simulation" StartTime="0.0" Endtime="50.0"> <Event EventType="Collection" CollectionType="Temporal" StartTime="0.0" Endtime="1.0"> <Event EventType="Movement" NodeId="2" <Movement MovementType="Path" PathType="TimeLatLonHeight" PathLength="2"> <DataItem NumberType="Float" Dimensions="3 4" Format="XML"> 0.0 35.0 75.0 1.0 1.0 35.15 75.0 1.0 </DataItem> </Movement> </Event> <Event EventType="Comm" CommType="EndPoints" EndPointType="IPV4"> <AddressItem AddressType="IPV4" NumberOfAddresses"4" Format="XML" > 10.11.102.23 10.11.104.23 192.168.0.1 192.168.0.12 </AddressItem> </Event> <Event EventType="Comm" CommType="Conversation"> <Conversation ConversationType="IPV4" EndPointA="10.11.102.23" EndPointB="10.11.104.23"> <PacketItem NumberOfPackets="100" PacketType="Filter" Filter="src host 10.11.102.23 and dst host 10.11.104.23" Format="PCAP"> test.pcap </PacketItem> <Traffic TrafficType="Bin" Units="Bytes" Interval="0.1"> <DataItem NumberType="Float" Dimensions="10" Format="XML"> 0.0 0.0 0.0 0.0 356.0 500.0 500.0 0.0 0.0 0.0 </DataItem> </Traffic> </Conversation> </Event> <Event EventType="Comm" CommType="PacketCapture"> <Parameter Name="NodeId" Value="1"/> <Parameter Name="DeviceId" Value="0"/> <PacketItem Format="PCAP"> test1_n1d0.pcap </PacketItem> </Event> </Event> <Event EventType="Collection" StartTime="1.0" Endtime="2.0"> Events for time 1.0 2.0 </Event> Etc....... </Event> </Result> @endverbatim */ void parseEvents(NetDMFScenario *parent) { int totalEvents = parent->GetNumberOfEvents(); for (int i = 0; i < totalEvents; i++) { NetDMFEvent *eventItem = parent->GetEvent(i); if (eventItem->GetEventType() == 1) { parseMovements(eventItem); } else if (eventItem->GetEventType() == 2) { parseCommunications(eventItem); } else { printf("Unknown event type: %d\n", i); } } }