/******************************************************************************
 * Copyright (c) 2000-2021 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 ******************************************************************************/
//
//  File:               TCCInterface_Functions.ttcn
//  Description:        TCC Useful Functions: Interface Functions
//  Rev:                <RnXnn>
//  Prodnr:             CNL 113 472
//  Updated:            2010-03-25
//  Contact:            http://ttcn.ericsson.se
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//  Module: TCCInterface_Functions
// 
//  Purpose:
//    This module supports network related operations
// 
//  Module Parameters:
//      - 
// 
//  Module depends on:
//    -
//
///////////////////////////////////////////////////////////////////////////////
module TCCInterface_Functions {

///////////////////////////////////////////////////////////////////////////////
//  Record: IPAddresses
// 
//  Purpose:
//    To store multiple ipv4 and ipv6 addresses typically describing a host.
//    Warning: An own CharstringList type is definied, that is not compatible
//    with any other record of charstring in TITAN's load run time library, which
//    is the defalt, and thus it is not able to directly copy this lists for example
//    to EPTF_CharstringList. 
//
///////////////////////////////////////////////////////////////////////////////
type record of charstring CharstringList;
type record IPAddresses{
  CharstringList ipv4List,
  CharstringList ipv6List
}

///////////////////////////////////////////////////////////////////////////////
//  Enum: TCCInterface_IPAddressType
// 
//  Purpose:
//   An enum type for setting the type of IP addresses. Possible values:
//	IPv4 - for IPv4 type addresses
//	IPv6 - for IPv6 type addresses
//	etc
///////////////////////////////////////////////////////////////////////////////
type enumerated TCCInterface_IPAddressType 
{
  IPv4,
  IPv6
};

///////////////////////////////////////////////////////////////////////////////
//  Function: f_setIP
// 
//  Purpose:
//    Set IP address, subnet mask and broadcast address in a network inteface
//    If number is set, a range of virtual interfaces are set up with
//    continuous IP address (no subnet mask, broadcast checking)
//
//  Parameters:
//    interface - *in* *charstring* - network interface
//    ipaddress - *in* *charstring* - starting IP address
//    subnetmask - *in* *charstring* - subnetmask
//    broadcast - *in* *charstring* - broadcast
//    number - *in* *integer* - number of interfaces to set up
// 
//  Return Value:
//    -
//
//  Errors:
//    - 
// 
//  Detailed description:
//    -
// 
///////////////////////////////////////////////////////////////////////////////
external function f_setIP(in charstring interface, in charstring ipaddress, 
  in charstring subnetmask, in charstring broadcast,
  in integer number := 1);

///////////////////////////////////////////////////////////////////////////////
//  Function: f_setIP_ip
// 
//  Purpose:
//    Set IP address, subnet mask in a network inteface
//    Uses RTLN netlink interface on linux, which is faster than original POSIX.    
//
//  Parameters:
//    interface - *in* *charstring* - network interface
//    ipaddress - *in* *charstring* - starting IP address
//    prefix - *in* *integer* - subnetmask of the ipaddress
//    v_set - *in* *integer* - Determines behavior, 1 sets, other deletes the IP
// 
//  Return Value:
//    True on success, false in other cases.
//
//  Errors:
//    Many possibilities, all generates a TTCN_warning
// 
//  Detailed description:
//    -
// 
///////////////////////////////////////////////////////////////////////////////
external function f_setIP_ip(in charstring interface, in charstring ipaddress, in integer prefix := 32, in integer v_set := 1) return boolean;

///////////////////////////////////////////////////////////////////////////////
//  Function: f_delIP_ip
// 
//  Purpose:
//    Deletes IP address, subnet mask in a network inteface
//    Uses RTLN netlink interface on linux, which is faster than original POSIX.    
//
//  Parameters:
//    interface - *in* *charstring* - network interface
//    ipaddress - *in* *charstring* - starting IP address
//    prefix - *in* *integer* - subnetmask of the ipaddress
// 
//  Return Value:
//    True on success, false in other cases.
//
//  Errors:
//    Many possibilities, all generates a TTCN_warning
// 
//  Detailed description:
//    -
// 
///////////////////////////////////////////////////////////////////////////////
external function f_delIP_ip(in charstring interface, in charstring ipaddress, in integer prefix := 32) return boolean;

///////////////////////////////////////////////////////////////////////////////
//  Function: f_deleteIP
// 
//  Purpose:
//    Delete IP address from a network inteface
//
//  Parameters:
//    interface - *in* *charstring* - network interface
// 
//  Return Value:
//    -
//
//  Errors:
//    - 
// 
//  Detailed description:
//    -
// 
///////////////////////////////////////////////////////////////////////////////  
external function f_deleteIP(in charstring interface);

///////////////////////////////////////////////////////////////////////////////
//  Function: f_getIP
// 
//  Purpose:
//    Get IP address, subnet mask and broadcast address from a network inteface
//
//  Parameters:
//    interface - *in* *charstring* - network interface
//    ip - *out* *charstring* - IP address
//    netmask - *out* *charstring* - netmask
//    broadcast - *out* *charstring* - broadcast
//    addressType - *in* <TCCInterface_IPAddressType> - type of IP addresses (default is IPv4)
// 
//  Return Value:
//    -
//
//  Errors:
//    - 
// 
//  Detailed description:
//    -
// 
///////////////////////////////////////////////////////////////////////////////  
external function f_getIP(in charstring interface, out charstring ip,
  out charstring netmask, out charstring broadcast, in TCCInterface_IPAddressType addressType:=IPv4);

///////////////////////////////////////////////////////////////////////////////
//  Function: f_setInterfaceUp
// 
//  Purpose:
//    Set up a network interface
//
//  Parameters:
//    interface - *in* *charstring* - network interface
//    addressType - *in* <TCCInterface_IPAddressType> - type of IP addresses (default is IPv4)
// 
//  Return Value:
//    -
//
//  Errors:
//    - 
// 
//  Detailed description:
//    -
// 
///////////////////////////////////////////////////////////////////////////////
external function f_setInterfaceUp(in charstring interface, in TCCInterface_IPAddressType addressType:=IPv4);

///////////////////////////////////////////////////////////////////////////////
//  Function: f_setInterfaceDown
// 
//  Purpose:
//    Set down a network interface
//
//  Parameters:
//    interface - *in* *charstring* - network interface
//    addressType - *in* <TCCInterface_IPAddressType> - type of IP addresses (default is IPv4)
// 
//  Return Value:
//    -
//
//  Errors:
//    - 
// 
//  Detailed description:
//    -
// 
///////////////////////////////////////////////////////////////////////////////
external function f_setInterfaceDown(in charstring interface, in TCCInterface_IPAddressType addressType:=IPv4);

///////////////////////////////////////////////////////////////////////////////
//  Function: f_getHostName
// 
//  Purpose:
//    Get name of host
//
//  Parameters:
//    -
// 
//  Return Value:
//    charstring - name of the host
//
//  Errors:
//    - 
// 
//  Detailed description:
//    -
// 
///////////////////////////////////////////////////////////////////////////////
external function f_getHostName() return charstring;

///////////////////////////////////////////////////////////////////////////////
//  Function: f_getIpAddr
// 
//  Purpose:
//    Get IP address of host
//
//  Parameters:
//    hostname - *in* *charstring* - name of the host
//    addressType - *in* <TCCInterface_IPAddressType> - type of IP addresses (default is IPv4)
// 
//  Return Value:
//    charstring - IP address of the host
//
//  Errors:
//    - 
// 
//  Detailed description:
//    -
// 
///////////////////////////////////////////////////////////////////////////////
external function f_getIpAddr(in charstring hostname, in TCCInterface_IPAddressType addressType:=IPv4) return charstring;

///////////////////////////////////////////////////////////////////////////////
//  Function: f_getIpAddresses
// 
//  Purpose:
//    Get both IPv4 and IPv6 addresses of host. 
//
//  Parameters:
//    hostname - *in* *charstring* - name of the host
// 
//  Return Value:
//    Initialized IPAddresses structure
//
//  Errors:
//    Drops TTCN_Warnings on fault
// 
//  Detailed description:
//    -
// 
///////////////////////////////////////////////////////////////////////////////
external function f_getIpAddresses(in charstring hostname) return IPAddresses;
}
