42 #include <arpa/inet.h>    45 EMANE::Models::CommEffect::FilterReader::getFilters(xmlNode * cur, 
Filters & filters)
    49       if((!xmlStrcmp(cur->name, 
XMLCHAR "filter")))
    51           Target * pTarget = getTarget(cur->xmlChildrenNode);
    55               auto optionalEffect = getEffect(cur->xmlChildrenNode);
    57               if(optionalEffect.second)
    59                   filters.push_back({pTarget,optionalEffect.first});
    74 EMANE::Models::CommEffect::FilterReader::getTarget(xmlNode * cur)
    78       if((!xmlStrcmp(cur->name, 
XMLCHAR "target")))
    81             getEthernetProtocolRules(cur->xmlChildrenNode);
    83           return new Target(rules);
    93 std::pair<EMANE::Events::CommEffect,bool>
    94 EMANE::Models::CommEffect::FilterReader::getEffect(xmlNode * cur)
    98       if((!xmlStrcmp(cur->name, 
XMLCHAR "effect")))
   100           return std::make_pair(Events::CommEffect{0,
   101                 getDuration(cur->xmlChildrenNode, 
"latency"),
   102                 getDuration(cur->xmlChildrenNode, 
"jitter"),
   103                 getProbability(cur->xmlChildrenNode, 
"loss"),
   104                 getProbability(cur->xmlChildrenNode, 
"duplicate"),
   105                 getBitRate(cur->xmlChildrenNode, 
"unicastbitrate"),
   106                 getBitRate(cur->xmlChildrenNode, 
"broadcastbitrate")},
true);
   117 EMANE::Models::CommEffect::FilterReader::getEthernetProtocolRules(xmlNode * cur)
   123       if((!xmlStrcmp(cur->name, 
XMLCHAR "ipv4")))
   125           std::string sSrc = getAttribute(cur, 
XMLCHAR "src");
   126           std::string sDst = getAttribute(cur, 
XMLCHAR "dst");
   127           std::string sLen = getAttribute(cur, 
XMLCHAR "len");
   128           std::string sTTL = getAttribute(cur, 
XMLCHAR "ttl");
   129           std::string sTOS = getAttribute(cur, 
XMLCHAR "tos");
   131           EthernetProtocolIPv4Rule * ethProto =
   132             new EthernetProtocolIPv4Rule{
static_cast<uint32_t
>(inet_addr(sSrc.c_str())),
   133                                          static_cast<uint32_t
>(inet_addr(sDst.c_str())),
   135                                          Utils::ParameterConvert(sTOS).toUINT8(),
   136                                          Utils::ParameterConvert(sTTL).toUINT8(),
   137                                          getIPProtocolRules(cur->xmlChildrenNode)};
   139           rules.push_back(ethProto);
   151 EMANE::Models::CommEffect::FilterReader::getIPProtocolRules(xmlNodePtr cur)
   157       if((!xmlStrcmp(cur->name, 
XMLCHAR "udp")))
   159           std::string sSrc = getAttribute(cur, 
XMLCHAR "sport");
   160           std::string sDst = getAttribute(cur, 
XMLCHAR "dport");
   162           rules.push_back(
new IPProtocolUDPRule{
EMANE::HTONS(Utils::ParameterConvert(sSrc).toUINT16()),
   163                 EMANE::HTONS(Utils::ParameterConvert(sDst).toUINT16())});
   165       else if((!xmlStrcmp(cur->name, 
XMLCHAR "protocol")))
   167           std::string type = getAttribute(cur, 
XMLCHAR "type");
   169           rules.push_back(
new IPProtocolSimpleRule{Utils::ParameterConvert(type).toUINT8()});
   181 EMANE::Models::CommEffect::FilterReader::getDuration(xmlNode * cur, 
const char *
id)
   185       if((!xmlStrcmp(cur->name, 
XMLCHAR id)))
   187           std::string sSec  = getAttribute(cur, 
XMLCHAR "sec");
   188           std::string sUSec = getAttribute(cur, 
XMLCHAR "usec");
   190           return Microseconds{std::chrono::duration_cast<
Microseconds>(std::chrono::seconds{Utils::ParameterConvert(sSec).toUINT32()}) +
   191               Microseconds{Utils::ParameterConvert(sUSec).toUINT32()}};
   196   return EMANE::Microseconds::zero();
   202 EMANE::Models::CommEffect::FilterReader::getProbability(xmlNode * cur, 
const char * 
id)
   206       if((!xmlStrcmp(cur->name, 
XMLCHAR id)))
   208           std::string sValue = getContent(cur);
   210           return Utils::ParameterConvert(sValue).toFloat();
   220 EMANE::Models::CommEffect::FilterReader::getBitRate(xmlNode * cur, 
const char * 
id)
   224       if((!xmlStrcmp(cur->name, 
XMLCHAR id)))
   226           std::string sValue = getContent(cur);
   228           return Utils::ParameterConvert(sValue).toUINT64();
   239 EMANE::Models::CommEffect::FilterReader::getAttribute(xmlNodePtr cur, 
const xmlChar * 
id)
   242   std::string str = 
"0";
   246       xmlChar *attr = xmlGetProp(cur, 
id);
   250           str =(
const char *) attr;
   260 EMANE::Models::CommEffect::FilterReader::getContent(xmlNodePtr cur)
   263   std::string str = 
"0";
   265   xmlChar *attr = xmlNodeGetContent(cur);
   269       str =(
const char *) attr;
   281   xmlParserCtxtPtr pContext{};
   286       pContext = xmlNewParserCtxt();
   291           if(!(pDoc = xmlCtxtReadFile(pContext,
   294                                       XML_PARSE_DTDVALID|XML_PARSE_NOERROR)))
   296               xmlFreeParserCtxt(pContext);
   301           if((pContext)->valid)
   303               if(!(pRoot = xmlDocGetRootElement(pDoc)))
   305                   xmlFreeParserCtxt(pContext);
   312               xmlFreeParserCtxt(pContext);
   329   xmlNodePtr pCurrent = pRoot;
   333       if((!xmlStrcmp(pCurrent->name, 
XMLCHAR "commeffect")))
   335           getFilters(pCurrent->xmlChildrenNode, filters);
   338       pCurrent = pCurrent->next;
   341   xmlFreeParserCtxt(pContext);
 
std::list< IPProtocolRule * > IPProtocolRules
 
std::list< Filter > Filters
 
static Filters load(const char *pzFileName)
 
std::list< EthernetProtocolRule * > EthernetProtocolRules
 
std::chrono::microseconds Microseconds
 
A CommEffect entry holds the NEM Id of a transmitter and the link effects to apply to received transm...
 
constexpr std::uint16_t HTONS(std::uint16_t x)