Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

attrs.hh File Reference

#include <unistd.h>
#include <netinet/in.h>
#include "nr/nr.hh"
#include "header.hh"
#include "tools.hh"

Include dependency graph for attrs.hh:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions

NRAttrVecCopyAttrs (NRAttrVec *src_attrs)
void AddAttrs (NRAttrVec *attr_vec1, NRAttrVec *attr_vec2)
void ClearAttrs (NRAttrVec *attr_vec)
void PrintAttrs (NRAttrVec *attr_vec)
DiffPacket AllocateBuffer (NRAttrVec *attr_vec)
int CalculateSize (NRAttrVec *attr_vec)
int PackAttrs (NRAttrVec *attr_vec, char *start_pos)
NRAttrVecUnpackAttrs (DiffPacket pkt, int num_attr)
bool PerfectMatch (NRAttrVec *attr_vec1, NRAttrVec *attr_vec2)
bool OneWayPerfectMatch (NRAttrVec *attr_vec1, NRAttrVec *attr_vec2)
bool MatchAttrs (NRAttrVec *attr_vec1, NRAttrVec *attr_vec2)
bool OneWayMatch (NRAttrVec *attr_vec1, NRAttrVec *attr_vec2)


Function Documentation

void AddAttrs NRAttrVec attr_vec1,
NRAttrVec attr_vec2
 

Definition at line 93 of file attrs.cc.

References CopyAttrs().

Referenced by DiffusionRouting::send().

00094 {
00095   NRAttrVec *copied_attrs;
00096   NRAttrVec::iterator itr;
00097   NRAttribute *src;
00098 
00099   if (attr_vec1 == NULL)
00100     attr_vec1 = new NRAttrVec;
00101 
00102   // Check if there's something to do
00103   if (attr_vec2 == NULL)
00104     return;
00105 
00106   // Duplicate source attributes so they can be added to the dst set
00107   copied_attrs = CopyAttrs(attr_vec2);
00108 
00109   // Add all attributes in the copied set into the dst set
00110   for (itr = copied_attrs->begin(); itr != copied_attrs->end(); ++itr){
00111     src = *itr;
00112 
00113     attr_vec1->push_back(src);
00114   }
00115 
00116   // Delete the copied_attr vector without deleting its attributes
00117   delete copied_attrs;
00118 }

Here is the call graph for this function:

DiffPacket AllocateBuffer NRAttrVec attr_vec  ) 
 

Definition at line 175 of file attrs.cc.

References CalculateSize(), DEBUG_ALWAYS, DiffPacket, DiffPrint(), and len.

Referenced by DiffusionRouting::sendMessageToDiffusion(), DiffusionCoreAgent::sendMessageToLibrary(), and DiffusionCoreAgent::sendMessageToNetwork().

00176 {
00177   DiffPacket pkt;
00178   int len;
00179 
00180   len = CalculateSize(attr_vec);
00181   len = len + sizeof(struct hdr_diff);
00182   pkt = new int [1 + (len / sizeof(int))];
00183 
00184   if (pkt == NULL){
00185     DiffPrint(DEBUG_ALWAYS, "Cannot allocate memory for packet !\n");
00186     exit(-1);
00187   }
00188 
00189   return pkt;
00190 }

Here is the call graph for this function:

int CalculateSize NRAttrVec attr_vec  ) 
 

Definition at line 192 of file attrs.cc.

References NRAttribute::getLen(), and int32_t.

Referenced by DiffusionRouting::addFilter(), AllocateBuffer(), DiffusionRouting::filterKeepaliveTimeout(), DiffusionCoreAgent::forwardMessage(), DiffusionRouting::interestTimeout(), LogFilter::ProcessMessage(), DiffusionRouting::removeFilter(), DiffusionRouting::send(), DiffusionRouting::sendMessage(), and DiffusionCoreAgent::sendMessage().

