blob: d338aebb9e9ddfb1195cffa374778b819d83067e [file] [log] [blame]
Alexander Afanasyeve985adc2012-10-05 09:18:23 -07001diff --git csrc/libexec/ccndc.c csrc/libexec/ccndc.c
2index ecde5f0..9b91c65 100644
3--- csrc/libexec/ccndc.c
4+++ csrc/libexec/ccndc.c
5@@ -649,6 +649,19 @@ ccndc_srv(struct ccndc_data *self,
6 if (res < 0) {
7 ccndc_warn(__LINE__, "Cannot register prefix [%s]\n", ccn_charbuf_as_string(uri));
8 }
9+
10+ ccn_charbuf_destroy (&uri);
11+ uri = ccn_charbuf_create();
12+ ccn_charbuf_append_string(uri, "ccnx:/autoconf-route");
13+ if (domain_size != 0) {
14+ ccn_uri_append_percentescaped(uri, domain, domain_size);
15+ }
16+ prefix->name_prefix = uri;
17+
18+ res = ccndc_do_prefix_action(self, "prefixreg", prefix);
19+ if (res < 0) {
20+ ccndc_warn(__LINE__, "Cannot register prefix [%s]\n", ccn_charbuf_as_string(uri));
21+ }
22
23 Cleanup:
24 free(uri);
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070025diff --git csrc/util/ccnd-autoconfig.sh csrc/util/ccnd-autoconfig.sh
26new file mode 100755
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070027index 0000000..2bef939
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070028--- /dev/null
29+++ csrc/util/ccnd-autoconfig.sh
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070030@@ -0,0 +1,55 @@
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070031+# Source file: util/ccnd-autoconfig.sh
32+#
33+# Script that tries to (automatically) discover of a local ccnd gateway
34+#
35+# Part of the CCNx distribution.
36+#
37+# Copyright (C) 2012 Palo Alto Research Center, Inc.
38+#
39+# This work is free software; you can redistribute it and/or modify it under
40+# the terms of the GNU General Public License version 2 as published by the
41+# Free Software Foundation.
42+# This work is distributed in the hope that it will be useful, but WITHOUT ANY
43+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
44+# FOR A PARTICULAR PURPOSE.
45+
46+# This script should be installed in the same place as ccnd, ccndc, ccndsmoketest, ...
47+# adjust the path to get consistency.
48+D=`dirname "$0"`
49+export PATH="$D:$PATH"
50+
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070051+ccndstatus | grep 224.0.23.170:59695 > /dev/null
52+MCAST_EXISTED=$?
53+
54+# Removing any previously created (either by this script or ccndc srv command) default route
55+for i in `ccndstatus | grep "ccnx:/autoconf-route face" | awk '{print $3}'`; do
56+ ccndc del / face $i
57+ ccndc del /autoconf-route face $i
58+done
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -070059+
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070060+# Set temporary multicast face
61+ccndc -t 10 add "/local/ndn" udp 224.0.23.170 59695
62+
63+# Get info from local hub, if available
64+info=`ccncat -s 2 /local/ndn/udp`
65+if [ "x$info" = "x" ]; then
66+ echo "Local hub is not availble, trying to use DNS to get local configuration"
67+ # Try to use DNS search list to get default route information
68+ ccndc srv
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -070069+
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070070+ if [ ! $MCAST_EXISTED ]; then
71+ # destroying multicast face
72+ ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face
73+ fi
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070074+ exit 1
75+fi
76+
77+echo Setting default route to a local hub: "$info"
78+echo "$info" | xargs ccndc add / udp
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070079+echo "$info" | xargs ccndc add /autoconf-route udp
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -070080+
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070081+if [ ! $MCAST_EXISTED ]; then
82+ # destroying multicast face
83+ ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face
84+fi
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -070085+
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070086diff --git csrc/util/ccnd-publish-local-info.sh csrc/util/ccnd-publish-local-info.sh
87new file mode 100755
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -070088index 0000000..b433f69
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070089--- /dev/null
90+++ csrc/util/ccnd-publish-local-info.sh
91@@ -0,0 +1,34 @@
92+# Source file: util/ccnd-autoconfig.sh
93+#
94+# Script to publish information about local ccnd gateway in local repo (should be run only on ccnd gateway nodes)
95+#
96+# Part of the CCNx distribution.
97+#
98+# Copyright (C) 2012 Palo Alto Research Center, Inc.
99+#
100+# This work is free software; you can redistribute it and/or modify it under
101+# the terms of the GNU General Public License version 2 as published by the
102+# Free Software Foundation.
103+# This work is distributed in the hope that it will be useful, but WITHOUT ANY
104+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
105+# FOR A PARTICULAR PURPOSE.
106+
107+# This script should be installed in the same place as ccnd, ccndc, ccndsmoketest, ...
108+# adjust the path to get consistency.
109+D=`dirname "$0"`
110+export PATH="$D:$PATH"
111+
112+#
113+
114+udp_face_info=$1
115+local_prefix=$2
116+
117+if [ "x$udp_face_info" = "x" -o "x$local_prefix" = "x" ]; then
118+ echo "Usage: "
119+ echo " " $0 " <udp_face_info> <routable_prefix>"
120+ exit 1
121+fi
122+
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -0700123+echo $udp_face_info | ccnseqwriter -c 1 -r -x 5 "/local/ndn/udp"
124+echo $local_prefix | ccnseqwriter -c 1 -r -x 5 "/local/ndn/prefix"
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -0700125+
126diff --git csrc/util/dir.mk csrc/util/dir.mk
127index f29038f..94bc7b6 100644
128--- csrc/util/dir.mk
129+++ csrc/util/dir.mk
130@@ -14,8 +14,10 @@
131
132 SCRIPTSRC = shebang \
133 ccndstart.sh ccndstop.sh ccndstatus.sh ccndlogging.sh ccnget.sh ccnput.sh \
134- ccntestloop-trampoline
135-PROGRAMS = ccndstart ccndstop ccndstatus ccntestloop ccndlogging ccnget ccnput
136+ ccntestloop-trampoline \
137+ ccnd-autoconfig.sh ccnd-publish-local-info.sh
138+
139+PROGRAMS = ccndstart ccndstop ccndstatus ccntestloop ccndlogging ccnget ccnput ccnd-autoconfig ccnd-publish-local-info
140 INSTALLED_PROGRAMS = $(PROGRAMS)
141
142 default all: $(SCRIPTSRC) $(PROGRAMS)