case OPTYPE_REMOVE_BOM:
u.expr.v1=p.u.expr.v1->clone();
break;
+ case OPTYPE_HOSTID: // [v1]
+ u.expr.v1=p.u.expr.v1?p.u.expr.v1->clone():0;
+ break;
case OPTYPE_ADD: // v1 v2
case OPTYPE_SUBTRACT:
case OPTYPE_MULTIPLY:
case OPTYPE_REMOVE_BOM:
case OPTYPE_GET_STRINGENCODING:
case OPTYPE_DECODE_BASE64:
+ case OPTYPE_HOSTID:
delete u.expr.v1;
break;
case OPTYPE_ADD: // v1 v2
if(!p_v1) FATAL_ERROR("Value::Value()");
u.expr.v1=p_v1;
break;
+ case OPTYPE_HOSTID:
+ u.expr.v1=p_v1;
+ break;
default:
FATAL_ERROR("Value::Value()");
} // switch
case OPTYPE_DECODE_BASE64:
u.expr.v1->set_fullname(p_fullname+".<operand>");
break;
+ case OPTYPE_HOSTID: // [v1]
+ if(u.expr.v1) u.expr.v1->set_fullname(p_fullname+".<operand>");
+ break;
case OPTYPE_ADD: // v1 v2
case OPTYPE_SUBTRACT:
case OPTYPE_MULTIPLY:
case OPTYPE_DECODE_BASE64:
u.expr.v1->set_my_scope(p_scope);
break;
+ case OPTYPE_HOSTID: // [v1]
+ if(u.expr.v1) u.expr.v1->set_my_scope(p_scope);
+ break;
case OPTYPE_ADD: // v1 v2
case OPTYPE_SUBTRACT:
case OPTYPE_MULTIPLY:
case OPTYPE_REMOVE_BOM:
u.expr.v1->set_code_section(p_code_section);
break;
+ case OPTYPE_HOSTID: // [v1]
+ if(u.expr.v1) u.expr.v1->set_code_section(p_code_section);
+ break;
case OPTYPE_ADD: // v1 v2
case OPTYPE_SUBTRACT:
case OPTYPE_MULTIPLY:
case OPTYPE_TTCN2STRING:
case OPTYPE_GET_STRINGENCODING:
case OPTYPE_ENCODE_BASE64:
+ case OPTYPE_HOSTID:
return Type::T_CSTR;
case OPTYPE_INT2UNICHAR:
case OPTYPE_OCT2UNICHAR:
return "encode_base64()";
case OPTYPE_DECODE_BASE64:
return "decode_base64()";
+ case OPTYPE_HOSTID: // [v1]
+ return "hostid()";
case OPTYPE_ADD: // v1 v2
return "+";
case OPTYPE_SUBTRACT:
chk_expr_val_ustr_7bitchars(v1, the, opname);
}
break;
+ case OPTYPE_HOSTID:
+ v1=u.expr.v1 ? u.expr.v1 : 0;
+ if (v1)
+ {
+ Error_Context cntxt(this, "In the first operand of operation `%s'", opname);
+ v1->set_lowerid_to_ref();
+ tt1=v1->get_expr_returntype(exp_val);
+ chk_expr_operandtype_cstr(tt1, second, opname, v1);
+ chk_expr_eval_value(v1, t_chk, refch, exp_val);
+ }
+ break;
case OPTYPE_UNICHAR2OCT: // v1 [v2]
v1=u.expr.v1;
{
case OPTYPE_DECVALUE_UNICHAR:
case OPTYPE_CHECKSTATE_ANY:
case OPTYPE_CHECKSTATE_ALL:
+ case OPTYPE_HOSTID:
break;
case OPTYPE_TESTCASENAME: { // -
if (!my_scope) FATAL_ERROR("Value::evaluate_value()");
case OPTYPE_DECVALUE_UNICHAR:
case OPTYPE_CHECKSTATE_ANY:
case OPTYPE_CHECKSTATE_ALL:
+ case OPTYPE_HOSTID:
return true;
case OPTYPE_COMP_NULL: // -
return false;
u.expr.t1->chk_recursions(refch);
refch.prev_state();
break;
+ case OPTYPE_HOSTID: // [v1]
+ if (u.expr.v1) {
+ refch.mark_state();
+ u.expr.v1->chk_recursions(refch);
+ refch.prev_state();
+ }
+ break;
case OPTYPE_ADD: // v1 v2
case OPTYPE_SUBTRACT:
case OPTYPE_MULTIPLY:
case OPTYPE_REMOVE_BOM:
self_ref |= chk_expr_self_ref_val(u.expr.v1, lhs);
break;
+ case OPTYPE_HOSTID: // [v1]
+ if (u.expr.v1) self_ref |= chk_expr_self_ref_val(u.expr.v1, lhs);
+ break;
case OPTYPE_ADD: // v1 v2
case OPTYPE_SUBTRACT: // v1 v2
case OPTYPE_MULTIPLY: // v1 v2
if (u.expr.v2) return create_stringRepr_predef2("encvalue_unichar");
else return create_stringRepr_predef1("encvalue_unichar");
}
+ case OPTYPE_HOSTID: {
+ if (u.expr.v1) return create_stringRepr_predef1("hostid");
+ else return string("hostid()");
+ }
case OPTYPE_DECVALUE_UNICHAR: {
if (u.expr.v3) {
string ret_val("decvalue_unichar");
ass = u.expr.r2->get_refd_assignment();
if (parlist) str = parlist->rearrange_init_code(str, usage_mod);
break; }
+ case OPTYPE_HOSTID:
+ if (u.expr.v1) str = u.expr.v1->rearrange_init_code(str, usage_mod);
+ break;
case OPTYPE_ADD:
case OPTYPE_SUBTRACT:
case OPTYPE_MULTIPLY:
case OPTYPE_DECVALUE_UNICHAR:
generate_code_expr_decvalue_unichar(expr);
break;
+ case OPTYPE_HOSTID:
+ generate_code_expr_hostid(expr);
+ break;
case OPTYPE_OCT2HEX:
generate_code_expr_predef1(expr, "oct2hex", u.expr.v1);
break;
expr->expr = mputstr(expr->expr, ")");
}
+ void Value::generate_code_expr_hostid(expression_struct *expr)
+ {
+ expr->expr = mputstr(expr->expr, "TTCN_Runtime::get_host_address(");
+ if (u.expr.v1) u.expr.v1->generate_code_expr_mandatory(expr);
+ else expr->expr = mputstr(expr->expr, "CHARSTRING(\"Ipv4orIpv6\")");
+ expr->expr = mputstr(expr->expr, ")");
+ }
+
char* Value::generate_code_char_coding_check(expression_struct *expr, Value *v, const char *name)
{
expression_struct expr2;
case OPTYPE_PROF_RUNNING:
case OPTYPE_CHECKSTATE_ANY:
case OPTYPE_CHECKSTATE_ALL:
+ case OPTYPE_HOSTID:
return true;
case OPTYPE_ENCODE:
case OPTYPE_DECODE:
OPTYPE_ANY2UNISTR, // logarg, length = 1
OPTYPE_CHECKSTATE_ANY, // [r1] v2, port or any
OPTYPE_CHECKSTATE_ALL, // [r1] v2, port or all
+ OPTYPE_HOSTID, // [v1]
NUMBER_OF_OPTYPES // must be last
};
* COMP_ALIVE_ALL, COMP_ALIVE_ANY, TMR_RUNNING_ANY, GETVERDICT,
* PROF_RUNNING */
Value(operationtype_t p_optype);
- /** Constructor used by V_EXPR "v1" */
+ /** Constructor used by V_EXPR "v1" or [v1] */
Value(operationtype_t p_optype, Value *p_v1);
/** Constructor used by V_EXPR "ti1": LENGTHOF, SIZEOF, VALUEOF, TTCN2STRING */
Value(operationtype_t p_optype, TemplateInstance *p_ti1);
void generate_code_expr_checkstate(expression_struct *expr);
+ void generate_code_expr_hostid(expression_struct *expr);
+
char* generate_code_char_coding_check(expression_struct *expr, Value *v, const char *name);
/** Helper function for \a generate_code_init(). It handles the
encvalue_unichar RETURN(encvalue_unicharKeyWord);
decvalue_unichar RETURN(decvalue_unicharKeyWord);
any2unistr RETURN(any2unistrKeyWord);
+hostid RETURN(hostidKeyWord);
/* Values */
%token encvalue_unicharKeyWord
%token decvalue_unicharKeyWord
%token any2unistrKeyWord
+%token hostidKeyWord
/* Multi-character operators */
$$ = new Value(Value::V_ERROR);
$$->set_location(infile, @$);
}
+| hostidKeyWord '(' ')'
+ {
+ Value *null_value = NULL;
+ $$ = new Value(Value::OPTYPE_HOSTID, null_value);
+ $$->set_location(infile, @$);
+ }
+| hostidKeyWord '(' optError Expression optError ')'
+ {
+ $$ = new Value(Value::OPTYPE_HOSTID, $4);
+ $$->set_location(infile, @$);
+ }
;
DecValueArg:
* Forstner, Matyas
* Kovacs, Ferenc
* Raduly, Csaba
+ * Szabo, Bence Janos
* Szabo, Janos Zoltan – initial implementation
* Zalanyi, Balazs Andor
*
public:
static const NetworkFamily& get_network_family() { return hcnh.get_family(); }
+ static bool has_local_address() { return local_addr_set; }
static void set_local_address(const char *host_name);
static const IPAddress *get_local_address();
static void set_mc_address(const char *host_name,
* Lovassy, Arpad
* Raduly, Csaba
* Szabados, Kristof
+ * Szabo, Bence Janos
* Szabo, Janos Zoltan – initial implementation
* Zalanyi, Balazs Andor
* Pandi, Krisztian
return host_name;
}
+CHARSTRING TTCN_Runtime::get_host_address(const CHARSTRING& type)
+{
+ if (type != "Ipv4orIpv6" && type != "Ipv4" && type != "Ipv6") {
+ TTCN_error("The argument of hostid function must be Ipv4orIpv6 or Ipv4"
+ "or Ipv6. %s is not a valid argument.", (const char*)type);
+ }
+
+ // Return empty if no host address could be retrieved
+ if (!TTCN_Communication::has_local_address()) {
+ return CHARSTRING("");
+ }
+ const IPAddress *address = TTCN_Communication::get_local_address();
+
+ // Return empty if the type is not matching the address type
+ if (type == "Ipv4") {
+ const IPv4Address * ipv4 = dynamic_cast<const IPv4Address*>(address);
+ if (ipv4 == NULL) {
+ return CHARSTRING("");
+ }
+ } else if (type == "Ipv6") {
+ const IPv6Address * ipv6 = dynamic_cast<const IPv6Address*>(address);
+ if (ipv6 == NULL) {
+ return CHARSTRING("");
+ }
+ }
+ // Return the string representation of the address
+ return CHARSTRING(address->get_addr_str());
+}
+
CHARSTRING TTCN_Runtime::get_testcase_id_macro()
{
if (in_controlpart()) TTCN_error("Macro %%testcaseId cannot be used from "
* Kovacs, Ferenc
* Raduly, Csaba
* Szabados, Kristof
+ * Szabo, Bence Janos
* Szabo, Janos Zoltan – initial implementation
* Zalanyi, Balazs Andor
*
/// Returns a string which must not be freed.
static const char *get_host_name();
+
+ static CHARSTRING get_host_address(const CHARSTRING& type);
static CHARSTRING get_testcase_id_macro();
static CHARSTRING get_testcasename();
macros visibility hexstrOper ucharstrOper objidOper CRTR00015758 slider \
XML ipv6 implicitOmit testcase_defparam transparent HQ16404 cfgFile \
all_from lazyEval tryCatch text2ttcn json junitlogger ttcn2json profiler templateOmit \
-customEncoding makefilegen uidChars checkstate
+customEncoding makefilegen uidChars checkstate hostid
ifdef DYN
DIRS += loggerplugin
--- /dev/null
+/******************************************************************************
+ * Copyright (c) 2000-2016 Ericsson Telecom AB
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Szabo, Bence Janos
+ *
+ ******************************************************************************/
+
+module Hostid
+{
+ type port MyPort message
+ {
+ inout charstring
+ } with { extension "internal" }
+
+ type component MyMTCType
+ {
+ port MyPort MyPCO1;
+ }
+
+ type component MTCType
+ {
+ port MyPort MyPCO2;
+ }
+
+ testcase tc_hostid() runs on MyMTCType system MTCType
+ {
+ // ip should be "127.0.0.1" aka localhost, I think...
+ var charstring ip := hostid("Ipv4orIpv6");
+ log(ip);
+ if(ip != "") {
+ setverdict(pass);
+ }else {
+ setverdict(fail);
+ }
+
+ // The same as hostid("Ipv4orIpv6")
+ ip := hostid();
+ log(ip);
+ if(ip != "") {
+ setverdict(pass);
+ }else {
+ setverdict(fail);
+ }
+
+ ip := hostid("Ipv4");
+ if(ip != "") {
+ setverdict(pass);
+ }else {
+ setverdict(fail);
+ }
+
+ ip := hostid("Ipv6");
+ if(ip == "") {
+ setverdict(pass);
+ }else {
+ setverdict(fail);
+ }
+ }
+
+ control
+ {
+ execute(tc_hostid());
+ }
+}
--- /dev/null
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ..
+include $(TOPDIR)/Makefile.regression
+
+.SUFFIXES: .ttcn .hh
+.PHONY: all clean dep run
+
+TTCN3_LIB = ttcn3$(RT2_SUFFIX)-parallel$(DYNAMIC_SUFFIX)
+
+TTCN3_MODULES = Hostid.ttcn
+
+GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc)
+GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh)
+ifdef CODE_SPLIT
+GENERATED_SOURCES := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), .cc _seq.cc _set.cc _seqof.cc _setof.cc _union.cc))
+endif
+
+USER_SOURCES =
+
+OBJECTS = $(GENERATED_SOURCES:.cc=.o) $(USER_SOURCES:.cc=.o)
+
+TARGET = Hostid$(EXESUFFIX)
+
+all: $(TARGET)
+
+$(TARGET): $(GENERATED_SOURCES) $(USER_SOURCES)
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ -L$(TTCN3_DIR)/lib -l$(TTCN3_LIB) -L$(OPENSSL_DIR)/lib -lcrypto $($(PLATFORM)_LIBS)
+
+$(GENERATED_SOURCES) $(GENERATED_HEADERS): compile
+ @if [ ! -f $@ ]; then $(RM) compile; $(MAKE) compile; fi
+
+compile: $(TTCN3_MODULES) $(ASN1_MODULES)
+ $(filter-out -Nold -E, $(TTCN3_COMPILER)) $(COMPILER_FLAGS) $^
+ touch compile
+
+clean distclean:
+ -rm -f $(TARGET) $(OBJECTS) $(GENERATED_HEADERS) \
+ $(GENERATED_SOURCES) *.log Makefile.bak
+
+dep: $(GENERATED_SOURCES)
+ makedepend $(CPPFLAGS) $(GENERATED_SOURCES)
+
+run: $(TARGET)
+ $(TTCN3_DIR)/bin/ttcn3_start $^
+
+