network_communication.tex 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. \chapter{Network communication}
  2. %Apart from the logical interface that is exposed, the physical interface should also be specified.
  3. %This interface determines how the provided services can be invoked, possibly over the network.
  4. %Since the Modelverse components are defined as seperate modules, with a standardized API, multiple back-ends can be created to couple them.
  5. %Depending on the used back-end, the physical interface will differ.
  6. %We will implement a simple back-end that makes the Modelverse state run as a service, exposed to the network.
  7. %This is done with the XML/HTTP back-end, described below.
  8. %
  9. %While XML/HTTP is not the most efficient protocol for this data exchange, it has the most wide portability and is not blocked by most firewalls.
  10. %It also shows that our approach works with even a minimal communication protocol.
  11. %In the future, it is possible to define new back-ends, which possibly uses low-latency and low-overhead communication protocols.
  12. %Using XML/HTTP can still be used as a fallback method if other protocols are not supported.
  13. \section{Motivation}
  14. \section{Modelverse State}
  15. \subsection{Interface}
  16. The XML/HTTPRequest back-end of the MvS will simply host an HTTP server, which responds to POST requests.
  17. The reply of the server is again encoded in the same format as the POST request.
  18. All requests should be send via POST, and contain the following two parameters:
  19. \begin{itemize}
  20. \item \textbf{op}: this indicates which operation to execute on the MvS.
  21. \item \textbf{params}: contains the parameters for the function, encoded in JSON format.
  22. While we require JSON encoding, the data can never be complex due to the simple signature of the supported operations.
  23. This parameter should always be a list of the parameters to pass.
  24. If there is only a single parameter, a list with a single element is still required.
  25. \end{itemize}
  26. The operations all use coding, to reduce the amount of data that needs to be transfered.
  27. Table~\ref{table:decoding} shows the mapping between the operation and the formalized function name.
  28. \begin{table}
  29. \center
  30. \begin{tabular}{l l}
  31. \textbf{Operation} & \textbf{Formal function} \\
  32. \hline
  33. \hline
  34. CN & create\_node \\
  35. CE & create\_edge \\
  36. CNV & create\_nodevalue \\
  37. CD & create\_dict \\
  38. \hline
  39. RV & read\_value \\
  40. RO & read\_outgoing \\
  41. RI & read\_incoming \\
  42. RE & read\_edge \\
  43. RD & read\_dict \\
  44. RDN & read\_dict\_node \\
  45. RDE & read\_dict\_edge \\
  46. RRD & read\_reverse\_dict \\
  47. RR & read\_root \\
  48. RDK & read\_dict\_keys \\
  49. \hline
  50. DE & delete\_edge \\
  51. DN & delete\_node \\
  52. \end{tabular}
  53. \caption{Mapping between operations and formalized function name}
  54. \label{table:decoding}
  55. \end{table}
  56. \begin{lstlisting}[label=listing:request_reply,caption=Example request and reply,frame=single]
  57. Request: op=RE&params=[1]
  58. Reply: data=[[2, 3], 100]
  59. \end{lstlisting}
  60. An example request, and corresponding reply, is shown in Listing~\ref{listing:request_reply}, where an edge with identifier 1 is read.
  61. The reply indicates that the request was succesful (statuscode 100), and the returnvalue indicates that edge 1 goes from element 2 to element 3.
  62. Note that the $\mathcal{G}$ parts of the request and reply, as were formalized previously, are not included.
  63. This is because the MvS itself is the instance of $\mathcal{G}$ being modified.
  64. Sockets are kept open until explicitly closed, so it is possible to reuse a single socket for every request.
  65. It is also possible to send a request before the previous request is handled of.
  66. In that case, the order of the replies will be the same as of the requests.
  67. \subsection{Statechart}
  68. \begin{figure}
  69. \center
  70. \includegraphics[width=0.7\textwidth]{images/mvs_server.pdf}
  71. \caption{Modelverse State server statechart}
  72. \label{fig:mvs_server_statechart}
  73. \end{figure}
  74. \section{Modelverse Kernel}
  75. \subsection{Interface}
  76. Communication with the Modelverse Kernel is very similar to the communication with the Modelverse State.
  77. The Modelverse accepts two different operations: \texttt{set\_input} and \texttt{get\_output}.
  78. Data is to be send as a POST request, and has to consist of the following fields:
  79. \begin{enumerate}
  80. \item \textbf{op}: the operation to perform. It can be either "set\_input" or "get\_output".
  81. Depending on the value of this entry, some additional elements need to be present in the request.
  82. \item \textbf{username}: the name of the user whose input or output queue is modified.
  83. Always present for both operations.
  84. \item \textbf{element\_type}: how to interpret the value parameter.
  85. It is either "R", to indicate that the value parameter is a reference, and therefore an element identifier.
  86. The other option is "V", to indicate that the value parameter is a JSON encoded value.
  87. Only present if the operation is set\_input.
  88. \item \textbf{value}: the actual parameter to the operation.
  89. Its interpretation is given by the element\_type operation.
  90. If it has to be interpreted as a value, it needs to be an instance of a primitive for the MvS.
  91. Only present if the operation is set\_input.
  92. \end{enumerate}
  93. For both requests, a reply will be returned containing an \textit{id} and \textit{value} entry.
  94. For the \texttt{set\_input}, the \textit{id} and \textit{value} are a status code and human-readable description.
  95. Generally, giving input should always succeed, resulting in \textit{id} 100 and \textit{value} \texttt{success}.
  96. For the \texttt{get\_output}, the \textit{id} will be the identifier of the node that is to be output.
  97. The \textit{value} is the value of the node with the provided identifier.
  98. Getting output is a blocking call, so the request will stay open until input is actually generated.
  99. As soon as the output is generated, it will be sent out.
  100. An example request and reply is shown in Listing~\ref{listing:reqrep_new_user} and~\ref{listing:reqrep_setR}, for set\_input, and Listing~\ref{listing:reqrep_output} and~\ref{listing:reqrep_output_fail}, for get\_output.
  101. \begin{lstlisting}[frame=single,caption=Example: create new user,label=listing:reqrep_new_user]
  102. Request: op=set_input&username=user_manager&element_type=V&value="user_1"
  103. Reply: id=100&value="success"
  104. \end{lstlisting}
  105. \begin{lstlisting}[frame=single,caption=Example: input element ID 15 for user,label=listing:reqrep_setR]
  106. Request: op=set_input&username=user_1&element_type=R&value=15
  107. Reply: id=100&value="success"
  108. \end{lstlisting}
  109. \begin{lstlisting}[frame=single,caption=Example: read output valuelabel=listing:reqrep_output]
  110. Request: op=get_output&username=user_1
  111. Reply: id=123&value="node_value"
  112. \end{lstlisting}
  113. \subsection{Statechart}
  114. \begin{figure}
  115. \center
  116. \includegraphics[width=1.3\textwidth,angle=90]{images/mvk_server.pdf}
  117. \caption{Modelverse Kernel server statechart}
  118. \label{fig:mvk_server_statechart}
  119. \end{figure}
  120. \section{Modelverse Interface}