00193 {
00194   NRAttrVec::iterator itr;
00195   NRAttribute *temp;
00196   int pad, attr_len;
00197   int total_len = 0;
00198 
00199   for (itr = attr_vec->begin(); itr != attr_vec->end(); ++itr){
00200     temp = *itr;
00201     attr_len = temp->getLen();
00202 
00203     // We have to pad to avoid bus errors
00204     pad = 0;
00205     if (attr_len % sizeof(int)){
00206       pad = sizeof(int) - (attr_len % sizeof(int));
00207     }
00208     total_len = total_len + sizeof(PackedAttribute) - sizeof(int32_t) + attr_len + pad;
00209   }
00210   return total_len;
00211 }

Here is the call graph for this function:

void ClearAttrs NRAttrVec attr_vec  ) 
 

Definition at line 120 of file attrs.cc.

Referenced by GeoRoutingFilter::beaconTimeout(), GeoRoutingFilter::broadcastHeuristicValue(), GeoRoutingFilter::preProcessFilter(), DiffusionRouting::processMessage(), GradientFilter::sendDisinterest(), GeoRoutingFilter::sendNeighborRequest(), GradientFilter::sendPositiveReinforcement(), TagFilter::setupFilter(), SrcRtFilter::setupFilter(), LogFilter::setupFilter(), GradientFilter::setupFilter(), GeoRoutingFilter::setupPostFilter(), GeoRoutingFilter::setupPreFilter(), PushSenderApp::setupPublication(), PingSenderApp::setupPublication(), PushReceiverApp::setupSubscription(), PingSenderApp::setupSubscription(), PingReceiverApp::setupSubscription(), AttributeEntry::~AttributeEntry(), FilterEntry::~FilterEntry(), HandleEntry::~HandleEntry(), Message::~Message(), RoutingEntry::~RoutingEntry(), and SubscriptionExpirationTimer::~SubscriptionExpirationTimer().

00121 {
00122   NRAttrVec::iterator itr;
00123 
00124   for (itr = attr_vec->begin(); itr != attr_vec->end(); ++itr){
00125     delete *itr;
00126   }
00127 
00128   attr_vec->clear();
00129 }

NRAttrVec* CopyAttrs NRAttrVec src_attrs  ) 
 

Definition at line 37 of file attrs.cc.

References NRAttribute::BLOB_TYPE, DEBUG_ALWAYS, DiffPrint(), NRAttribute::FLOAT32_TYPE, NRAttribute::FLOAT64_TYPE, NRAttribute::getKey(), NRAttribute::getLen(), NRAttribute::getOp(), NRAttribute::getType(), NRAttribute::INT32_TYPE, and NRAttribute::STRING_TYPE.

Referenced by AddAttrs(), DiffusionRouting::addFilter(), DiffusionCoreAgent::addFilter(), GeoRoutingFilter::beaconTimeout(), GeoRoutingFilter::broadcastHeuristicValue(), CopyMessage(), DiffusionRouting::filterKeepaliveTimeout(), GradientFilter::forwardData(), DiffusionCoreAgent::forwardMessage(), DiffusionRouting::interestTimeout(), GeoRoutingFilter::preProcessFilter(), DiffusionRouting::processMessage(), GradientFilter::processNewMessage(), DiffusionRouting::publish(), GradientFilter::reinforcementTimeout(), DiffusionRouting::send(), GradientFilter::sendDisinterest(), GradientFilter::sendInterest(), DiffusionRouting::sendMessage(), DiffusionCoreAgent::sendMessage(), GeoRoutingFilter::sendNeighborRequest(), GradientFilter::sendPositiveReinforcement(), and DiffusionRouting::subscribe().

