The Open Protocol Notation Programming Guide 1 Document Version 1 (4/23/2018)



Download 1.37 Mb.
Page22/24
Date23.04.2018
Size1.37 Mb.
#46651
1   ...   16   17   18   19   20   21   22   23   24

Modalities


The following declarations address the representation in OPN of modality keywords (MUST, MAY, SHOULD), as defined in RFC 2119.

A Boolean method is used to represent a modality. The semantics for parsing, validation and simulation would be to allow both interpretations (DOES, DOES NOT) unless a value of true or false has been specified or inferred.

module Standard;

pattern Modality = enum 

{

MAY, 


SHOULD

}

bool Option(Modality modality, string identifier, Map perVendor);



bool Option(Modality modality, string identifier)

{

return Option(modality, identifier, {});



}

bool Option(Modality modality, Map perVendor)

{

return Option(modality, "", perVendor);



}

bool Option(Modality modality)

{

return Option(modality, "", {});



}

bool May(string identifier, Map perVendor)

{

return Option(Modality.MAY, identifier, perVendor);



}

bool May(string identifier)

{

return May(identifier, {});



}

bool May(Map perVendor)

{

return May("", perVendor);



}

bool May()

{

return May("", {});



}

bool Should(string identifier, Map perVendor)

{

return Option(Modality.SHOULD, identifier, perVendor);



}

bool Should(string identifier)

{

return Should(identifier, {});



}

bool Should(Map perVendor)

{

return Should("", perVendor);



}

bool Should()

{

return Should("", {});



}
    1. Error handling


Standard library provides a way to handle non-fatal validation and protocol errors. When processing a message, must-stop (fatal) errors can be already handled by specifying a where clause describing the conditions under which the message is not valid. To deal with non-fatal errors, standard library provides a set of functions that can be used in where clauses to just signal that some problem occurred during parsing, but that current message can continue processing. These Boolean functions always return true, so from a where clause perspective, no constraints are violated. When non-fatal error conditions are met, the compiler provides diagnosis information to the runtime so an error message can be displayed appropriately.
      1. ValidationCheck


The ValidationCheck function is provided to check whether non-fatal errors occurred.

module Standard;

bool ValidationCheck(bool expression, string ErrorDescription);

bool ValidationCheck(bool expression, any message context, string 

ErrorDescription);

bool ValidationCheck(bool condition, any message context, DiagnosisLevel 

level, string description);

When the message context is null, or when using the overloaded function, the error will be attached to the current message that is being processed, which is the lower layer message in the current runtime implementation. Otherwise, it will be attached to the message instance passed as a parameter. As mentioned before, ValidationCheck always returns true.

When DiagnosisLevel is not specified, Warning is the default.

Typical value validations could be the following:

A value is in a certain range or one of the specified values.

A value must contain certain characters.

A value has a certain length.

To give an example, note the following.

type SomeType

{

int Checksum where ValidationCheck(value > 1, null, "A value greater 



than 1 was expected");

// ...


}

If the value assigned to Checksum is not greater than 1, then a notification will be sent to runtime, attached to the message currently being processed.


      1. ErrorCodeIf


The ErrorCodeIf function represents a legitimate protocol error (such as SMB_ACCESS_DENIED for SMB protocol). These kinds of errors are usually encoded in a special type of message, or indicated by a message with special values.

bool ErrorCodeIf(Boolean expression, any message context, string 

ErrorDescription);

bool ErrorCodeIf(Boolean expression, string ErrorDescription);

Message context works in the same way as for the previous function, using null to represent that the error will be attached to the message currently being processed.

type SomeType

{

Code AckCode where ErrorCodeIf(value != S_OK, null, 


"The ACK code is not ok");

// ...


}

In this example, the runtime will be notified that the current message being processed represents a protocol error if the AckCode field is not equal to S_OK.


      1. ReportInsufficientData


The ReportInsufficientData function represents the case when additional data was expected, but it is known that this data will never arrive.

bool ReportInsufficientData(any message context, DiagnosisLevel level, 


string description);

Message context works in the same way as for the previous function, using null to represent that the error will be attached to the message currently being processed.


    1. Logging Messages


There is a special type of endpoint to which log messages can be dispatched. The runtime listens to this special logging endpoint and from the processing perspective can be considered as a regular endpoint.

pattern LogLevel = enum 

Error = 1, // All errors



Warning = 2, // All warnings, including errors.

Info = 4 // All informational, including warnings.

}

// Dispatch the logMessage to the logging endpoint with a specific logLevel.



void DispatchLog(LogLevel logLevel, string logMessage);

// Converts a value to string and logs the result.

void DispatchLog(LogLevel logLevel, any logValue);

 

// If there is no log level specified, by default log level = LEVEL_INFO.



void DispatchLog(string logMessage);

void DispatchLog(any logValue);

An example of use is the following.

process this accepts s:Segment{Kind = $DATA}

{

InsertSegment(s);



while (segmentsReady > 0)

{

var socket = endpoint Socket[Port, DestinAddress, DestinPort] 



                        over this.Node;

DispatchLog("Accepted data segment:");

String message ;

foreach (var byte in orderedSegments[0])

{

message += byte + "|";



dispatch socket accepts byte;

}

DispatchLog(message);



segments = orderedSegments.RemoveAt(0);

segmentsReady -= 1;

}  

}



    1. Download 1.37 Mb.

      Share with your friends:
1   ...   16   17   18   19   20   21   22   23   24




The database is protected by copyright ©ininet.org 2024
send message

    Main page