Menu

Attributes.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2008-2010 Michael Schulze <mschulze@ivs.cs.uni-magdeburg.de>
00004  *               2009-2010 Michael Kriese <kriese@cs.uni-magdeburg.de>
00005  * All rights reserved.
00006  *
00007  *    Redistribution and use in source and binary forms, with or without
00008  *    modification, are permitted provided that the following conditions
00009  *    are met:
00010  *
00011  *    * Redistributions of source code must retain the above copyright
00012  *      notice, this list of conditions and the following disclaimer.
00013  *
00014  *    * Redistributions in binary form must reproduce the above copyright
00015  *      notice, this list of conditions and the following disclaimer in
00016  *      the documentation and/or other materials provided with the
00017  *      distribution.
00018  *
00019  *    * Neither the name of the copyright holders nor the names of
00020  *      contributors may be used to endorse or promote products derived
00021  *      from this software without specific prior written permission.
00022  *
00023  *
00024  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00025  *    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026  *    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027  *    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00028  *    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00029  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00030  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00031  *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00032  *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00033  *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  *
00037  * $Id$
00038  *
00039  ******************************************************************************/
00040 
00041 #ifndef _Attributes_h_
00042 #define _Attributes_h_
00043 
00044 #include <boost/mpl/list.hpp>
00045 #include "mw/attributes/tags/IntegralConstTag.h"
00046 #include "mw/attributes/Attribute.h"
00047 #include "mw/attributes/AttributeSet.h"
00048 #include "mw/attributes/TTL.h"
00049 #include "mw/attributes/Latency.h"
00050 #include "mw/attributes/Throughput.h"
00051 #include "mw/attributes/PacketLoss.h"
00052 #include "mw/attributes/filter/find.h"
00053 #include "mw/attributes/detail/AttributeSetProvider.h"
00054 #include "mw/attributes/detail/tags/TagSet.h"
00055 #include "mw/attributes/detail/tags/HasLessThanRelation.h"
00056 #include "mw/nl/awds/logging.h"
00057 #include "mw/nl/awds/FlowId.h"
00058 
00059 #ifdef RANDOM_ATTRIBUTES
00060 #include <cstdlib>
00061 #endif
00062 
00063 namespace famouso {
00064     namespace mw {
00065         namespace nl {
00066             namespace awds {
00071                 namespace detail {
00072 
00073                     using namespace famouso::mw::attributes;
00074                     using famouso::mw::attributes::detail::HighDensityIDs;
00075 
00082                     struct FlowMgmtIDs {
00083                             enum {
00084                                 action = 1, 
00085                                 flowId = action + 1, 
00086                                 subject = flowId + 1, 
00087                                 prio = subject + 1
00089                             };
00090                     };
00091 
00094                     struct FlowMgmtActionIDs {
00095                             enum {
00096                                 reg = 1, 
00097                                 free = 2, 
00098                                 dead = 3, 
00099                                 use = 4, 
00100                                 avail = 5, 
00101                                 max
00103                             };
00104                     };
00105 
00112                     template< FlowId id >
00113                     class FlowMgmtID: public Attribute<FlowMgmtID<0> , tags::integral_const_tag, FlowId, id,
00114                                     FlowMgmtIDs::flowId,
00115                                     attributes::detail::TagSet<attributes::detail::HasLessThanRelation> > {
00116                         public:
00117                             typedef FlowMgmtID type;
00118                     };
00119 
00126                     template< uint8_t action >
00127                     class FlowMgmtAction: public Attribute<FlowMgmtAction<0> , tags::integral_const_tag, uint8_t, action,
00128                                     FlowMgmtIDs::action,
00129                                     attributes::detail::TagSet<attributes::detail::HasLessThanRelation> > {
00130                         public:
00131                             typedef FlowMgmtAction type;
00132                     };
00133 
00138                     template< uint64_t snn >
00139                     class SubjectAttribute: public Attribute<SubjectAttribute<0> , tags::integral_const_tag, uint64_t, snn,
00140                                     FlowMgmtIDs::subject,
00141                                     attributes::detail::TagSet<attributes::detail::HasLessThanRelation> > {
00142                         public:
00143                             typedef SubjectAttribute type;
00144 
00149                             Subject subject() {
00150                                 return Subject(this->getValue());
00151                             }
00152 
00157                             void subject(Subject s) {
00158                                 this->setValue(s.value());
00159                             }
00160                     };
00161 
00168                     template< int8_t prio >
00169                     class Priority: public Attribute<Priority<0> , tags::integral_const_tag, int8_t, prio,
00170                                     FlowMgmtIDs::prio,
00171                                     attributes::detail::TagSet<attributes::detail::HasLessThanRelation> > {
00172                         public:
00173                             typedef Priority type;
00174                     };
00175 
00176                 } // namespace detail
00177 
00178                 using famouso::mw::attributes::detail::SetProvider;
00179 
00181                 typedef famouso::mw::attributes::TTL<0xFF> TTL;
00182 
00184                 typedef famouso::mw::attributes::Latency<0xFFFFFFFF> Latency;
00185 
00187                 typedef famouso::mw::attributes::Throughput<0xFFFFFFFF> Throughput;
00188 
00190                 typedef famouso::mw::attributes::PacketLoss<0xFFFF> PacketLoss;
00191 
00193                 typedef SetProvider<TTL, Latency, Throughput, PacketLoss>::attrSet AWDSAttributeSet;
00194 
00196                 typedef detail::FlowMgmtID<0xFFFFFFFF> FlowMgmtID;
00197 
00199                 typedef detail::FlowMgmtActionIDs FlowMgmtActionIDs;
00200 
00202                 typedef detail::FlowMgmtAction<FlowMgmtActionIDs::max> FlowMgmtAction;
00203 
00205                 typedef detail::SubjectAttribute<0xFFFFFFFFFFFFFFFFull> SubjectAttribute;
00206 
00208                 typedef detail::Priority<0xFF> Priority;
00209 
00211                 typedef SetProvider<FlowMgmtAction, SubjectAttribute, FlowMgmtID, Throughput, Priority>::attrSet FlowMgmtRequestAttributeSet;
00212 
00214                 typedef SetProvider<FlowMgmtAction, SubjectAttribute, FlowMgmtID>::attrSet FlowMgmtResponseAttributeSet;
00215 
00216 #ifdef RANDOM_ATTRIBUTES
00217 
00221                 inline void _createAttrSet(uint8_t *data) {
00222 
00223                     switch (rand() % 11) {
00224                         case 0: {
00225                             new (data) SetProvider<TTL>::attrSet;
00226                             break;
00227                         }
00228                         case 1: {
00229                             new (data) SetProvider<Throughput>::attrSet;
00230                             break;
00231                         }
00232                         case 2: {
00233                             new (data) SetProvider<Latency>::attrSet;
00234                             break;
00235                         }
00236                         case 3: {
00237                             new (data) SetProvider<PacketLoss>::attrSet;
00238                             break;
00239                         }
00240                         case 4: {
00241                             new (data) SetProvider<TTL, PacketLoss>::attrSet;
00242                             break;
00243                         }
00244                         case 5: {
00245                             new (data) SetProvider<TTL, Throughput>::attrSet;
00246                             break;
00247                         }
00248                         case 6: {
00249                             new (data) SetProvider<TTL, Latency>::attrSet;
00250                             break;
00251                         }
00252                         case 7: {
00253                             new (data) SetProvider<Latency, PacketLoss>::attrSet;
00254                             break;
00255                         }
00256                         case 8: {
00257                             new (data) SetProvider<TTL, Throughput, PacketLoss>::attrSet;
00258                             break;
00259                         }
00260                         case 9: {
00261                             new (data) SetProvider<TTL, Latency, PacketLoss>::attrSet;
00262                             break;
00263                         }
00264                         default:
00265                             break;
00266                     }
00267                 }
00268 
00273                 inline AWDSAttributeSet::type createRandAttributes() {
00274                     AWDSAttributeSet::type res;
00275                     _createAttrSet(reinterpret_cast<uint8_t *> (&res));
00276 
00277                     TTL *ttl = res.find<TTL> ();
00278                     if (ttl)
00279                         ttl->set(rand() % 20 + 1);
00280 
00281                     Latency *l = res.find<Latency> ();
00282                     if (l)
00283                         l->set(rand() % 50 + 20);
00284 
00285                     Throughput *b = res.find<Throughput> ();
00286                     if (b)
00287                         b->set((rand() % 1000 + 1000));
00288 
00289                     PacketLoss *p = res.find<PacketLoss> ();
00290                     if (p)
00291                         p->set(rand() % 20 + 1);
00292 
00293                     return res;
00294                 }
00295 #endif
00296 
00297             } /* awds */
00298         } /* nl */
00299     } /* mw */
00300 } /* famouso */
00301 
00302 #endif /* _Attributes_h_ */