00038 {
00039   NRAttrVec::iterator itr;
00040   NRAttrVec *dst_attrs;
00041   NRAttribute *src;
00042 
00043   dst_attrs = new NRAttrVec;
00044 
00045   for (itr = src_attrs->begin(); itr != src_attrs->end(); ++itr){
00046     src = *itr;
00047     switch (src->getType()){
00048     case NRAttribute::INT32_TYPE:
00049       dst_attrs->push_back(new NRSimpleAttribute<int>(src->getKey(),
00050                                                 NRAttribute::INT32_TYPE,
00051                                                 src->getOp(),
00052                                                ((NRSimpleAttribute<int> *)src)->getVal()));
00053       break;
00054 
00055     case NRAttribute::FLOAT32_TYPE:
00056       dst_attrs->push_back(new NRSimpleAttribute<float>(src->getKey(),
00057                                                 NRAttribute::FLOAT32_TYPE,
00058                                                 src->getOp(),
00059                                                 ((NRSimpleAttribute<float> *)src)->getVal()));
00060       break;
00061 
00062     case NRAttribute::FLOAT64_TYPE:
00063       dst_attrs->push_back(new NRSimpleAttribute<double>(src->getKey(),
00064                                                  NRAttribute::FLOAT64_TYPE,
00065                                                  src->getOp(),
00066                                                  ((NRSimpleAttribute<double> *)src)->getVal()));
00067       break;
00068 
00069     case NRAttribute::STRING_TYPE:
00070       dst_attrs->push_back(new NRSimpleAttribute<char *>(src->getKey(),
00071                                                 NRAttribute::STRING_TYPE,
00072                                                 src->getOp(),
00073                                                 ((NRSimpleAttribute<char *> *)src)->getVal()));
00074       break;
00075 
00076     case NRAttribute::BLOB_TYPE:
00077       dst_attrs->push_back(new NRSimpleAttribute<void *>(src->getKey(),
00078                                               NRAttribute::BLOB_TYPE,
00079                                               src->getOp(),
00080                                               ((NRSimpleAttribute<void *> *)src)->getVal(),
00081                                               src->getLen()));
00082       break;
00083 
00084     default:
00085 
00086       DiffPrint(DEBUG_ALWAYS, "Unknown attribute type found in CopyAttrs() !\n");
00087       break;
00088     }
00089   }
00090   return dst_attrs;
00091 }

Here is the call graph for this function:

bool MatchAttrs NRAttrVec attr_vec1,
NRAttrVec attr_vec2
 

Definition at line 379 of file attrs.cc.

References OneWayMatch().

Referenced by GradientFilter::matchRoutingEntry(), and DiffusionRouting::processMessage().

00380 {
00381   if (OneWayMatch(attr_vec1, attr_vec2))
00382     if (OneWayMatch(attr_vec2, attr_vec1))
00383       return true;
00384 
00385   return false;
00386 }

Here is the call graph for this function:

bool OneWayMatch NRAttrVec attr_vec1,
NRAttrVec attr_vec2
 

Definition at line 388 of file attrs.cc.

References DEBUG_ALWAYS, DiffPrint(), NRAttribute::EQ, NRAttribute::EQ_ANY, NRAttribute::find_matching_key_from(), NRAttribute::GE, NRAttribute::getOp(), NRAttribute::GT, NRAttribute::IS, NRAttribute::isEQ(), NRAttribute::isGE(), NRAttribute::isGT(), NRAttribute::isLE(), NRAttribute::isLT(), NRAttribute::isNE(), NRAttribute::LE, NRAttribute::LT, and NRAttribute::NE.

Referenced by DiffusionCoreAgent::findMatchingFilter(), MatchAttrs(), and DiffusionRouting::processControlMessage().

