Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 1 | diff --git csrc/libexec/ccndc.c csrc/libexec/ccndc.c |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 2 | index ecde5f0..9be6e3b 100644 |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 3 | --- csrc/libexec/ccndc.c |
| 4 | +++ csrc/libexec/ccndc.c |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 5 | @@ -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 Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 18 | if (res < 0) { |
| 19 | ccndc_warn(__LINE__, "Cannot register prefix [%s]\n", ccn_charbuf_as_string(uri)); |
| 20 | } |
| 21 | + |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 22 | + 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 Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 29 | + } |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 30 | + |
| 31 | + prefix_auto->faceid = prefix->faceid; |
| 32 | + res = ccndc_do_prefix_action(self, "prefixreg", prefix_auto); |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 33 | + if (res < 0) { |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 34 | + ccndc_warn(__LINE__, "Cannot register prefix_auto [%s]\n", ccn_charbuf_as_string(uri_auto)); |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 35 | + } |
| 36 | |
| 37 | Cleanup: |
| 38 | free(uri); |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 39 | + 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 Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 47 | diff --git csrc/util/ccnd-autoconfig.sh csrc/util/ccnd-autoconfig.sh |
| 48 | new file mode 100755 |
Alexander Afanasyev | 9282836 | 2012-10-08 11:24:32 -0700 | [diff] [blame^] | 49 | index 0000000..48ec9fc |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 50 | --- /dev/null |
| 51 | +++ csrc/util/ccnd-autoconfig.sh |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 52 | @@ -0,0 +1,55 @@ |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 53 | +# 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 Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 73 | +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 Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 81 | + |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 82 | +# 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 Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 91 | + |
Alexander Afanasyev | 9282836 | 2012-10-08 11:24:32 -0700 | [diff] [blame^] | 92 | + if [ $MCAST_EXISTED -eq 1 ]; then |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 93 | + # destroying multicast face |
| 94 | + ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face |
| 95 | + fi |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 96 | + exit 1 |
| 97 | +fi |
| 98 | + |
| 99 | +echo Setting default route to a local hub: "$info" |
| 100 | +echo "$info" | xargs ccndc add / udp |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 101 | +echo "$info" | xargs ccndc add /autoconf-route udp |
Alexander Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 102 | + |
Alexander Afanasyev | 9282836 | 2012-10-08 11:24:32 -0700 | [diff] [blame^] | 103 | +if [ $MCAST_EXISTED -eq 1 ]; then |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 104 | + # destroying multicast face |
| 105 | + ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face |
| 106 | +fi |
Alexander Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 107 | + |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 108 | diff --git csrc/util/ccnd-publish-local-info.sh csrc/util/ccnd-publish-local-info.sh |
| 109 | new file mode 100755 |
Alexander Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 110 | index 0000000..b433f69 |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 111 | --- /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 Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 145 | +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 Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 147 | + |
| 148 | diff --git csrc/util/dir.mk csrc/util/dir.mk |
| 149 | index 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) |