blob: f4275c112a0c881bb11ed1a4284787404044433e [file] [log] [blame]
diff --git csrc/libexec/ccndc.c csrc/libexec/ccndc.c
index ecde5f0..9be6e3b 100644
--- csrc/libexec/ccndc.c
+++ csrc/libexec/ccndc.c
@@ -580,9 +580,11 @@ ccndc_srv(struct ccndc_data *self,
int port = 0;
char port_str[10];
struct ccn_charbuf *uri;
+ struct ccn_charbuf *uri_auto;
struct ccn_face_instance *face;
struct ccn_face_instance *newface;
struct ccn_forwarding_entry *prefix;
+ struct ccn_forwarding_entry *prefix_auto;
int res;
res = ccndc_query_srv(domain, domain_size, &host, &port, &proto);
@@ -649,12 +651,29 @@ ccndc_srv(struct ccndc_data *self,
if (res < 0) {
ccndc_warn(__LINE__, "Cannot register prefix [%s]\n", ccn_charbuf_as_string(uri));
}
+
+ uri_auto = ccn_charbuf_create();
+ ccn_charbuf_append_string(uri_auto, "ccnx:/autoconf-route");
+ prefix_auto = parse_ccn_forwarding_entry(self, ccn_charbuf_as_string(uri_auto), NULL,
+ self->lifetime);
+ if (prefix_auto == NULL) {
+ res = -1;
+ goto Cleanup;
+ }
+
+ prefix_auto->faceid = prefix->faceid;
+ res = ccndc_do_prefix_action(self, "prefixreg", prefix_auto);
+ if (res < 0) {
+ ccndc_warn(__LINE__, "Cannot register prefix_auto [%s]\n", ccn_charbuf_as_string(uri_auto));
+ }
Cleanup:
free(uri);
+ free(uri_auto);
free(host);
ccn_face_instance_destroy(&face);
ccn_forwarding_entry_destroy(&prefix);
+ ccn_forwarding_entry_destroy(&prefix_auto);
return res;
}
diff --git csrc/util/ccnd-autoconfig.sh csrc/util/ccnd-autoconfig.sh
new file mode 100755
index 0000000..48ec9fc
--- /dev/null
+++ csrc/util/ccnd-autoconfig.sh
@@ -0,0 +1,55 @@
+# Source file: util/ccnd-autoconfig.sh
+#
+# Script that tries to (automatically) discover of a local ccnd gateway
+#
+# Part of the CCNx distribution.
+#
+# Copyright (C) 2012 Palo Alto Research Center, Inc.
+#
+# This work is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License version 2 as published by the
+# Free Software Foundation.
+# This work is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.
+
+# This script should be installed in the same place as ccnd, ccndc, ccndsmoketest, ...
+# adjust the path to get consistency.
+D=`dirname "$0"`
+export PATH="$D:$PATH"
+
+ccndstatus | grep 224.0.23.170:59695 > /dev/null
+MCAST_EXISTED=$?
+
+# Removing any previously created (either by this script or ccndc srv command) default route
+for i in `ccndstatus | grep "ccnx:/autoconf-route face" | awk '{print $3}'`; do
+ ccndc del / face $i
+ ccndc del /autoconf-route face $i
+done
+
+# Set temporary multicast face
+ccndc -t 10 add "/local/ndn" udp 224.0.23.170 59695
+
+# Get info from local hub, if available
+info=`ccncat -s 2 /local/ndn/udp`
+if [ "x$info" = "x" ]; then
+ echo "Local hub is not availble, trying to use DNS to get local configuration"
+ # Try to use DNS search list to get default route information
+ ccndc srv
+
+ if [ $MCAST_EXISTED -eq 1 ]; then
+ # destroying multicast face
+ ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face
+ fi
+ exit 1
+fi
+
+echo Setting default route to a local hub: "$info"
+echo "$info" | xargs ccndc add / udp
+echo "$info" | xargs ccndc add /autoconf-route udp
+
+if [ $MCAST_EXISTED -eq 1 ]; then
+ # destroying multicast face
+ ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face
+fi
+
diff --git csrc/util/ccnd-publish-local-info.sh csrc/util/ccnd-publish-local-info.sh
new file mode 100755
index 0000000..b433f69
--- /dev/null
+++ csrc/util/ccnd-publish-local-info.sh
@@ -0,0 +1,34 @@
+# Source file: util/ccnd-autoconfig.sh
+#
+# Script to publish information about local ccnd gateway in local repo (should be run only on ccnd gateway nodes)
+#
+# Part of the CCNx distribution.
+#
+# Copyright (C) 2012 Palo Alto Research Center, Inc.
+#
+# This work is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License version 2 as published by the
+# Free Software Foundation.
+# This work is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.
+
+# This script should be installed in the same place as ccnd, ccndc, ccndsmoketest, ...
+# adjust the path to get consistency.
+D=`dirname "$0"`
+export PATH="$D:$PATH"
+
+#
+
+udp_face_info=$1
+local_prefix=$2
+
+if [ "x$udp_face_info" = "x" -o "x$local_prefix" = "x" ]; then
+ echo "Usage: "
+ echo " " $0 " <udp_face_info> <routable_prefix>"
+ exit 1
+fi
+
+echo $udp_face_info | ccnseqwriter -c 1 -r -x 5 "/local/ndn/udp"
+echo $local_prefix | ccnseqwriter -c 1 -r -x 5 "/local/ndn/prefix"
+
diff --git csrc/util/dir.mk csrc/util/dir.mk
index f29038f..94bc7b6 100644
--- csrc/util/dir.mk
+++ csrc/util/dir.mk
@@ -14,8 +14,10 @@
SCRIPTSRC = shebang \
ccndstart.sh ccndstop.sh ccndstatus.sh ccndlogging.sh ccnget.sh ccnput.sh \
- ccntestloop-trampoline
-PROGRAMS = ccndstart ccndstop ccndstatus ccntestloop ccndlogging ccnget ccnput
+ ccntestloop-trampoline \
+ ccnd-autoconfig.sh ccnd-publish-local-info.sh
+
+PROGRAMS = ccndstart ccndstop ccndstatus ccntestloop ccndlogging ccnget ccnput ccnd-autoconfig ccnd-publish-local-info
INSTALLED_PROGRAMS = $(PROGRAMS)
default all: $(SCRIPTSRC) $(PROGRAMS)