Skip to content

Commit 0204e8f

Browse files
committed
Merge branch 'develop'
Conflicts: README.md Resolution: An extra blank newline from develop. Removed - Nitin
2 parents b8b7831 + 8c6ee43 commit 0204e8f

File tree

3,426 files changed

+1022
-658
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,426 files changed

+1022
-658
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
core
1010
*~
1111
*.sw?
12-
!/visualizations/local_click/Visualizer.swf
12+
!/tools/visualizations/local_click/Visualizer.swf
13+
!/tools/visualizations/distributed_click/Visualizer.swf
1314
tags
1415
cscope.out
1516
*.o.cmd

api/dagaddr/cpp/dagaddr.cpp

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,65 @@
1818
@file dagaddr.cpp
1919
@brief Implements dagaddr library
2020
*/
21+
22+
2123
#include "dagaddr.hpp"
2224
#include "utils.hpp"
2325
#include <cstring>
24-
#include <cstdio>
2526
#include <map>
2627
#include <algorithm>
2728
#include <sys/socket.h>
2829
#include <netinet/in.h>
2930
#include <arpa/inet.h>
3031

31-
3232
static const std::size_t vector_find_npos = std::size_t(-1);
3333

34+
/*
35+
* load user defined XIDs for use in parsing and unparsing DAGs
36+
*/
37+
Node::XidMap Node::load_xids()
38+
{
39+
Node::XidMap ids;
40+
41+
char path[PATH_SIZE];
42+
char name[256], text[256];
43+
short id;
44+
unsigned len = sizeof(path);
45+
char *p;
46+
47+
if ((p = getenv("XIADIR")) != NULL) {
48+
strncpy(path, p, len);
49+
} else if (!getcwd(path, len)) {
50+
path[0] = 0;
51+
}
52+
53+
p = strstr(path, SOURCE_DIR);
54+
if (p) {
55+
p += sizeof(SOURCE_DIR) - 1;
56+
*p = '\0';
57+
}
58+
strncat(path, "/etc/xids", len);
59+
60+
FILE *f = fopen(path, "r");
61+
if (f) {
62+
while (!feof(f)) {
63+
if (fgets(text, sizeof(text), f)) {
64+
if (sscanf(text, "%hi %s", &id, name) == 2) {
65+
ids[id] = name;
66+
}
67+
}
68+
}
69+
fclose(f);
70+
}
71+
72+
return ids;
73+
}
74+
75+
// call the load_xids function at init time to fill in the hash map
76+
Node::XidMap Node::xids = Node::load_xids();
77+
78+
79+
3480
template <typename T>
3581
static std::size_t
3682
vector_find(std::vector<T>& v, const T& e)
@@ -232,8 +278,23 @@ Node::construct_from_strings(const std::string type_str, const std::string id_st
232278
ptr_->type = XID_TYPE_DUMMY_SOURCE;
233279
else
234280
{
235-
ptr_->type = 0;
236-
printf("WARNING: Unrecognized XID type: %s\n", type_str.c_str());
281+
// see if it's a user defined XID
282+
XidMap::const_iterator itr;
283+
int found = 0;
284+
285+
for (itr = Node::xids.begin(); itr != Node::xids.end(); itr++) {
286+
287+
if (type_str == (*itr).second) {
288+
found = 1;
289+
ptr_->type = (*itr).first;
290+
break;
291+
}
292+
}
293+
294+
if (!found) {
295+
ptr_->type = 0;
296+
printf("WARNING: Unrecognized XID type: %s\n", type_str.c_str());
297+
}
237298
}
238299

239300
// If this is a 4ID formatted as an IP address (x.x.x.x), we
@@ -273,14 +334,16 @@ Node::construct_from_strings(const std::string type_str, const std::string id_st
273334
/**
274335
* @brief Return the node's type as a string
275336
*
276-
* @return The node's type as a string. Will be one of:
337+
* The type string will either be one of the following built-in XID types or will match
338+
* one of the entries in etc/xids.
277339
* \n Node::XID_TYPE_AD_STRING
278340
* \n Node::XID_TYPE_HID_STRING
279341
* \n Node::XID_TYPE_CID_STRING
280342
* \n Node::XID_TYPE_SID_STRING
281343
* \n Node::XID_TYPE_IP_STRING
282344
* \n Node::XID_TYPE_DUMMY_SOURCE
283345
* \n Node:: ID_TYPE_UNKNOWN_STRING
346+
* @return the node's type as a string
284347
*/
285348
std::string
286349
Node::type_string() const
@@ -300,7 +363,11 @@ Node::type_string() const
300363
case XID_TYPE_DUMMY_SOURCE:
301364
return XID_TYPE_DUMMY_SOURCE_STRING;
302365
default:
303-
return XID_TYPE_UNKNOWN_STRING;
366+
std::string s = xids[this->type()];
367+
if (s.empty())
368+
s = XID_TYPE_UNKNOWN_STRING;
369+
370+
return s;
304371
}
305372
}
306373

