blob: f4275c112a0c881bb11ed1a4284787404044433e [file] [log] [blame]
Alexander Afanasyeve985adc2012-10-05 09:18:23 -07001diff --git csrc/libexec/ccndc.c csrc/libexec/ccndc.c
Alexander Afanasyevf22a6652012-10-05 09:30:15 -07002index ecde5f0..9be6e3b 100644
Alexander Afanasyeve985adc2012-10-05 09:18:23 -07003--- csrc/libexec/ccndc.c
4+++ csrc/libexec/ccndc.c
Alexander Afanasyevf22a6652012-10-05 09:30:15 -07005@@ -580,9 +580,11 @@ ccndc_srv(struct ccndc_data *self,
6 int port = 0;
7 char port_str[10];
8 struct ccn_charbuf *uri;
9+ struct ccn_charbuf *uri_auto;
10 struct ccn_face_instance *face;
11 struct ccn_face_instance *newface;
12 struct ccn_forwarding_entry *prefix;
13+ struct ccn_forwarding_entry *prefix_auto;
14 int res;
15
16 res = ccndc_query_srv(domain, domain_size, &host, &port, &proto);
17@@ -649,12 +651,29 @@ ccndc_srv(struct ccndc_data *self,
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070018 if (res < 0) {
19 ccndc_warn(__LINE__, "Cannot register prefix [%s]\n", ccn_charbuf_as_string(uri));
20 }
21+
Alexander Afanasyevf22a6652012-10-05 09:30:15 -070022+ uri_auto = ccn_charbuf_create();
23+ ccn_charbuf_append_string(uri_auto, "ccnx:/autoconf-route");
24+ prefix_auto = parse_ccn_forwarding_entry(self, ccn_charbuf_as_string(uri_auto), NULL,
25+ self->lifetime);
26+ if (prefix_auto == NULL) {
27+ res = -1;
28+ goto Cleanup;
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070029+ }
Alexander Afanasyevf22a6652012-10-05 09:30:15 -070030+
31+ prefix_auto->faceid = prefix->faceid;
32+ res = ccndc_do_prefix_action(self, "prefixreg", prefix_auto);
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070033+ if (res < 0) {
Alexander Afanasyevf22a6652012-10-05 09:30:15 -070034+ ccndc_warn(__LINE__, "Cannot register prefix_auto [%s]\n", ccn_charbuf_as_string(uri_auto));
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070035+ }
36
37 Cleanup:
38 free(uri);
Alexander Afanasyevf22a6652012-10-05 09:30:15 -070039+ free(uri_auto);
40 free(host);
41 ccn_face_instance_destroy(&face);
42 ccn_forwarding_entry_destroy(&prefix);
43+ ccn_forwarding_entry_destroy(&prefix_auto);
44 return res;
45 }
46
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070047diff --git csrc/util/ccnd-autoconfig.sh csrc/util/ccnd-autoconfig.sh
48new file mode 100755
Alexander Afanasyev92828362012-10-08 11:24:32 -070049index 0000000..48ec9fc
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070050--- /dev/null
51+++ csrc/util/ccnd-autoconfig.sh
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070052@@ -0,0 +1,55 @@
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070053+# Source file: util/ccnd-autoconfig.sh
54+#
55+# Script that tries to (automatically) discover of a local ccnd gateway
56+#
57+# Part of the CCNx distribution.
58+#
59+# Copyright (C) 2012 Palo Alto Research Center, Inc.
60+#
61+# This work is free software; you can redistribute it and/or modify it under
62+# the terms of the GNU General Public License version 2 as published by the
63+# Free Software Foundation.
64+# This work is distributed in the hope that it will be useful, but WITHOUT ANY
65+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
66+# FOR A PARTICULAR PURPOSE.
67+
68+# This script should be installed in the same place as ccnd, ccndc, ccndsmoketest, ...
69+# adjust the path to get consistency.
70+D=`dirname "$0"`
71+export PATH="$D:$PATH"
72+
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070073+ccndstatus | grep 224.0.23.170:59695 > /dev/null
74+MCAST_EXISTED=$?
75+
76+# Removing any previously created (either by this script or ccndc srv command) default route
77+for i in `ccndstatus | grep "ccnx:/autoconf-route face" | awk '{print $3}'`; do
78+ ccndc del / face $i
79+ ccndc del /autoconf-route face $i
80+done
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -070081+
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070082+# Set temporary multicast face
83+ccndc -t 10 add "/local/ndn" udp 224.0.23.170 59695
84+
85+# Get info from local hub, if available
86+info=`ccncat -s 2 /local/ndn/udp`
87+if [ "x$info" = "x" ]; then
88+ echo "Local hub is not availble, trying to use DNS to get local configuration"
89+ # Try to use DNS search list to get default route information
90+ ccndc srv
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -070091+
Alexander Afanasyev92828362012-10-08 11:24:32 -070092+ if [ $MCAST_EXISTED -eq 1 ]; then
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070093+ # destroying multicast face
94+ ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face
95+ fi
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070096+ exit 1
97+fi
98+
99+echo Setting default route to a local hub: "$info"
100+echo "$info" | xargs ccndc add / udp
Alexander Afanasyeve985adc2012-10-05 09:18:23 -0700101+echo "$info" | xargs ccndc add /autoconf-route udp
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -0700102+
Alexander Afanasyev92828362012-10-08 11:24:32 -0700103+if [ $MCAST_EXISTED -eq 1 ]; then
Alexander Afanasyeve985adc2012-10-05 09:18:23 -0700104+ # destroying multicast face
105+ ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face
106+fi
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -0700107+
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -0700108diff --git csrc/util/ccnd-publish-local-info.sh csrc/util/ccnd-publish-local-info.sh
109new file mode 100755
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -0700110index 0000000..b433f69
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -0700111--- /dev/null
112+++ csrc/util/ccnd-publish-local-info.sh
113@@ -0,0 +1,34 @@
114+# Source file: util/ccnd-autoconfig.sh
115+#
116+# Script to publish information about local ccnd gateway in local repo (should be run only on ccnd gateway nodes)
117+#
118+# Part of the CCNx distribution.
119+#
120+# Copyright (C) 2012 Palo Alto Research Center, Inc.
121+#
122+# This work is free software; you can redistribute it and/or modify it under
123+# the terms of the GNU General Public License version 2 as published by the
124+# Free Software Foundation.
125+# This work is distributed in the hope that it will be useful, but WITHOUT ANY
126+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
127+# FOR A PARTICULAR PURPOSE.
128+
129+# This script should be installed in the same place as ccnd, ccndc, ccndsmoketest, ...
130+# adjust the path to get consistency.
131+D=`dirname "$0"`
132+export PATH="$D:$PATH"
133+
134+#
135+
136+udp_face_info=$1
137+local_prefix=$2
138+
139+if [ "x$udp_face_info" = "x" -o "x$local_prefix" = "x" ]; then
140+ echo "Usage: "
141+ echo " " $0 " <udp_face_info> <routable_prefix>"
142+ exit 1
143+fi
144+
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -0700145+echo $udp_face_info | ccnseqwriter -c 1 -r -x 5 "/local/ndn/udp"
146+echo $local_prefix | ccnseqwriter -c 1 -r -x 5 "/local/ndn/prefix"
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -0700147+
148diff --git csrc/util/dir.mk csrc/util/dir.mk
149index f29038f..94bc7b6 100644
150--- csrc/util/dir.mk
151+++ csrc/util/dir.mk
152@@ -14,8 +14,10 @@
153
154 SCRIPTSRC = shebang \
155 ccndstart.sh ccndstop.sh ccndstatus.sh ccndlogging.sh ccnget.sh ccnput.sh \
156- ccntestloop-trampoline
157-PROGRAMS = ccndstart ccndstop ccndstatus ccntestloop ccndlogging ccnget ccnput
158+ ccntestloop-trampoline \
159+ ccnd-autoconfig.sh ccnd-publish-local-info.sh
160+
161+PROGRAMS = ccndstart ccndstop ccndstatus ccntestloop ccndlogging ccnget ccnput ccnd-autoconfig ccnd-publish-local-info
162 INSTALLED_PROGRAMS = $(PROGRAMS)
163
164 default all: $(SCRIPTSRC) $(PROGRAMS)