00389 {
00390   NRAttrVec::iterator itr1, itr2;
00391   NRAttribute *a;
00392   NRAttribute *b;
00393   bool found_attr;
00394 
00395   for (itr1 = attr_vec1->begin(); itr1 != attr_vec1->end(); ++itr1){
00396 
00397     // For each attribute in vec1 that has an operator different
00398     // than "IS", we need to find a "matchable" one in vec2
00399     a = *itr1;
00400     if (a->getOp() == NRAttribute::IS)
00401       continue;
00402 
00403     itr2 = attr_vec2->begin();
00404     for (;;){
00405       b = a->find_matching_key_from(attr_vec2, itr2, &itr2);
00406 
00407       // Found ?
00408       if (!b)
00409         return false;
00410 
00411       // If Op is not "IS" we need keep looking
00412       if (b->getOp() != NRAttribute::IS){
00413         itr2++;
00414         continue;
00415       }
00416 
00417       // If a's Op is "EQ_ANY" that's enough   
00418       if (a->getOp() == NRAttribute::EQ_ANY){
00419         found_attr = true;
00420         break;
00421       }
00422 
00423       found_attr = false;
00424 
00425       switch (a->getOp()){
00426 
00427          case NRAttribute::EQ:
00428 
00429            if (b->isEQ(a))
00430              found_attr = true;
00431 
00432            break;
00433 
00434       case NRAttribute::GT:
00435 
00436         if (b->isGT(a))
00437           found_attr = true;
00438 
00439         break;
00440 
00441       case NRAttribute::GE:
00442 
00443         if (b->isGE(a))
00444           found_attr = true;
00445 
00446         break;
00447 
00448       case NRAttribute::LT:
00449 
00450         if (b->isLT(a))
00451           found_attr = true;
00452 
00453         break;
00454 
00455       case NRAttribute::LE:
00456 
00457         if (b->isLE(a))
00458           found_attr = true;
00459 
00460         break;
00461 
00462       case NRAttribute::NE:
00463 
00464         if (b->isNE(a))
00465           found_attr = true;
00466 
00467         break;
00468 
00469       default:
00470 
00471         DiffPrint(DEBUG_ALWAYS, "Unknown operator found in OneWayMacth !\n");
00472         break;
00473       }
00474 
00475       if (found_attr)
00476         break;
00477 
00478       itr2++;
00479     }
00480   }
00481 
00482   // All attributes found !
00483   return true;
00484 }

Here is the call graph for this function:

bool OneWayPerfectMatch NRAttrVec attr_vec1,
NRAttrVec attr_vec2
 

Definition at line 345 of file attrs.cc.

References NRAttribute::find_matching_key_from(), NRAttribute::getOp(), and NRAttribute::isEQ().

Referenced by PerfectMatch().

00346 {
00347   NRAttrVec::iterator itr1, itr2;
00348   NRAttribute *a;
00349   NRAttribute *b;
00350 
00351   for (itr1 = attr_vec1->begin(); itr1 != attr_vec1->end(); ++itr1){
00352 
00353     // For each attribute in vec1, we look in vec2 for the same attr
00354     a = *itr1;
00355     itr2 = attr_vec2->begin();
00356     b = a->find_matching_key_from(attr_vec2, itr2, &itr2);
00357 
00358     while (b){
00359       // They should have the same operator and be "EQUAL"
00360       if (a->getOp() == b->getOp())
00361         if (a->isEQ(b))
00362           break;
00363 
00364       // Keys match but value/operator don't. Let's
00365       // Try to find another attribute with the same key
00366       itr2++;
00367       b = a->find_matching_key_from(attr_vec2, itr2, &itr2);
00368     }
00369 
00370     // Check if attribute found
00371     if (b == NULL)
00372       return false;
00373   }
00374 
00375   // All attributes match !
00376   return true;
00377 }

Here is the call graph for this function:

int PackAttrs NRAttrVec attr_vec,
char *  start_pos
 

Definition at line 213 of file attrs.cc.

References NRAttribute::getGenericVal(), NRAttribute::getKey(), NRAttribute::getLen(), NRAttribute::getOp(), NRAttribute::getType(), int32_t, NRAttribute::INT32_TYPE, PackedAttribute::key_, PackedAttribute::len_, PackedAttribute::op_, PackedAttribute::type_, and PackedAttribute::val_.

Referenced by DiffusionRouting::sendMessageToDiffusion(), DiffusionCoreAgent::sendMessageToLibrary(), and DiffusionCoreAgent::sendMessageToNetwork().