api/include/dagaddr.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
#pragma once
22

3+
#define PATH_SIZE 4096
4+
#include <unistd.h>
5+
#include <stdio.h>
6+
#include <string.h>
7+
#include <stdlib.h>
8+
9+
10+
311
#include <stdint.h> // for non-c++0x
412
#include <vector>
513
#include <string>
14+
#include <map>
615
#include "xia.h"
716

817
class Graph;
@@ -28,7 +37,6 @@ class Node
2837
static const std::string XID_TYPE_SID_STRING;
2938
static const std::string XID_TYPE_IP_STRING;
3039

31-
3240
public:
3341
Node();
3442
Node(const Node& r);
@@ -55,6 +63,12 @@ class Node
5563

5664
bool equal_to(const Node& r) const;
5765

66+
typedef std::map<int, std::string> XidMap;
67+
static XidMap xids;
68+
static XidMap load_xids();
69+
70+
71+
5872
protected:
5973
void acquire() const;
6074
void release() const;

api/xsocket/Xutil.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,10 @@ char *XrootDir(char *buf, unsigned len) {
4444
strncpy(buf, dir, len);
4545
return buf;
4646
}
47-
#ifdef __APPLE__
4847
if (!getcwd(buf, len)) {
4948
buf[0] = 0;
5049
return buf;
5150
}
52-
#else
53-
int cnt = readlink("/proc/self/exe", buf, MIN(len, PATH_SIZE));
54-
55-
if (cnt < 0) {
56-
buf[0] = 0;
57-
return buf;
58-
}
59-
else if ((unsigned)cnt == len)
60-
buf[len - 1] = 0;
61-
else
62-
buf[cnt] = 0;
63-
#endif
6451
pos = strstr(buf, SOURCE_DIR);
6552
if (pos) {
6653
pos += sizeof(SOURCE_DIR) - 1;

bin/xianet

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ ALL_PROCESSES="click xrouted xhcp_serverd xhcp_clientd xnameservice xstats xstat
3434
NAME=`basename $0`
3535
VERBOSE=0
3636
LOG_FLAGS=""
37+
LOG_LEVEL=6
38+
V_FLAG="-q"
3739
CLICK_ONLY=0
3840
NAMESERVER=0
3941
RUN_VISUALIZER_CLIENT=0
@@ -93,16 +95,19 @@ setup()
9395
;;
9496
l)
9597
LOG_FLAGS="$LOG_FLAGS -l $OPTARG"
98+
LOG_LEVEL=$OPTARG
9699
;;
97100
s)
98101
SCRIPT=$OPTARG
99102
;;
100103
V)
101104
VERBOSE=2
102105
LOG_FLAGS="$LOG_FLAGS -v"
106+
V_FLAG="-v"
103107
;;
104108
v)
105109
VERBOSE=1
110+
V_FLAG="-v"
106111
;;
107112
4)
108113
MAKECONF="dual$MAKECONF"
@@ -409,17 +414,19 @@ start_click()
409414
printf "$HOSTNAME\tnameserver\n" >> $NODECONF
410415
fi
411416

