BasicDSCPClassifier.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2005 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 
00019 #include <omnetpp.h>
00020 #include "BasicDSCPClassifier.h"
00021 #include "IPDatagram.h"
00022 #ifndef WITHOUT_IPv6
00023 #include "IPv6Datagram.h"
00024 #endif
00025 
00026 Register_Class(BasicDSCPClassifier);
00027 
00028 #define BEST_EFFORT 1
00029 
00030 int BasicDSCPClassifier::getNumQueues()
00031 {
00032     return 2;
00033 }
00034 
00035 int BasicDSCPClassifier::classifyPacket(cMessage *msg)
00036 {
00037     if (dynamic_cast<IPDatagram *>(msg))
00038     {
00039         // IPv4 QoS: map DSCP to queue number
00040         IPDatagram *datagram = (IPDatagram *)msg;
00041         int dscp = datagram->getDiffServCodePoint();
00042         return classifyByDSCP(dscp);
00043     }
00044 #ifndef WITHOUT_IPv6
00045     else if (dynamic_cast<IPv6Datagram *>(msg))
00046     {
00047         // IPv6 QoS: map Traffic Class to queue number
00048         IPv6Datagram *datagram = (IPv6Datagram *)msg;
00049         int dscp = datagram->getTrafficClass();
00050         return classifyByDSCP(dscp);
00051     }
00052 #endif
00053     else
00054     {
00055         return BEST_EFFORT; // lowest priority ("best effort")
00056     }
00057 }
00058 
00059 int BasicDSCPClassifier::classifyByDSCP(int dscp)
00060 {
00061     // DSCP is 6 bits, mask out all others
00062     dscp = (dscp & 0x3f);
00063 
00064     // DSCP format:
00065     //    xxxxx0: used by standards; see RFC 2474
00066     //    xxxxx1: experimental or local use
00067     // source: Stallings, High-Speed Networks, 2nd Ed, p494
00068 
00069     // all-zero DSCP maps to Best Effort (lowest priority)
00070     if (dscp==0)
00071         return BEST_EFFORT;
00072 
00073     // assume Best Effort service for experimental or local DSCP's too
00074     if (dscp & 1)
00075         return BEST_EFFORT;
00076 
00077     // from here on, we deal with non-zero standardized DSCP values only
00078     int upper3bits = (dscp & 0x3c) >> 3;
00079     //int lower3bits = (dscp & 0x07);  -- we'll ignore this
00080 
00081     // rfc 2474, section 4.2.2: at least two independently forwarded classes of traffic have to be created
00082     if (upper3bits & 0x04)
00083         return 0; // highest priority
00084     else
00085         return 1; // low priority (best effort)
00086 }
00087