|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2004 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 "ProtocolMap.h" 00021 00022 00023 void ProtocolMapping::parseProtocolMapping(const char *s) 00024 { 00025 while (isspace(*s)) s++; 00026 00027 while (*s) 00028 { 00029 Entry entry; 00030 00031 if (!isdigit(*s)) 00032 throw cRuntimeError("syntax error: protocol number expected"); 00033 entry.protocolNumber = atoi(s); 00034 while (isdigit(*s)) s++; 00035 00036 if (*s++!=':') 00037 throw cRuntimeError("syntax error: colon expected"); 00038 00039 while (isspace(*s)) s++; 00040 if (!isdigit(*s)) 00041 throw cRuntimeError("syntax error in script: output gate index expected"); 00042 entry.outGateIndex = atoi(s); 00043 while (isdigit(*s)) s++; 00044 00045 // add 00046 entries.push_back(entry); 00047 00048 // skip delimiter 00049 while (isspace(*s)) s++; 00050 if (!*s) break; 00051 if (*s++!=',') 00052 throw cRuntimeError("syntax error: comma expected"); 00053 while (isspace(*s)) s++; 00054 } 00055 00056 } 00057 00058 int ProtocolMapping::getOutputGateForProtocol(int protocol) 00059 { 00060 for (Entries::iterator i=entries.begin();i!=entries.end();++i) 00061 if (i->protocolNumber==protocol) 00062 return i->outGateIndex; 00063 opp_error("No output gate defined in protocolMapping for protocol number %d", protocol); 00064 return -1; 00065 } 00066