/**
 * Reads properties from the network element.
 *
 * @param[in] ne  A pointer to the network element structure
 */
void
read_properties (onep_network_element_t* ne)
{
    onep_status_t rc;
    char *description = NULL;
    char *product_id = NULL;
    char *serial_number = NULL;
    onep_element_property_t *property = NULL;

    /*
     * Get network element properties
    */
    rc = onep_element_get_property(ne, &property);
    if (rc != ONEP_OK) {
        fprintf(stderr, "\nFailed to get property of network element:"
                " errocode = %d, errormsg = %s",
                rc, onep_strerror(rc));
        return;
    }

    rc = onep_element_property_get_sys_descr(property, &description);
    if (rc != ONEP_OK) {
        fprintf(stderr, "\nFailed to get property system description:"
                " errorcode = %d, errormsg = %s",
                rc, onep_strerror(rc));
        goto cleanup;
    }

    rc = onep_element_property_get_product_id(property, &product_id);
    if (rc != ONEP_OK) {
        fprintf(stderr, "\nFailed to get property product ID:"
                " errorcode = %d, errormsg = %s",
                rc, onep_strerror(rc));
        goto cleanup;
    }

    rc = onep_element_property_get_serial_no(property, &serial_number);
    if (rc != ONEP_OK) {
        fprintf(stderr, "\nFailed to get property serial no.:"
                " errorcode = %d, errormsg = %s",
                rc, onep_strerror(rc));
        goto cleanup;
    }

    fprintf(stderr, "\n----- SysDescr  %s -----"
                    "\n----- ProductId %s -----"
                    "\n----- Serial No %s -----",
                    description, product_id, serial_number);

cleanup:
    rc = onep_element_property_destroy(&property);
    if (rc != ONEP_OK) {
        fprintf(stderr, "\nFailed to destroy element property:"
                " errorcode = %d, errormsg = %s",
                rc, onep_strerror(rc));
    }
    free(description);
    free(product_id);
    free(serial_number);
}
int changeRouterConfig(char* element_hostname)
{
	int ec = EXIT_SUCCESS;
	onep_status_t rc = ONEP_OK;
	onep_network_application_t *nwapp = NULL;
	onep_network_element_t *ne = NULL;
	onep_session_handle_t *sh = NULL;
	onep_element_property_t *property = NULL;
	char *hostname = NULL;
	onep_session_config_t* config = NULL;

	rc = onep_application_get_instance(&nwapp);
	if (rc != ONEP_OK) {
		fprintf(stderr, "\nFailed to get network application: "
			"errorcode = %d, errormsg = %s\n\n",
			rc, onep_strerror(rc));
		ec = EXIT_FAILURE;
		goto cleanup;
	}

	rc = onep_application_set_name(nwapp, appname);
	if (rc != ONEP_OK) {
		fprintf(stderr, "\nFailed to set application name: "
			"errorcode = %d, errormsg = %s\n\n",
			rc, onep_strerror(rc));
	}

	rc = onep_application_get_network_element_by_name(nwapp,
		element_hostname,
		&ne);
	if (rc != ONEP_OK) {
		fprintf(stderr, "\nFailed to get network element: "
			"errorcode = %d, errormsg = %s\n\n",
			rc, onep_strerror(rc));
		ec = EXIT_FAILURE;
		goto cleanup;
	}

	printf("Connecting with onep transport type TLS. \n");
	rc = onep_session_config_new(ONEP_SESSION_TLS, &config);
	if (ONEP_OK != rc) {
		fprintf(stderr, "\nFailed to get config: "
			"errorcode = %d, errormsg = %s",
			rc, onep_strerror(rc));
		(void)onep_session_config_destroy(&config);
		return rc;
	}
	rc = onep_session_config_set_port(config, 15002);
	if (ONEP_OK != rc) {
		fprintf(stderr, "\nFailed to set port: "
			"errorcode = %d, errormsg = %s",
			rc, onep_strerror(rc));
		(void)onep_session_config_destroy(&config);
		return rc;
	}

	rc = onep_session_config_set_tls(
		config, /* Pointer to onep_session_config_t  */
		app_cert, /* Client certificate file path */
		app_private_key,  /* Client private key file path */
		app_private_key_password, /* SSL certificate passcode     */
		network_element_root_cert);  /* Root certificate file path   */

	if (ONEP_OK != rc) {
		fprintf(stderr, "\nFailed to set TLS: errorcode = %d, errormsg = %s",
			rc, onep_strerror(rc));
		if (config)
			(void)onep_session_config_destroy(&config);
		goto disconnect;
		return rc;
	}

	rc = onep_element_connect(ne, username, password, config, &sh);
	if (rc != ONEP_OK) {
		fprintf(stderr, "\nFailed to connect to network element: "
			"errorcode = %d, errormsg = %s\n\n",
			rc, onep_strerror(rc));
		ec = EXIT_FAILURE;
		goto cleanup;
	}

	rc = onep_element_get_property(ne, &property);
	if (rc != ONEP_OK) {
		fprintf(stderr, "\nFailed to get element property: "
			"errorcode = %d, errormsg = %s\n\n",
			rc, onep_strerror(rc));
		ec = EXIT_FAILURE;
		goto disconnect;
	}

	rc = onep_element_property_get_sys_name(property, &hostname);
	if (rc != ONEP_OK) {
		fprintf(stderr, "\nFailed to get system name: "
			"errorcode = %d, errormsg = %s\n\n",
			rc, onep_strerror(rc));
		ec = EXIT_FAILURE;
		goto disconnect;
	}

	onep_vty_t *vty = NULL;
	uint32_t timeout;
	char *response = NULL;

	rc = onep_vty_new(ne, &vty);
	if (rc != ONEP_OK) {
		printf("\nFailed to get vty instance: %d %s", rc, onep_strerror(rc));
		return EXIT_FAILURE;
	}

	rc = onep_vty_open(vty);
	if (rc != ONEP_OK) {
		printf("\nFailed to open vty to Network Element: %d %s", rc,
			onep_strerror(rc));
		return EXIT_FAILURE;
	}

	rc = onep_vty_get_timeout(vty, &timeout);
	if (rc != ONEP_OK) {
		printf("\nFailed to get timeout of vty to Network Element: %d %s", rc,
			onep_strerror(rc));
		return EXIT_FAILURE;
	}

	/* Test command
	char *showCommand = "show access-list DENYACCESS";
	printf("\nWriting a command VTY to the Network Element ... \"%s\"\n",
		showCommand);
	rc = onep_vty_write(vty, showCommand, &response);
	if (rc != ONEP_OK) {
		printf("\nFailed to get response for first from vty: %d %s", rc,
			onep_strerror(rc));
		return EXIT_FAILURE;
	}
	//printf("\n\nResponse for %s is - %s", showCommand, response);
	*/

	char command[1000] = "";
	if ((strncmp(allow, "a", strlen(allow)) == 0) || (strncmp(allow, "A", strlen(allow)) == 0))
		sprintf(command, "configure terminal \r \n ip access-list standard DENYACCESS \r\n no permit %s \r\n end \r\n", ipMask);
	else
		sprintf(command, "configure terminal \r \n ip access-list standard DENYACCESS \r\n permit %s \r\n end \r\n", ipMask);
	//printf("\n\ncommand is - %s\n", command);


	printf("\nWriting a command VTY to the Network Element ... \"%s\"\n",
		command);
	rc = onep_vty_write(vty, command, &response);
	if (rc != ONEP_OK) {
		printf("\nFailed to get response for first from vty: %d %s", rc,
			onep_strerror(rc));
		return EXIT_FAILURE;
	}
	printf("\n\nResponse for %s is - %s", command, response);

	printf("\n Save config changes \n");
	rc = onep_vty_write(vty, "write memory", &response);
	if (rc != ONEP_OK) {
		printf("\nFailed to get response for first from vty: %d %s", rc,
			onep_strerror(rc));
		return EXIT_FAILURE;
	}
	if (hostname)
		free(hostname);

disconnect:
	rc = onep_element_disconnect(ne);
	if (rc != ONEP_OK) {
		fprintf(stderr, "\nFailed to disconnect from network element: "
			"errorcode = %d, errormsg = %s\n\n",
			rc, onep_strerror(rc));
		ec = EXIT_FAILURE;
		goto cleanup;
	}

cleanup:
	if (property)
		(void)onep_element_property_destroy(&property);
	if (sh)
		(void)onep_session_handle_destroy(&sh);
	if (ne)
		(void)onep_element_destroy(&ne);
	if (nwapp)
		(void)onep_application_destroy(&nwapp);

	return ec;
}