00214 {
00215   PackedAttribute *current;
00216   NRAttrVec::iterator itr;
00217   NRAttribute *temp;
00218   int32_t t;
00219   char *pos;
00220   int pad, attr_len;
00221   int total_len = 0;
00222 
00223   current = (PackedAttribute *) start_pos;
00224 
00225   for (itr = attr_vec->begin(); itr != attr_vec->end(); ++itr){
00226     temp = *itr;
00227     current->key_ = htonl(temp->getKey());
00228     current->type_ = temp->getType();
00229     current->op_ = temp->getOp();
00230     attr_len = temp->getLen();
00231     current->len_ = htons(attr_len);
00232     if (attr_len > 0){
00233       switch (current->type_){
00234       case NRAttribute::INT32_TYPE:
00235 
00236         t = htonl(((NRSimpleAttribute<int> *)temp)->getVal());
00237         memcpy(&current->val_, &t, sizeof(int32_t));
00238 
00239         break;
00240 
00241       default:
00242 
00243         memcpy(&current->val_, temp->getGenericVal(), attr_len);
00244 
00245         break;
00246       }
00247     }
00248 
00249     // We have to pad in order to avoid bus errors
00250     pad = 0;
00251     if (attr_len % sizeof(int)){
00252       pad = sizeof(int) - (attr_len % sizeof(int));
00253     }
00254     total_len = total_len + sizeof(PackedAttribute) - sizeof(int32_t) + attr_len + pad;
00255     pos = (char *) current + sizeof(PackedAttribute) - sizeof(int32_t) + attr_len + pad;
00256     current = (PackedAttribute *) pos;
00257   }
00258   return total_len;
00259 }

Here is the call graph for this function:

bool PerfectMatch NRAttrVec attr_vec1,
NRAttrVec attr_vec2
 

Definition at line 333 of file attrs.cc.

References OneWayPerfectMatch().

Referenced by GradientFilter::findMatchingSubscription(), GradientFilter::findRoutingEntry(), and DiffusionCoreAgent::processControlMessage().

00334 {
00335   if (attr_vec1->size() != attr_vec2->size())
00336     return false;
00337 
00338   if (OneWayPerfectMatch(attr_vec1, attr_vec2))
00339     if (OneWayPerfectMatch(attr_vec2, attr_vec1))
00340       return true;
00341 
00342   return false;
00343 }

Here is the call graph for this function:

void PrintAttrs NRAttrVec attr_vec  ) 
 

Definition at line 131 of file attrs.cc.

References NRAttribute::BLOB_TYPE, DEBUG_ALWAYS, DiffPrint(), NRAttribute::FLOAT32_TYPE, NRAttribute::FLOAT64_TYPE, NRAttribute::getKey(), NRAttribute::getLen(), NRAttribute::getOp(), NRAttribute::getType(), NRAttribute::INT32_TYPE, and NRAttribute::STRING_TYPE.

Referenced by PushReceiverApp::recv(), and PingReceiverApp::recv().

00132 {
00133   NRAttrVec::iterator itr;
00134   NRAttribute *aux;
00135   int counter = 0;
00136 
00137   for (itr = attr_vec->begin(); itr != attr_vec->end(); ++itr){
00138     aux = *itr;
00139     DiffPrint(DEBUG_ALWAYS, "Attribute #%d\n", counter);
00140     counter++;
00141     DiffPrint(DEBUG_ALWAYS, "-------------\n");
00142     DiffPrint(DEBUG_ALWAYS, "Type = %d\n", aux->getType());
00143     DiffPrint(DEBUG_ALWAYS, "Key  = %d\n", aux->getKey());
00144     DiffPrint(DEBUG_ALWAYS, "Op   = %d\n", aux->getOp());
00145     DiffPrint(DEBUG_ALWAYS, "Len  = %d\n", aux->getLen());
00146     switch(aux->getType()){
00147     case NRAttribute::INT32_TYPE:
00148       DiffPrint(DEBUG_ALWAYS, "Val  = %d\n",
00149                 ((NRSimpleAttribute<int> *)aux)->getVal());
00150       break;
00151     case NRAttribute::FLOAT32_TYPE:
00152       DiffPrint(DEBUG_ALWAYS, "Val  = %f\n",
00153                 ((NRSimpleAttribute<float> *)aux)->getVal());
00154       break;
00155     case NRAttribute::FLOAT64_TYPE:
00156       DiffPrint(DEBUG_ALWAYS, "Val  = %f\n",
00157                 ((NRSimpleAttribute<double> *)aux)->getVal());
00158       break;
00159     case NRAttribute::STRING_TYPE:
00160       DiffPrint(DEBUG_ALWAYS, "Val  = %s\n",
00161                 ((NRSimpleAttribute<char *> *)aux)->getVal());
00162       break;
00163     case NRAttribute::BLOB_TYPE:
00164       DiffPrint(DEBUG_ALWAYS, "Val  = %s\n",
00165                 ((NRSimpleAttribute<void *> *)aux)->getVal());
00166       break;
00167     default:
00168       DiffPrint(DEBUG_ALWAYS, "Val  = Unknown\n");
00169       break;
00170     }
00171     DiffPrint(DEBUG_ALWAYS, "\n");
00172   }
00173 }