412-
if [ $VERBOSE -eq 0 ]; then
413-
exec 3>&1 # save stdout handle
414-
exec &> /dev/null
415-
fi
417+
# if [ $VERBOSE -eq 0 ]; then
418+
# exec 3>&1 # save stdout handle
419+
# exec &> /dev/null
420+
# fi
416421

417422
$CLICK -R $CONFPATH/$SCRIPT &
418-
[ $VERBOSE -eq 0 ] && exec 1>&3
423+
# [ $VERBOSE -eq 0 ] && exec 1>&3
419424

420425
get_pid "click"
421426
[ "$XPID" == "" ] && printf "Click is not running, aborting...\n" && exit 1
422427

428+
$XIADIR/bin/xlog $V_FLAG -l $LOG_LEVEL >/dev/null
429+
423430
[ $CLICK_ONLY -eq 1 ] && check_service click && exit
424431
sleep 1
425432
}

bin/xlog

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2013 Carnegie Mellon University
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
PORT=7777
18+
19+
check() {
20+
# see if click is running
21+
pid=`ps aux | grep -v grep | grep userlevel/click | tr -s " " | cut -d\ -f2`
22+
[ "$pid" == "" ] && printf "Click is not running, aborting...\n" && exit 1
23+
}
24+
25+
get() {
26+
check
27+
printf "$1: "
28+
printf "read log.$1\nquit\n" | nc localhost $PORT | sed -n '4p'
29+
}
30+
31+
put() {
32+
check
33+
printf "write log.$1 $2\nquit\n" | nc localhost $PORT > /dev/null
34+
}
35+
36+
help() {
37+
cat << EOH
38+
39+
Adjust XIA click logging output
40+
41+
usage: xlog [-vq] [-l <loglevel>]
42+
43+
where:
44+
-v output log messages to the console
45+
-q disable console logging
46+
-l syslog level (0=LOG_EMERG through 7=LOG_DEBUG) default=6 (LOG_INFO)
47+
48+
EOH
49+
exit 0
50+
}
51+
52+
while getopts "hvql:" opt; do
53+
case $opt in
54+
v)
55+
put verbose 1
56+
;;
57+
q)
58+
put verbose 0
59+
;;
60+
l)
61+
put level $OPTARG
62+
;;
63+
h)
64+
help
65+
;;
66+
\?)
67+
help
68+
;;
69+
esac
70+
done
71+
72+
get verbose
73+
get level

bin/xroute

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ class XrouteApp:
287287
# the main logic of the xroute app
288288
#
289289
def run(self):
290+
# load user defined XIDs
291+
self.loadXids()
292+
290293
# get the command line options
291294
self.options = Options()
292295
self.options.getOptions()
@@ -364,6 +367,32 @@ class XrouteApp:
364367
self.errorExit("error %d: %s" % (code, msg))
365368
return code
366369

370+
#
371+
# load XIDs from file
372+
#
373+
def loadXids(self):
374+
xfile = os.path.dirname(os.path.realpath(__file__))
375+
tail = xfile.rfind("/")
376+
xfile = xfile[:tail] + "/etc/xids"
377+
378+
try:
379+
lines = open(xfile, "r")
380+
except:
381+
return
382+
383+
for line in lines:
384+
comment = line.find("#")
385+
if comment >= 0:
386+
line = line[:comment]
387+
line = line.strip()
388+
389+
if (line == ""):
390+
continue
391+
392+
(id, name) = line.split()
393+
KNOWN_XIDS.append(name)
394+
lines.close()
395+
367396
#
368397
# print the list of known alias to XID mappings to stdout
369398
#

0 commit comments

Comments
 (0)