From: Moumita Ray Date: Tue, 23 Jun 2015 16:57:29 +0000 (-0700) Subject: Adding IPv6 changes in Sample Apps. X-Git-Tag: 0.9.2-beta~95 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84dff73bce0ec4939633683d38230d7f9c40bd2c;p=contrib%2Fiotivity.git Adding IPv6 changes in Sample Apps. This change is part of Multiadaptor/IPv6. Sample Apps needs to be updated to allow available and currently suppoted connectivity types. Change-Id: I701027d599e53183673abe2afd7b0f1a5fade885 Signed-off-by: Moumita Ray Reviewed-on: https://gerrit.iotivity.org/gerrit/1406 Tested-by: jenkins-iotivity Reviewed-by: Erich Keane --- diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp index 7e40e7e..d0c13a6 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp @@ -29,8 +29,10 @@ #include "logger.h" #include "occlient.h" +// Tracking user input static int UNICAST_DISCOVERY = 0; static int TEST_CASE = 0; +static int CONNECTIVITY = 0; static const char * UNICAST_DEVICE_DISCOVERY_QUERY = "coap://%s:6298/oic/d"; static const char * MULTICAST_DEVICE_DISCOVERY_QUERY = "/oic/d"; @@ -76,9 +78,11 @@ void handleSigInt(int signum) static void PrintUsage() { - OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1..17> -c <0|1>"); + OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1..17> -c <0|1|2>"); OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources"); - OC_LOG(INFO, TAG, "-c <0|1> : IPv4/IPv6 (IPv6 not currently supported)"); + OC_LOG(INFO, TAG, "-c 0 : Default IPv4 and IPv6 auto-selection"); + OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type"); + OC_LOG(INFO, TAG, "-c 2 : IPv6 Connectivity Type (IPv6 not currently supported)"); OC_LOG(INFO, TAG, "-t 1 : Discover Resources"); OC_LOG(INFO, TAG, "-t 2 : Discover Resources and Initiate Nonconfirmable Get Request"); OC_LOG(INFO, TAG, "-t 3 : Discover Resources and Initiate Nonconfirmable Get Request" @@ -90,7 +94,7 @@ static void PrintUsage() OC_LOG(INFO, TAG, "-t 8 : Discover Resources and Initiate Nonconfirmable Get Request "\ "for a resource which is unavailable"); OC_LOG(INFO, TAG, "-t 9 : Discover Resources and Initiate Confirmable Get Request"); - OC_LOG(INFO, TAG, "-t 10 : Discover Resources and Initiate Confirmable Post Request"); + OC_LOG(INFO, TAG, "-t 10 : Discover Resources and Initiate Confirmable Post Request"); OC_LOG(INFO, TAG, "-t 11 : Discover Resources and Initiate Confirmable Delete Requests"); OC_LOG(INFO, TAG, "-t 12 : Discover Resources and Initiate Confirmable Observe Requests"\ " and cancel with Low QoS"); @@ -700,8 +704,9 @@ int InitPlatformDiscovery(OCQualityOfService qos) } else { - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT, - (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0); + + ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, OC_CONNTYPE, + (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0); } if (ret != OC_STACK_OK) @@ -741,8 +746,8 @@ int InitDeviceDiscovery(OCQualityOfService qos) } else { - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT, - (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0); + ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, OC_CONNTYPE, + (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0); } if (ret != OC_STACK_OK) @@ -779,8 +784,8 @@ int InitDiscovery(OCQualityOfService qos) } else { - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT, - (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0); + ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, OC_CONNTYPE, + (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0); } if (ret != OC_STACK_OK) { @@ -804,7 +809,7 @@ int main(int argc, char* argv[]) TEST_CASE = atoi(optarg); break; case 'c': - OC_CONNTYPE = CT_ADAPTER_IP; + CONNECTIVITY = atoi(optarg); break; default: PrintUsage(); @@ -813,7 +818,8 @@ int main(int argc, char* argv[]) } if ((UNICAST_DISCOVERY != 0 && UNICAST_DISCOVERY != 1) || - (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS) ) + (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS) || + (CONNECTIVITY < CT_ADAPTER_DEFAULT || CONNECTIVITY >= MAX_CT)) { PrintUsage(); return -1; @@ -827,7 +833,9 @@ int main(int argc, char* argv[]) } if (UNICAST_DISCOVERY) { - printf("Enter IPv4 address of the Server hosting resource (Ex: 192.168.0.15)\n"); + OC_LOG(INFO, TAG, "Enter IPv4 address of the Server hosting resource (Ex: 192.168.0.15)\n"); + OC_LOG(INFO, TAG, "Ipv6 is currently not supported..."); + if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin)) { //Strip newline char from ipv4addr @@ -838,7 +846,29 @@ int main(int argc, char* argv[]) OC_LOG(ERROR, TAG, "!! Bad input for IPV4 address. !!"); return OC_STACK_INVALID_PARAM; } - } + } + if(CONNECTIVITY == CT_ADAPTER_DEFAULT) + { + OC_CONNTYPE = CT_DEFAULT; + } + else if(CONNECTIVITY == CT_IPV4) + { + OC_CONNTYPE = CT_IP_USE_V4; + } + else if(CONNECTIVITY == CT_IPV6) + { + OC_CONNTYPE = CT_IP_USE_V6; + + //TODO: Remove when IPv6 is available. + OC_LOG(ERROR, TAG, "IPv6 is currently not supported !!!!"); + PrintUsage(); + return -1; + } + else + { + OC_LOG(INFO, TAG, "Default Connectivity type selected..."); + PrintUsage(); + } if(UNICAST_DISCOVERY == 0 && TEST_CASE == TEST_DISCOVER_DEV_REQ) { @@ -913,6 +943,12 @@ std::string getConnectivityType (OCConnectivityType connType) case CT_ADAPTER_IP: return "IP"; + case CT_IP_USE_V4: + return "IPv4"; + + case CT_IP_USE_V6: + return "IPv6"; + case CT_ADAPTER_GATT_BTLE: return "GATT"; diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h index 6e955b7..a8661ed 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h @@ -38,7 +38,7 @@ //----------------------------------------------------------------------------- /** - * List of methods that can be inititated from the client + * List of methods that can be initiated from the client */ typedef enum { TEST_DISCOVER_REQ = 1, @@ -66,6 +66,17 @@ typedef enum { MAX_TESTS } CLIENT_TEST; +/** + * List of connectivity types that can be initiated from the client + * Required for user input validation + */ +typedef enum { + CT_ADAPTER_DEFAULT = 0, + CT_IPV4, + CT_IPV6, + MAX_CT +} CLIENT_CONNECTIVITY_TYPE; + #ifdef WITH_PRESENCE int InitPresence(); #endif diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp index fa59537..2ea10a1 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp @@ -38,6 +38,7 @@ static int IPV4_ADDR_SIZE = 16; static int UNICAST_DISCOVERY = 0; static int TEST_CASE = 0; +static int CONNECTIVITY = 0; static const char UNICAST_DISCOVERY_QUERY[] = "coap://%s:6298/oic/res"; static std::string putPayload = "{\"oic\":[{\"rep\":{\"power\":15,\"state\":true}}]}"; @@ -63,15 +64,16 @@ void handleSigInt(int signum) static void PrintUsage() { - OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1>"); + OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1|2>"); OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources"); OC_LOG(INFO, TAG, "-t 1 : Discover Resources"); OC_LOG(INFO, TAG, "-t 2 : Discover Resources and" " Initiate Nonconfirmable Get/Put/Post Requests"); OC_LOG(INFO, TAG, "-t 3 : Discover Resources and Initiate " "Confirmable Get/Put/Post Requests"); - OC_LOG(INFO, TAG, "-c <0|1> : IPv4/IPv6 (IPv6 not currently supported)"); - OC_LOG(INFO, TAG, "Default connectivityType IPv4"); + OC_LOG(INFO, TAG, "-c 0 : Default IPv4 and IPv6 auto-selection"); + OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type"); + OC_LOG(INFO, TAG, "-c 2 : IPv6 Connectivity Type (IPv6 not currently supported)"); } /* @@ -316,8 +318,8 @@ int InitDiscovery() if (UNICAST_DISCOVERY) { char ipv4addr[IPV4_ADDR_SIZE]; - printf("Enter IPv4 address of the Server hosting " - "resource (Ex: 192.168.0.15)\n"); + OC_LOG(INFO, TAG, "Enter IPv4 address of the Server hosting resource (Ex: 192.168.0.15) "); + if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin)) { //Strip newline char from ipv4addr @@ -363,7 +365,7 @@ const char *getIPAddr(const OCClientResponse *clientResponse) } const OCDevAddr *devAddr = &clientResponse->devAddr; - char *ipaddr = (char *) OICCalloc(1, strlen(devAddr->addr)); + char *ipaddr = (char *) OICCalloc(1, strlen(devAddr->addr) +1); if (ipaddr) { snprintf(ipaddr, MAX_IP_ADDR_ST_SZ, "%s", devAddr->addr); @@ -628,8 +630,14 @@ void printResourceList() switch (iter->connType & CT_MASK_ADAPTER) { case CT_ADAPTER_IP: + printf("connType = %s\n","Default (IPv4) "); + break; + case CT_IP_USE_V4: printf("connType = %s\n","IPv4"); break; + case CT_IP_USE_V6: + printf("connType = %s\n","IPv6"); + break; case OC_ADAPTER_GATT_BTLE: printf("connType = %s\n","BLE"); break; @@ -677,7 +685,7 @@ int main(int argc, char* argv[]) TEST_CASE = atoi(optarg); break; case 'c': - OC_CONNTYPE = CT_ADAPTER_IP; + CONNECTIVITY = atoi(optarg); break; default: PrintUsage(); @@ -686,7 +694,8 @@ int main(int argc, char* argv[]) } if ((UNICAST_DISCOVERY != 0 && UNICAST_DISCOVERY != 1) || - (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS) ) + (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS) || + (CONNECTIVITY < CT_ADAPTER_DEFAULT || CONNECTIVITY >= MAX_CT)) { PrintUsage(); return -1; @@ -699,6 +708,29 @@ int main(int argc, char* argv[]) return 0; } + if(CONNECTIVITY == CT_ADAPTER_DEFAULT) + { + OC_CONNTYPE = CT_ADAPTER_IP;//CT_DEFAULT; + } + else if(CONNECTIVITY == CT_IPV4) + { + OC_CONNTYPE = CT_IP_USE_V4; + } + else if(CONNECTIVITY == CT_IPV6) + { + OC_CONNTYPE = CT_IP_USE_V6; + + //TODO: Remove when IPv6 is available. + printf("\n\nIPv6 is currently not supported !!!!\n"); + PrintUsage(); + return -1; + } + else + { + printf("Default Connectivity type selected \n\n"); + OC_CONNTYPE = CT_ADAPTER_IP; + } + InitDiscovery(); // Break from loop with Ctrl+C diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.h b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.h index c9d0dc9..4a0dd93 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.h +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.h @@ -46,6 +46,17 @@ typedef enum { MAX_TESTS } CLIENT_TEST; +/** + * List of connectivity types that can be initiated from the client + * Required for user input validation + */ +typedef enum { + CT_ADAPTER_DEFAULT = 0, + CT_IPV4, + CT_IPV6, + MAX_CT +} CLIENT_CONNECTIVITY_TYPE; + //----------------------------------------------------------------------------- //ResourceNode //----------------------------------------------------------------------------- diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp index 0f9c40a..15c3c8b 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp @@ -53,7 +53,19 @@ typedef enum MAX_TESTS } CLIENT_TEST; +/** + * List of connectivity types that can be initiated from the client + * Required for user input validation + */ +typedef enum { + CT_ADAPTER_DEFAULT = 0, + CT_IPV4, + CT_IPV6, + MAX_CT +} CLIENT_CONNECTIVITY_TYPE; + unsigned static int TEST = TEST_INVALID; +unsigned static int CONNECTIVITY = 0; typedef struct { @@ -107,7 +119,9 @@ int InitDiscovery(); void PrintUsage() { OC_LOG(INFO, TAG, "Usage : occlientcoll -t -c "); - OC_LOG(INFO, TAG, "-c <0|1> : IPv4/IPv6 (IPv6 not currently supported)"); + OC_LOG(INFO, TAG, "-c 0 : Default IPv4 and IPv6 auto-selection"); + OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type"); + OC_LOG(INFO, TAG, "-c 2 : IPv6 Connectivity Type (IPv6 not currently supported)"); OC_LOG(INFO, TAG, "Test Case 1 : Discover Resources && Initiate GET Request on an "\ "available resource using default interface."); OC_LOG(INFO, TAG, "Test Case 2 : Discover Resources && Initiate GET Request on an "\ @@ -321,7 +335,7 @@ int InitDiscovery() cbData.cb = discoveryReqCB; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT, + ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, OC_CONNTYPE, OC_LOW_QOS, &cbData, NULL, 0); if (ret != OC_STACK_OK) @@ -343,14 +357,15 @@ int main(int argc, char* argv[]) TEST = atoi(optarg); break; case 'c': - OC_CONNTYPE = CT_ADAPTER_IP; + CONNECTIVITY = atoi(optarg); break; default: PrintUsage(); return -1; } } - if (TEST <= TEST_INVALID || TEST >= MAX_TESTS) + if ((TEST <= TEST_INVALID || TEST >= MAX_TESTS) || + (CONNECTIVITY < CT_ADAPTER_DEFAULT || CONNECTIVITY >= MAX_CT)) { PrintUsage(); return -1; @@ -363,6 +378,28 @@ int main(int argc, char* argv[]) return 0; } + if(CONNECTIVITY == CT_ADAPTER_DEFAULT) + { + OC_CONNTYPE = CT_DEFAULT; + } + else if(CONNECTIVITY == CT_IPV4) + { + OC_CONNTYPE = CT_IP_USE_V4; + } + else if(CONNECTIVITY == CT_IPV6) + { + OC_CONNTYPE = CT_IP_USE_V6; + + //TODO: Remove when IPv6 is available. + OC_LOG(INFO, TAG, "Ipv6 is currently not supported..."); + PrintUsage(); + return -1; + } + else + { + OC_LOG(INFO, TAG, "Default Connectivity type selected..."); + OC_CONNTYPE = CT_ADAPTER_IP; + } InitDiscovery(); // Break from loop with Ctrl+C diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp index 0e07d81..7f55394 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp @@ -29,8 +29,11 @@ #include "logger.h" #include "occlientslow.h" +// Tracking user input static int UNICAST_DISCOVERY = 0; static int TEST_CASE = 0; +static int CONNECTIVITY = 0; + static const char * UNICAST_DISCOVERY_QUERY = "coap://%s:6298/oic/res"; static std::string putPayload = "{\"state\":\"off\",\"power\":10}"; static std::string coapServerIP = "255.255.255.255"; @@ -57,8 +60,10 @@ void handleSigInt(int signum) static void PrintUsage() { - OC_LOG(INFO, TAG, "Usage : occlient -c <0|1> -u <0|1> -t <1|2|3>"); - OC_LOG(INFO, TAG, "-c <0|1> : IPv4/IPv6 (IPv6 not currently supported)"); + OC_LOG(INFO, TAG, "Usage : occlient -c <0|1|2> -u <0|1> -t <1|2|3>"); + OC_LOG(INFO, TAG, "-c 0 : Default IPv4 and IPv6 auto-selection"); + OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type"); + OC_LOG(INFO, TAG, "-c 2 : IPv6 Connectivity Type (IPv6 not currently supported)"); OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources"); OC_LOG(INFO, TAG, "-t 1 : Discover Resources"); OC_LOG(INFO, TAG, "-t 2 : Discover Resources and Initiate Nonconfirmable Get Request"); @@ -181,7 +186,7 @@ int InitDiscovery() if (UNICAST_DISCOVERY) { char ipv4addr[IPV4_ADDR_SIZE]; - printf("Enter IPv4 address of the Server hosting resource (Ex: 192.168.0.15)\n"); + OC_LOG(INFO, TAG, "Enter IPv4 address of the Server hosting resource (Ex: 192.168.0.15)"); if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin)) { //Strip newline char from ipv4addr @@ -233,7 +238,7 @@ int main(int argc, char* argv[]) TEST_CASE = atoi(optarg); break; case 'c': - OC_CONNTYPE = CT_ADAPTER_IP; + CONNECTIVITY = atoi(optarg); break; default: PrintUsage(); @@ -242,7 +247,8 @@ int main(int argc, char* argv[]) } if ((UNICAST_DISCOVERY != 0 && UNICAST_DISCOVERY != 1) || - (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS) ) + (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS) || + (CONNECTIVITY < CT_ADAPTER_DEFAULT || CONNECTIVITY >= MAX_CT)) { PrintUsage(); return -1; @@ -255,6 +261,29 @@ int main(int argc, char* argv[]) return 0; } + if(CONNECTIVITY == CT_ADAPTER_DEFAULT) + { + OC_CONNTYPE = CT_ADAPTER_IP; + } + else if(CONNECTIVITY == CT_IPV4) + { + OC_CONNTYPE = CT_IP_USE_V4; + } + else if(CONNECTIVITY == CT_IPV6) + { + OC_CONNTYPE = CT_IP_USE_V6; + + //TODO: Remove when IPv6 is available. + OC_LOG(INFO, TAG, "Ipv6 is currently not supported..."); + PrintUsage(); + return -1; + } + else + { + OC_LOG(INFO, TAG, "Default Connectivity type selected..."); + OC_CONNTYPE = CT_ADAPTER_IP; + } + InitDiscovery(); // Break from loop with Ctrl+C diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.h b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.h index 8b6bcc4..fdb2204 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.h +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.h @@ -47,6 +47,17 @@ typedef enum MAX_TESTS } CLIENT_TEST; +/** + * List of connectivity types that can be initiated from the client + * Required for user input validation + */ +typedef enum { + CT_ADAPTER_DEFAULT = 0, + CT_IPV4, + CT_IPV6, + MAX_CT +} CLIENT_CONNECTIVITY_TYPE; + //----------------------------------------------------------------------------- // Function prototype //----------------------------------------------------------------------------- diff --git a/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp b/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp index ebc65a7..a2097ce 100644 --- a/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp +++ b/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp @@ -34,10 +34,12 @@ #define TAG "occlientbasicops" static int UNICAST_DISCOVERY = 0; static int TEST_CASE = 0; +static int CONN_TYPE = 0; static int IPV4_ADDR_SIZE = 16; static char UNICAST_DISCOVERY_QUERY[] = "coap://%s:6298/oic/res"; static char MULTICAST_DISCOVERY_QUERY[] = "/oic/res"; +OCConnectivityType discoveryReqConnType = CT_ADAPTER_IP; static std::string putPayload = "{\"oic\":[{\"rep\":{\"state\":\"off\",\"power\":10}}]}"; static std::string coapServerIP; @@ -66,12 +68,15 @@ void handleSigInt(int signum) static void PrintUsage() { - OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3>"); + OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1|2>"); OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources"); OC_LOG(INFO, TAG, "-t 1 : Discover Resources"); OC_LOG(INFO, TAG, "-t 2 : Discover Resources and" " Initiate Nonconfirmable Get/Put/Post Requests"); OC_LOG(INFO, TAG, "-t 3 : Discover Resources and Initiate Confirmable Get/Put/Post Requests"); + OC_LOG(INFO, TAG, "-c 0 : Default IPv4 and IPv6 auto-selection"); + OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type"); + OC_LOG(INFO, TAG, "-c 2 : IPv6 Connectivity Type (IPv6 not currently supported)"); } OCStackResult InvokeOCDoResource(std::ostringstream &query, @@ -233,7 +238,6 @@ int InitDiscovery() OCMethod method; OCCallbackData cbData; char szQueryUri[MAX_URI_LENGTH] = { 0 }; - OCConnectivityType discoveryReqConnType; if (UNICAST_DISCOVERY) { @@ -250,7 +254,6 @@ int InitDiscovery() OC_LOG(ERROR, TAG, "!! Bad input for IPV4 address. !!"); return OC_STACK_INVALID_PARAM; } - discoveryReqConnType = CT_ADAPTER_IP; method = OC_REST_GET; } else @@ -291,7 +294,7 @@ int main(int argc, char* argv[]) int opt; struct timespec timeout; - while ((opt = getopt(argc, argv, "u:t:")) != -1) + while ((opt = getopt(argc, argv, "u:t:c:")) != -1) { switch(opt) { @@ -301,6 +304,9 @@ int main(int argc, char* argv[]) case 't': TEST_CASE = atoi(optarg); break; + case 'c': + CONN_TYPE = atoi(optarg); + break; default: PrintUsage(); return -1; @@ -308,12 +314,37 @@ int main(int argc, char* argv[]) } if ((UNICAST_DISCOVERY != 0 && UNICAST_DISCOVERY != 1) || - (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS) ) + (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS)|| + (CONN_TYPE < CT_ADAPTER_DEFAULT || CONN_TYPE >= MAX_CT)) { PrintUsage(); return -1; } + + if(CONN_TYPE == CT_ADAPTER_DEFAULT) + { + discoveryReqConnType = CT_DEFAULT; + } + else if(CONN_TYPE == CT_IPV4) + { + discoveryReqConnType = CT_IP_USE_V4; + } + else if(CONN_TYPE == CT_IPV6) + { + //TODO: Remove when IPv6 is available. + //discoveryReqConnType = CT_IP_USE_V6; + OC_LOG(ERROR, TAG, "IPv6 is currently not supported !!!!"); + PrintUsage(); + return -1; + } + else + { + printf("Using Default Connectivity type\n\n"); + PrintUsage(); + } + + // Initialize Persistent Storage for SVR database OCPersistentStorage ps = {}; ps.open = client_fopen; diff --git a/resource/csdk/stack/samples/linux/secure/occlientbasicops.h b/resource/csdk/stack/samples/linux/secure/occlientbasicops.h index 8dee2f2..2262553 100644 --- a/resource/csdk/stack/samples/linux/secure/occlientbasicops.h +++ b/resource/csdk/stack/samples/linux/secure/occlientbasicops.h @@ -37,6 +37,17 @@ typedef enum { MAX_TESTS } CLIENT_TEST; +/** + * List of connectivity types that can be initiated from the client + * Required for user input validation + */ +typedef enum { + CT_ADAPTER_DEFAULT = 0, + CT_IPV4, + CT_IPV6, + MAX_CT +} CLIENT_CONNECTIVITY_TYPE; + //----------------------------------------------------------------------------- // Function prototype //----------------------------------------------------------------------------- diff --git a/resource/examples/devicediscoveryclient.cpp b/resource/examples/devicediscoveryclient.cpp index e5982f1..dded9ae 100644 --- a/resource/examples/devicediscoveryclient.cpp +++ b/resource/examples/devicediscoveryclient.cpp @@ -32,6 +32,13 @@ using namespace OC; +static void printUsage() +{ + std::cout << "Usage devicediscoveryclient <0|1>" << std::endl; + std::cout << "connectivityType: Default IP" << std::endl; + std::cout << "connectivityType 0: IPv4" << std::endl; + std::cout << "connectivityType 1: IPv6 (Currently not supported !)" << std::endl; +} //Callback after device information is received void receivedPlatformInfo(const OCRepresentation& rep) { @@ -90,6 +97,7 @@ int main(int argc, char* argv[]) { std::string platformDiscoveryURI = "/oic/p"; std::string deviceDiscoveryURI = "/oic/d"; + //Default Connectivity type OCConnectivityType connectivityType = CT_ADAPTER_IP; if(argc == 2) @@ -103,12 +111,22 @@ int main(int argc, char* argv[]) { { if(optionSelected == 0) { - connectivityType = CT_ADAPTER_IP; + std::cout << "Using IPv4."<< std::endl; + connectivityType = CT_IP_USE_V4; + } + else if(optionSelected == 1) + { + std::cout << "IPv6 is currently not supported."<< std::endl; + printUsage(); + return -1; + //TODO: printUsage to be removed when IPv6 is available. + //connectivityType = CT_ADAPTER_IP; } else { - std::cout << "Invalid connectivity type selected. Using default IP" - << std::endl; + std::cout << "Invalid connectivity type selected." << std::endl; + printUsage(); + return -1; } } else @@ -123,9 +141,7 @@ int main(int argc, char* argv[]) { } else { - std::cout << "Usage devicediscoveryclient 0" << std::endl; - std::cout << "connectivityType: Default IP" << std::endl; - std::cout << "connectivityType 0: IP" << std::endl; + printUsage(); } // Create PlatformConfig object PlatformConfig cfg { diff --git a/resource/examples/fridgeclient.cpp b/resource/examples/fridgeclient.cpp index 8a6cfbd..0536300 100644 --- a/resource/examples/fridgeclient.cpp +++ b/resource/examples/fridgeclient.cpp @@ -38,6 +38,13 @@ namespace PH = std::placeholders; const uint16_t API_VERSION = 2048; const uint16_t TOKEN = 3000; +static void printUsage() +{ + std::cout << "Usage: fridgeclient <0|1>" < curResource; std::mutex curResourceLock; +static void printUsage() +{ + std::cout<<"Usage: garageclient <0|1> \n"; + std::cout<<"ConnectivityType: Default IP\n"; + std::cout<<"ConnectivityType 0: IPv4 \n"; + std::cout<<"ConnectivityType 1: IPv6 \n"; +} + class Garage { public: @@ -288,7 +296,7 @@ int main(int argc, char* argv[]) { std::ostringstream requestURI; - OCConnectivityType connectivityType = CT_DEFAULT; + OCConnectivityType connectivityType = CT_ADAPTER_IP; if(argc == 2) { @@ -301,7 +309,16 @@ int main(int argc, char* argv[]) { { if(optionSelected == 0) { - connectivityType = CT_ADAPTER_IP; + std::cout << "Using IPv4."<< std::endl; + connectivityType = CT_IP_USE_V4; + } + else if(optionSelected == 1) + { + std::cout << "IPv6 is currently not supported."<< std::endl; + printUsage(); + return -1; + //TODO: printUsage to be removed when IPv6 is available. + //connectivityType = CT_IP_USE_V6; } else { @@ -321,9 +338,8 @@ int main(int argc, char* argv[]) { } else { - std::cout<<"Usage: garageclient 0\n"; - std::cout<<"ConnectivityType: Default IP\n"; - std::cout<<"ConnectivityType 0: IP\n"; + printUsage(); + std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl; } // Create PlatformConfig object diff --git a/resource/examples/groupserver.cpp b/resource/examples/groupserver.cpp index 0211113..6f010aa 100644 --- a/resource/examples/groupserver.cpp +++ b/resource/examples/groupserver.cpp @@ -33,6 +33,13 @@ namespace PH = std::placeholders; OCResourceHandle resourceHandle; std::vector< OCResourceHandle > resourceHandleVector; +static void printUsage() +{ + std::cout<<"Usage: groupclient <0|1>\n"; + std::cout<<"ConnectivityType: Default \n"; + std::cout<<"ConnectivityType 0: IPv4\n"; + std::cout<<"ConnectivityType 1: IPv6\n"; +} void foundResource(std::shared_ptr< OCResource > resource) { @@ -80,7 +87,7 @@ int main(int argc, char* argv[]) { ostringstream requestURI; - OCConnectivityType connectivityType = CT_DEFAULT; + OCConnectivityType connectivityType = CT_ADAPTER_IP; if(argc == 2) { @@ -93,7 +100,16 @@ int main(int argc, char* argv[]) { if(optionSelected == 0) { - connectivityType = CT_ADAPTER_IP; + std::cout << "Using IPv4."<< std::endl; + connectivityType = CT_IP_USE_V4; + } + else if(optionSelected == 1) + { + std::cout << "IPv6 is currently not supported."<< std::endl; + printUsage(); + return -1; + //TODO: printUsage to be removed when IPv6 is available. + //connectivityType = CT_IP_USE_V6; } else { @@ -112,9 +128,8 @@ int main(int argc, char* argv[]) } else { - std::cout<<"Usage: groupclient 0\n"; - std::cout<<"ConnectivityType: Default \n"; - std::cout<<"ConnectivityType 0: IP\n"; + printUsage(); + } PlatformConfig config diff --git a/resource/examples/presenceclient.cpp b/resource/examples/presenceclient.cpp index 9111ba8..e94dcf8 100644 --- a/resource/examples/presenceclient.cpp +++ b/resource/examples/presenceclient.cpp @@ -65,7 +65,7 @@ void printUsage() << std::endl; std::cout<<"ConnectivityType: Default IPv4" << std::endl; std::cout << "-c 0 : Send message with IPv4" << std::endl; - std::cout << "-c 1 : Send message with IPv6" << std::endl; + std::cout << "-c 1 : Send message with IPv6 (Currently Not Supported)" << std::endl; } // Callback to presence @@ -221,7 +221,16 @@ int main(int argc, char* argv[]) { { if(optionSelected == 0) { - connectivityType = CT_ADAPTER_IP; + std::cout << "Using IPv4."<< std::endl; + connectivityType = CT_IP_USE_V4; + } + else if(optionSelected == 1) + { + std::cout << "IPv6 is currently not supported."<< std::endl; + printUsage(); + return -1; + //TODO: printUsage to be removed when IPv6 is available. + //connectivityType = CT_IP_USE_V6; } else { diff --git a/resource/examples/roomclient.cpp b/resource/examples/roomclient.cpp index 1f4ef16..11abf73 100644 --- a/resource/examples/roomclient.cpp +++ b/resource/examples/roomclient.cpp @@ -41,6 +41,13 @@ int observe_count() return ++oc; } +static void printUsage() +{ + std::cout << "Usage roomclient <0|1>" << std::endl; + std::cout<<"connectivityType: Default" << std::endl; + std::cout << "connectivityType 0: IPv4" << std::endl; + std::cout << "connectivityType 0: IPv46 (Currently Not Supported)" << std::endl; +} // Forward declaration void putRoomRepresentation(std::shared_ptr resource); void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode); @@ -223,7 +230,7 @@ int main(int argc, char* argv[]) { std::ostringstream requestURI; - OCConnectivityType connectivityType = CT_DEFAULT; + OCConnectivityType connectivityType = CT_ADAPTER_IP; if(argc == 2) { try @@ -235,11 +242,20 @@ int main(int argc, char* argv[]) { { if(optionSelected == 0) { - connectivityType = CT_ADAPTER_IP; + std::cout << "Using IPv4."<< std::endl; + connectivityType = CT_IP_USE_V4; + } + else if(optionSelected == 1) + { + std::cout << "IPv6 is currently not supported."<< std::endl; + printUsage(); + return -1; + //TODO: printUsage to be removed when IPv6 is available. + //connectivityType = CT_IP_USE_V6; } else { - std::cout << "Invalid connectivity type selected. Using default IP" << std::endl; + std::cout << "Invalid connectivity type selected. Using default IP"<< std::endl; } } else @@ -254,9 +270,8 @@ int main(int argc, char* argv[]) { } else { - std::cout << "Usage roomclient 0" << std::endl; - std::cout<<"connectivityType: Default" << std::endl; - std::cout << "connectivityType 0: IP" << std::endl; + std::cout << "Default input argument. Using IP as Default connectivity type" << std::endl; + printUsage(); } // Create PlatformConfig object diff --git a/resource/examples/simpleclientHQ.cpp b/resource/examples/simpleclientHQ.cpp index da84d5d..b82e636 100644 --- a/resource/examples/simpleclientHQ.cpp +++ b/resource/examples/simpleclientHQ.cpp @@ -374,14 +374,15 @@ void PrintUsage() std::cout << " ObserveType : 1 - Observe" << std::endl; std::cout << " ObserveType : 2 - ObserveAll" << std::endl; std::cout << " ConnectivityType: Default IP" << std::endl; - std::cout << " ConnectivityType : 0 - IP"<< std::endl; + std::cout << " ConnectivityType : 0 - IPv4"<< std::endl; + std::cout << " ConnectivityType : 0 - IPv6 (Current Not Supported )"<< std::endl; } int main(int argc, char* argv[]) { std::ostringstream requestURI; - OCConnectivityType connectivityType = CT_DEFAULT; + OCConnectivityType connectivityType = CT_ADAPTER_IP; try { if (argc == 1) @@ -407,7 +408,16 @@ int main(int argc, char* argv[]) { { if(optionSelected == 0) { - connectivityType = CT_ADAPTER_IP; + std::cout << "Using IPv4."<< std::endl; + connectivityType = CT_IP_USE_V4; + } + else if(optionSelected == 1) + { + std::cout << "IPv6 is currently not supported."<< std::endl; + PrintUsage(); + return -1; + //TODO: printUsage to be removed when IPv6 is available. + //connectivityType = CT_IP_USE_V6; } else { @@ -431,6 +441,8 @@ int main(int argc, char* argv[]) { catch(std::exception& e) { std::cout << "Invalid input argument." << std::endl; + PrintUsage(); + return -1; } diff --git a/resource/examples/simpleclientserver.cpp b/resource/examples/simpleclientserver.cpp index 90b7682..cacb106 100644 --- a/resource/examples/simpleclientserver.cpp +++ b/resource/examples/simpleclientserver.cpp @@ -33,6 +33,13 @@ #include "OCApi.h" using namespace OC; +static void printUsage() +{ + std::cout<< " Usage simpleclientserver <0|1>" << std::endl; + std::cout<< " ConnectivityType: Default IP" << std::endl; + std::cout << " ConnectivityType : 0 - IPv4" << std::endl; + std::cout << " ConnectivityType : 1 - IPv6 (Currently Not Supported)" << std::endl; +} class ClientWorker { @@ -309,7 +316,16 @@ int main(int argc, char* argv[]) { if(optionSelected == 0) { - connectivityType = CT_ADAPTER_IP; + std::cout << "Using IPv4."<< std::endl; + connectivityType = CT_IP_USE_V4; + } + else if(optionSelected == 1) + { + std::cout << "IPv6 is currently not supported."<< std::endl; + printUsage(); + return -1; + //TODO: printUsage to be removed when IPv6 is available. + //connectivityType = CT_IP_USE_V6; } else { @@ -328,9 +344,7 @@ int main(int argc, char* argv[]) } else { - std::cout<< "Usage simpleclientserver 0>" << std::endl; - std::cout<< " ConnectivityType: Default IP" << std::endl; - std::cout << " ConnectivityType : 0 - IP" << std::endl; + printUsage(); } PlatformConfig cfg {