Академический Документы
Профессиональный Документы
Культура Документы
Version 10.5
September, 2014
Property of Triangle MicroWorks, Inc.
This Documentation and its associated distribution media contain proprietary information of Triangle
MicroWorks, Inc. and may not be copied or distributed in any form without the written permission of
Triangle MicroWorks, Inc.
Copies of the source code may be made only for backup purposes.
Congratulations on your purchase of a Triangle MicroWorks, Inc. (TMW) IEC 61850 Server Source Code
Library. This product is a member of a family of communication protocol libraries supported by Triangle
MicroWorks, Inc. These libraries were designed to be flexible, easy to use, and easily ported to a wide
variety of hardware and software platforms. For these reasons, the Triangle MicroWorks, Inc. Source Code
Libraries will provide an excellent solution to your communication protocol requirements.
Please Note
Your license agreement limits the installation of this source
code library to specific products. Before installing this source
code library in a new target application, check your license
agreement to verify that it allows use on that target
application. Contact Triangle MicroWorks, Inc. for
information about extending the number of target
applications that may use this source code library.
The TMW implementation of the IEC 61850 GOOSE services provides a mechanism for sending and
receiving the standardized messages. The IEC 61850 GOOSE services differ from the GSSE definitions in
that generalized data structures can be exchanged, rather than fixed bit strings. The APIs are quite similar.
The primary distinction is that the application software must handle the encoding and decoding of the
‘payload’ data – the contents of the dataset being exchanged. This TMW library will handle all header
encoding and decoding, retransmission and timeouts, as well as handling the interface to the 802.3 link
layer.
The programming interface is divided into five functional groups: Administrative Functions, Output
services, Input services, DataSet Query services, and Goose Control Block functions. These groups all
work off of a common information base, which is rooted at the IEC_Goose_Context record. The
IEC_Goose_Context record maintains lists of active GOOSE input and output streams, as well as a pointer
to the datalink (802.3) context. Pools of the dynamically allocated data structures (MMSd_Subscription
records) are created at startup and maintained by the TMW software. These records are used for status and
timers for both inputs and outputs.
TMW Library
802.3 Interface
This header file contains definitions used to set the operational parameters of the IEC GOOSE package.
USE_MMSD_IN_IEC_GOOSE
Default: On, Range: n/a, DefValue: Ignored
Include this if the IEC Goose library will be used with an MMS server, and make use of MMS server
GOOSE control blocks and Data Sets. The switch allows the library to automatically resolve the query
services (GetGsReference and GetGsDataOffset) against the MMS server dictionary. If the application will
not use an MMS server, remove the definition and replace the following function pointers in the IEC Goose
Context with pointers to custom routines:
getReferenceReqFcn;
getReferenceResFcn;
getElementNumReqFcn;
getElementNumResFcn;
The standard functions which use the MMS server dictionary can be used as templates for the custom
versions.
IEC_MAX_IDENT
Default: On, Range: 1-66, DefValue: 66
Defines the maximum length of a DataSet member in the IEC Goose implementation of the query services
(GetGsReference and GetGsDataOffset).
MAX_IEC_GOOSE_PROFILES
Default: On, Range: 1-32767, DefValue: 20
Defines the maximum number of outgoing GOOSE Profiles that may be defined. Each Profile defines the
parameters for a single IEC GOOSE output stream retransmission sequence.
IEC_GOOSE_IDENT_SIZE
Default: On, Range: 1-128, DefValue: 65
Defines the maximum length of the gcRef, appId, and dataSetRef strings used in the IEC Goose library.
MAX_IEC_GOOSE_ENTRIES
Default: On, Range: 1-32767, DefValue: 40
Defines the total number of input and output IEC Goose streams that can be active at a given time (pool
size). This can be overridden if the application performs its own pool initialization.
IEC_HOLD_TIME_FUDGE
Default: On, Range: 1-65535, DefValue: 0
Defines the amount in milliseconds to add to IEC Goose retransmission times before timing out. This may
be required on some platforms, particularly of there is some polling loop involved in the IEC Goose
processing.
IEC_GOOSE_MAX_DATA_LEN
Default: On, Range: 1-1517, DefValue: 1517
Defines the maximum number of octets which may be contained in a GOOSE message. This parameter
defines how much storage to reserve for saving the goose messages for delivery/retransmission.
There are two primary data structures used within the common interface: TAM_DL_Context and
TAM_DL_Definition. The context data structure maintains the global information about a specific data
link. Note that each Goose context is associated with one data link context. The library, however, supports
multiple Goose contexts and hence multiple data link contexts operating simultaneously. The
TAM_DL_Context data structure is defined as:
The data link context is returned by the open service function, and is passed to all other service requests
and service callback indication functions. If a data link implementation on a specific platform requires
additional data to be maintained, it can be added to the end of the data link context. In our data link
implementations, we create a platform-specific data link context with the common TAM_DL_Context data
as the header. For example:
This allows all library routines to access the standard link context information in a standard position within
the data link context. The TAM_DL_Context pointers passed to all service and indication callback routines
can then be cast to the CUSTOM_DL_Context type to access the platform-specific data.
The TAM_DL_Definition structure should be initialized with pointers to the platform specific routines
before linking into the TAM_DL_Context structure. The functions required to support Goose are:
The indication callback function provided in the call must be invoked when a packet is received which
meets the bind criteria (nBindType, pMulticastAddress, and nLsap). The indication data pointer will be
passed to the indication callback function to allow addressability of application data of the data link user.
The action and calling sequence of the indication function depends on the nBindType. The Goose protocol
is time critical, so that packets which match the Goose bind criteria are simply passed as raw buffers to the
indication callback. OSI binds (not needed for Goose implementations) are resolved by inserting the
packet into an input queue, then invoking the indication callback, which calls the TAM_DL_Receive
function to remove the next packet from the input queue.
Note that the code which maintains the list of binds is quite generic, so that it can generally be taken
directly from the Linux implementation of this routine provided with the library.
The Goose Administrative functions establish and manage the Goose context. Note that there can be more
than one Goose context, each associated with a different Ethernet adapter. The Administrative functions
include IEC_Goose_Initialize, IEC_Goose_Service, IEC_Goose_Service_Short and IEC_Goose_Close.
Application
Initialize Service
Tamarack Library
The IEC_Goose_Initialize function sets up the context record and allocates the pools of input and output
subscription records. This function also opens the 802.3 interface, and establishes the datalink context to
be used for all input and output messages. Note that the adapter name within the context must be initialized
before calling this routine.
The IEC_Goose_Service function invokes the datalink service routine, and then scans the list of active
input list for timeouts (Goose hold times exceeded) and the active output list for scheduled retransmissions.
This function must be called periodically by the application software. The time interval between calls to
IEC_Goose_Service will determine the time ‘jitter’ on retransmissions and the latency to detecting timeouts
on received IEC Goose messages.
If the target application is multi-threaded, the datalink service routine is typically being driven from the
primary thread components (TAM_TASK library). In this case, the IEC_Goose_Service_Short is used
instead.
The IEC_Goose_Close routine is used to provide a graceful close of the entire Goose context. This ceases
all Goose operations for the given context.
Tamarack Library
The function adds the output stream to the list of active outputs, sends the initial IEC goose messages, and
initializes the timer for retransmission.
The IEC_Goose_CreateOut function is the same as IEC_Goose_Create but adds support for the ndsCom
and test parameters.
The IEC_Goose_Delete function is called with the user-specified handle (as passed to the
IEC_Goose_Create function) to stop a goose output stream and free all associated storage.
The IEC_Goose_Publish function is called with the user-specified handle (as passed to the
IEC_Goose_Create function) and a buffer containing the encoded dataset values to transmit. The
IEC_Goose_Publish function transmits the updated values, stores them for later retransmissions, and
restarts the retransmission sequence for the output stream.
The initial retransmissions following a data change (and following the initial Goose enable or startup)
are used to enhance the reliability of the protocol. A typical connection-oriented communications protocol
involves the sender waiting for an acknowledgement from the receiver. If the acknowledgement doesn’t
come soon enough, the sender retransmits the message and again waits for an acknowledgement. This
introduces significant time loss due to errors, and is also complicated when using a multicast mechanism
such as Goose. The Goose protocol is based on the idea of assuming the acknowledgements did not come,
and so issues the retransmission in all cases. As time passes, however, the retransmissions become less
useful – either the receivers have all received the data, or they are likely too late to act on the change
anyway. This approach then is best with short retransmission intervals immediately after each data change,
with intervals increasing up to some maximum interval. The maximum interval is the maximum time that a
new subscriber will have to wait for its initial dataset values, and also defines the maximum interval that a
loss of connectivity will be detected.
The profile scheme allows for a specific set of intervals to be specified. Each interval (specified in
milliseconds) is used in sequence. When the last specified interval has been used, the parameters of the
arithmetic scheme are then used for subsequent intervals (including the maximum retransmission interval).
The data structure IEC_Goose_Strategy includes a strategyType (values are IEC_Goose_Arithmetic and
IEC_Goose_Profile), as well as the parameters for each strategy type. If the strategyType is
IEC_Goose_Arithmetic, then only that strategy is used and the profile parameters are ignored. If the
strategyType is IEC_Goose_Profile, then the profile values are used first, followed by the arithmetic
algorithm. A pointer to an IEC_Goose_Strategy must be passed to IEC_Goose_Create when initiating a
Goose output stream.
Application
Tamarack Library
The IEC_Goose_Subscribe function is used to establish a goose input stream. The application code calls
the function with
The subscribe function sets up the multicast address binding in the data link interface and adds the input
stream to the list of active inputs. Upon receipt of the first goose message for the input stream (and
whenever a message with a new StNum parameter is received) the indication callback function is invoked
with the decoded message header and a pointer and length of the dataset values to be decoded in the
message. Upon timeout (expiration of the most recent holdTime interval without receipt of a new
message), the indication callback function will be invoked with the most recently decoded message header
and with a NULL data pointer.
The IEC_Goose_Unsubscribe function deletes the input stream, cancels the datalink binding, and frees all
memory associated with the input stream.
IEC_Goose_SetInitialWait function is used to set a maximum time (ms) to wait for the first message in a
subscribed Goose stream. The stream is identified by the handle as supplied to the IEC_Goose_Subscribe
function. If an input Goose message is not received before the timer expires, the callback function assigned
by IEC_Goose_Subscribe will be called with a timeout indication. Once the first Goose message is
received from a Goose input stream, timeouts will be signaled based on the hold times specified in each
Goose message.
IEC_Goose_Context record,
a user-supplied (void *) handle indicating which peer goose input stream is to be used for the inquiry,
an arbitrary unsigned long integer identification number which will be used to resolve the response,
an array of integer indexes of dataset members to be resolved,
the number of integer indexes in the array,
A GetReferenceRequest message is encoded and sent to the datalink (directed) source address of the last
goose message received for the indicated stream. Upon receipt of a matching response message, the library
will invoke the callback indication function with the user-supplied parameter, both of which are maintained
in the IEC_Goose_Context (getReferenceResFcn, and getReferenceResParam). The callback function is
invoked with the unsigned long identification number (echoed from the request) Goose control block name,
the dataset name and configuration revision number, a pointer and length for the response data (ASN.1
encoding of a list of character strings) within the response message or an error code (if an error is received).
The data pointer and length can be inserted into an MMSd_descriptor, and the standard ASN.1 decode
functions (e.g. MMSd_fetchSTRING) can be used to retrieve the data. It is the responsibility of the
application code to manage timeouts and error recovery.
The IEC_Goose_GetElementNumber function operates in the same way, except that the call includes an
array of character strings (NULL terminated), and the pointer passed to the callback indication function
will point to a list of integer member indices. The callback function and data pointer in the
IEC_Goose_Context for IEC_GooseElementNumber are getElementNumResFcn and
getElementNumResFcn.
Application
Subscriber Role Publisher Role
Tamarack Library
Note that to use this software, you must still set up the IEC Goose context and configure the interface just
as before. This software rides on top of the rest of the Goose package. All of the routines described here
are implemented in IECGOOSE\IGOCB.C, with prototypes and constants defined in
IECGOOSE/IECGOOSE.H.
The assumption within the IEC 61850 specification is that each device supporting both Goose and MMS
will implement a Goose Control Block (GoCB), defined to be in functional component GO, under LLN0.
The IEC 61850 naming convention for GoCBs is unclear within the standard. For the example
applications, we have chosen to follow the same conventions for GoCBs as is used for Report Control
Blocks: rcbXX, where XX is derived from the name of the Datat Set associated with the control block at
boot time. Thus the name for the default Goose Control Object within LLN0 (which references is
LLN0$ST) is goST. When mapped to the MMS Named Variables, this becomes LLN0$GO$goST. When
generating MMS dictionaries, you can name them anything you wish – the software is driven by the class
of the object, not its name.
There is some question as to how many Goose Control Blocks can exist within a device. This software
allows for any number of Goose Control Blocks, each representing a distinct Goose Output stream.
The support for Goose Control Blocks includes the code for the read/write handlers of the attributes within
a Goose Control Block. The following primitive object classes have been defined within the file
CLASSLIB\GOCB.MMS:
MMSd_GoEna
MMSd_GoID
MMSd_GoDatSet
MMSd_GoConfRev
MMSd_GoNdsCo
MMSd_GoDstAddr
MMSd_GoPriority
MMSd_GoVid
MMSd_GoAppid
These correspond to the attributes of a GoCB. When the GoCB attribute GoEna is written with a value that
causes it to make the transition from FALSE to TRUE, the write handler automatically starts up a new
Goose output stream. When it makes the transition from TRUE to FALSE, the corresponding Goose
output stream is stopped and freed. All of these handlers assume that they are mapped to an instance of the
internal TMW control block structure for maintaining the status of the output stream.
Note that you may not want to grant write access to the Goose Control Blocks, requiring a re-configuration
to change the Goose parameters. This can be accomplished by setting the primitive classes to
READONLY, which clears the MMSd_OPT_read option bit for the class.
//To stop all Goose transmissions before shutting down the Goose API:
#if defined(USE_MMSD_IN_IEC_GOOSE)
MMSd_GooseControlStopAll( &mms_context );
#endif
The buffer used in each of these calls should be the maximum size needed to encode the longest DataSet
used by any Goose Control Block. The maximum allowable size for the data portion of a Goose message is
defined by MAX_IEC_GOOSE_DATASET_BUFFER.
All of the prototypes and constant definitions used are defined in IECGOOSE\IECGOOSE.H. The routines
used are:
This routine goes through the list of Goose Control Blocks defined in the model and links them with the
IEC Goose context. This is required to allow them access to the Goose interface.
This routine goes through the list of Goose Control Blocks defined in the model and, if enabled with a valid
datSet configured, starts the Goose output stream for than control block.
This routine goes through the list of Goose Control Blocks defined in the model and stops all active Goose
output streams.
The triggering of the Goose send messages can be done at any one of several levels, based on your
application requirements. The options for implementing the Goose triggers are discussed in the next
section.
Scans all Goose Control Blocks within the entire model, executing each evaluation handler and transmitting
each goose that had at least one dataset member changed.
Encodes the data set referenced by the Goose Control Block identified by the handle into the buffer.
Returns the number of bytes encoded, or zero to signal failue. The encoded data resides in the buffer at
offset ‘dataOffset’, for length ‘dataLength’. The handle of a Goose Control Block can be retrieved using
MMSd_GooseControlGetHandle.
Transmits the data within the buffer as the dataset for the Goose Control Block referenced by handle. The
handle of a Goose Control Block can be retrieved using MMSd_GooseControlGetHandle.
Retrieves the handle of the Goose Control Block named GcbName. Note that the name must be of the form
<domainName>/<controlBlockname>, where <domainName> is empty for VMD-specific control blocks.
The <controlBlockName> is the name of the MMS variable representing the control block (including
functional component name).
Returns a pointer to the strategy definition for the Goose output stream. The pointer should be cast as
(IEC_Goose_Strategy *) to get access to the values. The strategy can be modified by your software, but it
is safest to disable and re-enable the goose using MMSd_GooseControlStop and
MMSd_GooseControlStart.
Retrieves the value of the GoEna (Goose Enable) attribute of the Goose Control Block referenced by
handle. The returned value is zero if the block is currently disabled, non-zero oherwise.
Sets the value of the GoEna (Goose Enable) attribute of the Goose Control Block referenced by handle.
This will have the side-effect of starting up the Goose output stream, assuming all of the parameters (like
DatSet) have been properly initialized. This should NOT be called until after the call is made to
MMSd_GooseControlSetAllContexts.
Retrieves the name of the dataset configured for the Goose Control Block referenced by handle. The
dataset name is of the form <domainName>/<dataset>, and represents the name of the MMS Named
Variable List.
Sets the dataset configured for the Goose Control Block referenced by handle. The dataset name is of the
form <domainName>/<dataset>, and represents the name of the MMS Named Variable List.
Retrieves the LAN parameters (MAC Address and VLAN parameters) configured for the Goose Control
Block referenced by handle.
Sets the LAN parameters (MAC Address and VLAN parameters) configured for the Goose Control Block
referenced by handle.
The following data structures are used as part of the interface to the IEC Goose library.
typedef struct {
IEC_GooseType strategyType;
IEC_GooseAriPars ari;
IEC_GooseProPars pro;
} IEC_Goose_Strategy;
Publisher:
int IEC_Goose_SetTestMode( IEC_Goose_Context *cntxt,
void *handle,
unsigned char testMode );
int IEC_Goose_GetTestMode( IEC_Goose_Context *cntxt,
void *handle,
unsigned char *testMode );
start_goose()
stop_goose()
service_goose()
/* Standard includes */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
IEC_Goose_Context iec_goose_cntxt;
/* -------------------------------------------------------------- */
/* Main routine - initializes and enters service loop. If */
/* keyboard is input ready, it retrieves the characters. If a */
/* complete line has been entered, it passes it to the GOOSE test */
/* package as a command. */
/* -------------------------------------------------------------- */
int main(int argc, char **argv)
{
unsigned int VLAN_appID = 0;
TAM_Mac_Address SubscribeMacAddress =
{ 6, { 0x01, 0x0c, 0xcd, 0x01, 0x00, 0x01 } };
MMSd_start_clock();
argc--;
argv++;
while (argc > 0)
{
char *arg = *argv;
argv++;
argc--;
if (*arg == '-')
{
arg++;
switch (*arg)
{
case 'l':
arg++;
if (strlen(arg))
strcpy( iec_goose_cntxt.adapter_name, arg );
break;
default:
if (iec_goose_cntxt.adapter_name[0] == 0)
{
printf("Adapter must be specified (-l<adapter name>)\n");
return( 1 );
}
IEC_Goose_Initialize( &iec_goose_cntxt );
if ( !IEC_Goose_Subscribe( &iec_goose_cntxt,
"", /* goID
*/
"E1Rly1/LLN0$GO$gcSTa,
&SubscribeMacAddress,
VLAN_appID,
(void *) MyGooseHandle,
My_Goose_Indication,
(void *) &MyCallBackData ) )
{
printf("Goose subscription failed!\n" );
return( 1 );
}
while (TRUE)
{
/* This is OFTEN done in a different thread */
IEC_Goose_Service( &iec_goose_cntxt );
}
MMSd_stop_clock();
return( 0 );
}
The IEC 61850 Substation Configuration Language is designed to include the configuration of all 61850
communications across the substation. This includes the assignment of Goose multicast addresses to Goose
Control Blocks.
The Communication section of an SCL file contains a set of <SubNetwork> definition elements. Each
<SubNetwork> element contains a set of <ConnectedAP> elements, representing the access points
associated with the subnetwork. Each <ConnectedAP> element contains and IED name and possibly an
<Address> , which corresponds to a server address of the IED on that subnetwork. The <ConnectedAP>
element may also contain a set of <GSE> and <SMV> elements, each of which must contain ldInst and
cbName attributes, and may contain an <Address> element. The cbName and ldInst attributes uniquely
identify a Goose control block within an IED server, and the <Address> within the <GSE> defines the
configured MAC address to which the Goose stream is published.