IBR-DTNSuite  0.10
StaticRouteChangeEvent.cpp
Go to the documentation of this file.
1 /*
2  * StaticRouteChangeEvent.cpp
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
23 #include "core/EventDispatcher.h"
24 #include <sstream>
25 
26 namespace dtn
27 {
28  namespace routing
29  {
30  StaticRouteChangeEvent::StaticRouteChangeEvent(CHANGE_TYPE t)
31  : type(t), nexthop(), pattern(), timeout(0)
32  {
33  }
34 
35  StaticRouteChangeEvent::StaticRouteChangeEvent(CHANGE_TYPE t, const dtn::data::EID &n, const std::string &p, const dtn::data::Number &to)
36  : type(t), nexthop(n), pattern(p), timeout(to)
37  {
38  }
39 
40  StaticRouteChangeEvent::StaticRouteChangeEvent(CHANGE_TYPE t, const dtn::data::EID &n, const dtn::data::EID &d, const dtn::data::Number &to)
41  : type(t), nexthop(n), destination(d), timeout(to)
42  {
43  }
44 
46  {
47  }
48 
49  const std::string StaticRouteChangeEvent::getName() const
50  {
52  }
53 
55  {
56  std::stringstream ss;
57 
58  switch (type)
59  {
60  case ROUTE_ADD:
61  ss << "add route ";
62 
63  if (pattern.length() > 0)
64  {
65  ss << pattern;
66  }
67  else
68  {
69  ss << destination.getString();
70  }
71 
72  ss << " => " << nexthop.getString();
73  if (timeout > 0) ss << "; timeout = " << timeout.toString();
74  break;
75  case ROUTE_DEL:
76  ss << "del route ";
77 
78  if (pattern.length() > 0)
79  {
80  ss << pattern;
81  }
82  else
83  {
84  ss << destination.getString();
85  }
86 
87  ss << " => " << nexthop.getString();
88  break;
89  case ROUTE_EXPIRED:
90  ss << "route expired";
91  break;
92  case ROUTE_CLEAR:
93  ss << "routes cleared";
94  break;
95  default:
96  ss << "unknown";
97  break;
98  }
99 
100  return ss.str();
101  }
102 
104  {
106  }
107 
108  void StaticRouteChangeEvent::raiseEvent(CHANGE_TYPE t, const dtn::data::EID &n, const std::string &p, const dtn::data::Number &to)
109  {
111  }
112 
114  {
116  }
117 
118  const string StaticRouteChangeEvent::className = "StaticRouteChangeEvent";
119  } /* namespace routing */
120 } /* namespace dtn */