Here is the call graph for this function:

NRAttrVec* UnpackAttrs DiffPacket  pkt,
int  num_attr
 

Definition at line 261 of file attrs.cc.

References NRAttribute::BLOB_TYPE, DEBUG_ALWAYS, DiffPrint(), NRAttribute::FLOAT32_TYPE, NRAttribute::FLOAT64_TYPE, int32_t, NRAttribute::INT32_TYPE, PackedAttribute::key_, PackedAttribute::len_, PackedAttribute::op_, NRAttribute::STRING_TYPE, PackedAttribute::type_, and PackedAttribute::val_.

Referenced by DiffusionRouting::recvPacket(), and DiffusionCoreAgent::recvPacket().

00262 {
00263   PackedAttribute *current;
00264   NRAttrVec *attr_vec;
00265   int attr_len;
00266   char *pos;
00267   int pad;
00268 
00269   attr_vec = new NRAttrVec;
00270 
00271   pos = (char *) &pkt[0];
00272   current = (PackedAttribute *) (pos + sizeof(struct hdr_diff));
00273 
00274   for (int i = 0; i < num_attr; i++){
00275     switch (current->type_){
00276     case NRAttribute::INT32_TYPE:
00277       attr_vec->push_back(new NRSimpleAttribute<int>(ntohl(current->key_),
00278                                                 NRAttribute::INT32_TYPE,
00279                                                 current->op_,
00280                                                 ntohl(*(int *)&current->val_)));
00281       break;
00282 
00283     case NRAttribute::FLOAT32_TYPE:
00284       attr_vec->push_back(new NRSimpleAttribute<float>(ntohl(current->key_),
00285                                                 NRAttribute::FLOAT32_TYPE,
00286                                                 current->op_,
00287                                                 *(float *)&current->val_));
00288       break;
00289 
00290     case NRAttribute::FLOAT64_TYPE:
00291       attr_vec->push_back(new NRSimpleAttribute<double>(ntohl(current->key_),
00292                                              NRAttribute::FLOAT64_TYPE,
00293                                              current->op_,
00294                                              *(double *)&current->val_));
00295       break;
00296 
00297     case NRAttribute::STRING_TYPE:
00298       attr_vec->push_back(new NRSimpleAttribute<char *>(ntohl(current->key_),
00299                                             NRAttribute::STRING_TYPE,
00300                                             current->op_,
00301                                             (char *)&current->val_));
00302       break;
00303 
00304     case NRAttribute::BLOB_TYPE:
00305       attr_vec->push_back(new NRSimpleAttribute<void *>(ntohl(current->key_),
00306                                           NRAttribute::BLOB_TYPE,
00307                                           current->op_,
00308                                           (void *)&current->val_,
00309                                           ntohs(current->len_)));
00310       break;
00311 
00312     default:
00313 
00314       DiffPrint(DEBUG_ALWAYS, "Unknown attribute type found in UnpackAttrs() !\n");
00315       break;
00316     }
00317 
00318     attr_len = ntohs(current->len_);
00319 
00320     pad = 0;
00321     if (attr_len % sizeof(int)){
00322       // We have to calculate how much 'padding' to skip in order to
00323       // avoid bus errors
00324       pad = sizeof(int) - (attr_len % sizeof(int));
00325     }
00326     pos = (char *) current + sizeof(PackedAttribute) - sizeof(int32_t) + attr_len + pad;
00327     current = (PackedAttribute *) pos;
00328   }
00329 
00330   return attr_vec;
00331 }

Here is the call graph for this function:


Generated on Tue Apr 20 12:15:42 2004 for NS2.26SourcesOriginal by doxygen 1.3.3