[6822] | 1 | // [License]
|
---|
| 2 | // The Ariba-Underlay Copyright
|
---|
| 3 | //
|
---|
| 4 | // Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
|
---|
| 5 | //
|
---|
| 6 | // Institute of Telematics
|
---|
| 7 | // UniversitÀt Karlsruhe (TH)
|
---|
| 8 | // Zirkel 2, 76128 Karlsruhe
|
---|
| 9 | // Germany
|
---|
| 10 | //
|
---|
| 11 | // Redistribution and use in source and binary forms, with or without
|
---|
| 12 | // modification, are permitted provided that the following conditions are
|
---|
| 13 | // met:
|
---|
| 14 | //
|
---|
| 15 | // 1. Redistributions of source code must retain the above copyright
|
---|
| 16 | // notice, this list of conditions and the following disclaimer.
|
---|
| 17 | // 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 18 | // notice, this list of conditions and the following disclaimer in the
|
---|
| 19 | // documentation and/or other materials provided with the distribution.
|
---|
| 20 | //
|
---|
| 21 | // THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
|
---|
| 22 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 23 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
| 24 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
|
---|
| 25 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
| 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
| 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
| 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
---|
| 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
---|
| 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
| 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 32 | //
|
---|
| 33 | // The views and conclusions contained in the software and documentation
|
---|
| 34 | // are those of the authors and should not be interpreted as representing
|
---|
| 35 | // official policies, either expressed or implied, of the Institute of
|
---|
| 36 | // Telematics.
|
---|
| 37 | // [License]
|
---|
| 38 |
|
---|
| 39 | #include "DddVis.h"
|
---|
| 40 |
|
---|
| 41 | namespace ariba {
|
---|
| 42 | namespace utility {
|
---|
| 43 |
|
---|
| 44 | const string DddVis::del = ":";
|
---|
| 45 | use_logging_cpp(DddVis);
|
---|
| 46 |
|
---|
| 47 | DddVis::DddVis() : commandid(0) {
|
---|
| 48 | srand(time(NULL));
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | DddVis::~DddVis(){
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | void DddVis::sendMessage( const string msg, NETWORK_ID nid ) {
|
---|
| 55 | sendSocket( msg + "\n" );
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | long DddVis::getCommandID() {
|
---|
| 59 | return ++commandid;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | long DddVis::getTimestamp() {
|
---|
| 63 | return 0; //time(NULL);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | unsigned int DddVis::getNodeNumber(const NodeID& node){
|
---|
| 67 | NodeSet::iterator i = nodeSet.find(node);
|
---|
| 68 |
|
---|
| 69 | if(i == nodeSet.end()){
|
---|
| 70 | unsigned int number = node.get(MAX_KEYLENGTH-16, 16);
|
---|
| 71 | nodeSet.insert(make_pair(node, number));
|
---|
| 72 | return number;
|
---|
| 73 | } else {
|
---|
| 74 | return i->second;
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void DddVis::visCreate(
|
---|
| 79 | NETWORK_ID network,
|
---|
| 80 | NodeID& node,
|
---|
| 81 | string nodename,
|
---|
| 82 | string info
|
---|
| 83 | ){
|
---|
| 84 | //
|
---|
| 85 | // create layer first if not already done
|
---|
| 86 | //
|
---|
| 87 |
|
---|
| 88 | if(layerSet.find(network) == layerSet.end()){
|
---|
| 89 |
|
---|
| 90 | //
|
---|
| 91 | // create layer
|
---|
| 92 | //
|
---|
| 93 |
|
---|
| 94 | {
|
---|
| 95 | ostringstream out;
|
---|
| 96 | out << CREATE_LAYER_TYPE << del
|
---|
| 97 | << getCommandID() << del
|
---|
| 98 | << getTimestamp() << del
|
---|
| 99 | << getNetworkName(network) << del
|
---|
| 100 | << 0 << del;
|
---|
| 101 |
|
---|
| 102 | sendMessage( out.str(), network );
|
---|
| 103 | layerSet.insert(network);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | //
|
---|
| 107 | // set layer layout
|
---|
| 108 | //
|
---|
| 109 |
|
---|
| 110 | {
|
---|
| 111 | LayoutType layout = FORCE_LAYOUT;
|
---|
| 112 | LayoutOrderStrategie order = ORDER_RANDOMLY;
|
---|
| 113 |
|
---|
| 114 | switch(network){
|
---|
| 115 | case NETWORK_ID_BASE_COMMUNICATION:
|
---|
| 116 | layout = FORCE_LAYOUT;
|
---|
| 117 | order = ORDER_RANDOMLY;
|
---|
| 118 | break;
|
---|
| 119 | case NETWORK_ID_BASE_OVERLAY:
|
---|
| 120 | layout = CIRCULAR_LAYOUT;
|
---|
| 121 | order = ORDER_BY_ID;
|
---|
| 122 | break;
|
---|
| 123 | case NETWORK_ID_MCPO:
|
---|
| 124 | layout = FORCE_LAYOUT;
|
---|
| 125 | order = ORDER_RANDOMLY;
|
---|
| 126 | break;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | ostringstream out;
|
---|
| 130 | out << SET_CLUSTER_LAYOUT_TYPE << del
|
---|
| 131 | << getCommandID() << del
|
---|
| 132 | << getTimestamp() << del
|
---|
| 133 | << getNetworkName(network) << del
|
---|
| 134 | << 0 << del
|
---|
| 135 | << layout << del
|
---|
| 136 | << order << del;
|
---|
| 137 |
|
---|
| 138 | sendMessage( out.str(), network );
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | } // if(layerSet.find(network) == layerSet.end())
|
---|
| 142 |
|
---|
| 143 | //
|
---|
| 144 | // create node
|
---|
| 145 | //
|
---|
| 146 |
|
---|
| 147 | ostringstream out;
|
---|
| 148 | out << CREATE_NODE_TYPE << del
|
---|
| 149 | << getCommandID() << del
|
---|
| 150 | << getTimestamp() << del
|
---|
| 151 | << getNetworkName(network) << del
|
---|
| 152 | << 0 << del
|
---|
| 153 | << getNodeNumber(node) << del
|
---|
| 154 | << 0x00000000 << del
|
---|
| 155 | << "null" << del;
|
---|
| 156 |
|
---|
| 157 | sendMessage( out.str(), network );
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | void DddVis::visConnect(
|
---|
| 161 | NETWORK_ID network,
|
---|
| 162 | NodeID& srcnode,
|
---|
| 163 | NodeID& destnode,
|
---|
| 164 | string info
|
---|
| 165 | ){
|
---|
| 166 | // if we already have a link between the two nodes
|
---|
| 167 | // we just ignore the call and leave the old link
|
---|
| 168 |
|
---|
| 169 | if( networkLinks.exists( network, NodePair(srcnode,destnode) )) return;
|
---|
| 170 |
|
---|
| 171 | ostringstream out;
|
---|
| 172 | unsigned long edgekey = networkLinks.insert( network, NodePair(srcnode,destnode) );
|
---|
| 173 |
|
---|
| 174 | out << CREATE_EDGE_TYPE << del
|
---|
| 175 | << getCommandID() << del
|
---|
| 176 | << getTimestamp() << del
|
---|
| 177 | << getNetworkName(network) << del
|
---|
| 178 | << 0 << del
|
---|
| 179 | << getNodeNumber(srcnode) << del
|
---|
| 180 | << getNodeNumber(destnode) << del
|
---|
| 181 | << edgekey << del
|
---|
| 182 | << 0x00000000 << del
|
---|
| 183 | << "null" << del;
|
---|
| 184 |
|
---|
| 185 | sendMessage( out.str(), network );
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | void DddVis::visDisconnect(
|
---|
| 189 | NETWORK_ID network,
|
---|
| 190 | NodeID& srcnode,
|
---|
| 191 | NodeID& destnode,
|
---|
| 192 | string info
|
---|
| 193 | ){
|
---|
| 194 | if( !networkLinks.exists(network, NodePair(srcnode, destnode)) ) return;
|
---|
| 195 |
|
---|
| 196 | unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
|
---|
| 197 | networkLinks.remove( network, NodePair(srcnode, destnode) );
|
---|
| 198 |
|
---|
| 199 | ostringstream out;
|
---|
| 200 | out << REMOVE_EDGE_TYPE << del
|
---|
| 201 | << getCommandID() << del
|
---|
| 202 | << getTimestamp() << del
|
---|
| 203 | << getNetworkName(network) << del
|
---|
| 204 | << edgekey << del;
|
---|
| 205 |
|
---|
| 206 | sendMessage( out.str(), network );
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | void DddVis::visShutdown(
|
---|
| 210 | NETWORK_ID network,
|
---|
| 211 | NodeID& node,
|
---|
| 212 | string info
|
---|
| 213 | ){
|
---|
| 214 | ostringstream out;
|
---|
| 215 |
|
---|
| 216 | out << REMOVE_NODE_TYPE << del
|
---|
| 217 | << getCommandID() << del
|
---|
| 218 | << getTimestamp() << del
|
---|
| 219 | << getNetworkName(network) << del
|
---|
| 220 | << getNodeNumber(node) << del;
|
---|
| 221 |
|
---|
| 222 | sendMessage( out.str(), network );
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | void DddVis::visChangeNodeColor (
|
---|
| 226 | NETWORK_ID network,
|
---|
| 227 | NodeID& node,
|
---|
| 228 | unsigned char r,
|
---|
| 229 | unsigned char g,
|
---|
| 230 | unsigned char b
|
---|
| 231 | ){
|
---|
| 232 | ostringstream out;
|
---|
| 233 |
|
---|
| 234 | out << SET_NODE_COLOR_TYPE << del
|
---|
| 235 | << getCommandID() << del
|
---|
| 236 | << getTimestamp() << del
|
---|
| 237 | << getNetworkName(network) << del
|
---|
| 238 | << getNodeNumber(node) << del
|
---|
| 239 | << makeColor(r, g, b) << del;
|
---|
| 240 |
|
---|
| 241 | sendMessage( out.str(), network );
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | int DddVis::makeColor(unsigned char r, unsigned char g, unsigned char b){
|
---|
| 245 | return ((r<<16)+(g<<8)+b);
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | void DddVis::visChangeNodeColor (
|
---|
| 249 | NETWORK_ID network,
|
---|
| 250 | NodeID& node,
|
---|
| 251 | NODE_COLORS color
|
---|
| 252 | ){
|
---|
| 253 | unsigned char r = 0;
|
---|
| 254 | unsigned char g = 0;
|
---|
| 255 | unsigned char b = 0;
|
---|
| 256 |
|
---|
| 257 | switch( color ) {
|
---|
| 258 | case NODE_COLORS_GREY: r = 128; g = 128; b = 128; break;
|
---|
| 259 | case NODE_COLORS_GREEN: r = 0; g = 200; b = 0; break;
|
---|
| 260 | case NODE_COLORS_RED: r = 255; g = 0; b = 0; break;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | visChangeNodeColor( network, node, r, g, b );
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | void DddVis::visChangeLinkColor (
|
---|
| 267 | NETWORK_ID network,
|
---|
| 268 | NodeID& srcnode,
|
---|
| 269 | NodeID& destnode,
|
---|
| 270 | unsigned char r,
|
---|
| 271 | unsigned char g,
|
---|
| 272 | unsigned char b
|
---|
| 273 | ){
|
---|
| 274 | ostringstream out;
|
---|
| 275 | unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
|
---|
| 276 |
|
---|
| 277 | out << SET_EDGE_COLOR_TYPE << del
|
---|
| 278 | << getCommandID() << del
|
---|
| 279 | << getTimestamp() << del
|
---|
| 280 | << getNetworkName(network) << del
|
---|
| 281 | << edgekey << del
|
---|
| 282 | << makeColor(r, g, b) << del;
|
---|
| 283 |
|
---|
| 284 | sendMessage( out.str(), network );
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | void DddVis::visChangeLinkColor (
|
---|
| 288 | NETWORK_ID network,
|
---|
| 289 | NodeID& srcnode,
|
---|
| 290 | NodeID& destnode,
|
---|
| 291 | NODE_COLORS color
|
---|
| 292 | ){
|
---|
| 293 | unsigned char r = 0;
|
---|
| 294 | unsigned char g = 0;
|
---|
| 295 | unsigned char b = 0;
|
---|
| 296 |
|
---|
| 297 | switch( color ) {
|
---|
| 298 | case NODE_COLORS_GREY: r = 128; g = 128; b = 128; break;
|
---|
| 299 | case NODE_COLORS_GREEN: r = 0; g = 200; b = 0; break;
|
---|
| 300 | case NODE_COLORS_RED: r = 255; g = 0; b = 0; break;
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | visChangeLinkColor( network, srcnode, destnode, r, g, b );
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | }} // namespace ariba, common
|
---|