1
\chapter{The resource manager}\label{chap:rm}
2
\index{resource manager}
3
\begin{quote}
4
  Seek and ye shall find.\\
5
  -- Luke 11:9
6
\end{quote}
7
8
\section{Introduction}
9
The resource manager is a special kind of the SN ({\em service
10
  node})\index{service node} that keeps track of the NoTA-services in a given
11
NoTA system. It can be compared to Domain Name Servers\index{Domain Name
12
  Server} (DNS) on the internet. You can find the official specification
13
(WSDL) for the resource manager in appendix~\ref{chap:rm-sis}.
14
15
Note, in previous chapters, we've over talked about SNs or service nodes. In
16
this chapter we'll mostly mention \emph{serivices}\index{service}, which is a
17
bit more abstract - an SN is a concrete, running implementation, which offers
18
a certain service.
19
20
\section{Ontology and service description}
21
Many of the RM functions refer to the \emph{ontology} and \emph{service
22
  description} of a certain service.
23
24
\emph{Ontology}\index{ontology} is a philosophical concept referring to the
25
nature of reality. In information science, the word is use slightly
26
differently -- it denotes a \emph{domain} or \emph{namespace} in which a set
27
of concepts live. This is also what it means in NoTA, with the 'concepts'
28
being our services.
29
30
A \emph{service description} is a name describing a service. Within an
31
ontology, usually there is some rule or convention for what the service
32
descriptions look like. The resource manager lives in the
33
\emph{NoTA}-ontology. It's service description is shown in
34
table~\ref{table:rm-service-desc}.
35
36
\begin{table}[h]\label{table:rm-service-desc}
37
  \caption{Resource Manager Service Description}
38
  \begin{tabular} {| l| l | l | l |}
39
    \hline
40
    {\bf \#} & {\bf element} & {\bf
41
      value} &  {\bf notes} \\ 
42
    \hline
43
    \hline
44
    1&{\tt SRV\_AREA } &  {\tt SYSTEM} & \\
45
    2&{\tt SRV\_NAME } &  {\tt ResourceMng} & \\
46
    3&{\tt SRV\_MAJOR } &  {\tt 01} & \\
47
    4&{\tt SRV\_MINOR } &  {\tt 00} & \\
48
    5&{\tt VERSION }    & \emph{xxx}  & three digit source code version\\
49
    \hline
50
  \end{tabular}
51
\end{table}
52
53
Note that the ontology for your other services (SNs) can look quite different
54
-- the ontology defines the fields etc.
55
56
Implementation note: the reference implementation requires both ontology and
57
service description to be valid C-strings - ie., not contain embedded
58
\texttt{\\0}-characters. You can try of course, but don't say we did not warn
59
you.
60
61
\section{Service definition}
62
As mentioned, the Resource Manager is 'just another' Service Node - and as
63
things go, it has its service definition file. 
64
65
66
As we have seen before, the XML service definitions are a bit verbose. So once
67
more, we'll use our little shorthand notation.
68
69
\subsection{Registration and de-registration}
70
If you want to register your NoTA-service (SN) with the resource manager,
71
you'll need to send the \texttt{Register\_req}-message, with an \emph{ontology
72
name}, a \emph{service description} and a \emph{registration certificate}:
73
74
\begin{verbatim}
75
in:  [0x0001] Register_req (nota:bdata ontology_name,
76
                            nota:bdata service_desc,
77
                            nota:bdata cert_reg);
78
\end{verbatim}
79
80
After registration, the Resource Manager will respond with
81
\texttt{Register\_cnf}. In case there is no error (see the
82
\texttt{status}-parameter), it will give you the service-id, and two
83
certificates (that you should save carefully), for de-registration and
84
activation.
85
\begin{verbatim}
86
out: [0x0002] Register_cnf (tns:status_t status,
87
                           nota:sid_t sid,
88
                           nota:bdata cert_dereg,
89
                           nota:bdata cert_act);
90
\end{verbatim}                       
91
92
When you're closing down your service, you should to deregister it:
93
\begin{verbatim}
94
in: [0x0003] Deregister_req (nota:sid_t  sid,
95
                             nota:bdata  certificate);
96
97
out: [0x0004] Deregister_cnf (tns:status_t  status);
98
\end{verbatim}
99
100
\subsection{Challenge/response}
101
The resource manager also uses a simple one-way challenge-response mechanism;
102
as you can see from the \texttt{\_ind}-suffix, \texttt{Challenge\_ind} message
103
arrive unsollicited: your RM-using service might receive it any time, and
104
should then give the appropriate response.
105
106
\begin{verbatim}
107
out: [0x0010] Challenge_ind  (nota:bdata  challenge);
108
109
in:  [0x0011] Challenge_rsp  (nota:bdata  response);
110
\end{verbatim}
111
112
The exact nature of the algorithm to use for challenge/response is
113
implementation-defined. \textbf{Note}: currently, challenge/response is not
114
implemented in the reference implementation.
115
116
\subsection{Service resolution and discovery}
117
The main purpose of the resource manager is to provide for service resolution
118
and discovery. For \texttt{ResolveService\_req}, you need to know the
119
\emph{exact} ontology name and service description.
120
121
\begin{verbatim}
122
in:  [0x0020] ResolveService_req  (nota:bdata  ontology_name,
123
                                   nota:bdata  service_desc);
124
125
out: [0x0021] ResolveService_cnf  (tns:status_t  status,
126
                                   nota:sid_t    sid);
127
\end{verbatim} 
128
When the requested service is found (or not), you will receive
129
\texttt{ResolveService\_cnf} with either the SID (status = \texttt{S\_OK}, or
130
some error code (\texttt{E\_SERVICE\_NOT\_FOUND},
131
\texttt{E\_GENERAL\_ERROR}). If you get one of the error codes, you should
132
ignore the \texttt{sid} parameter.
133
134
Instead of asking for specific services, you can also request the full list of
135
services that have been registered with the resource manager, using th
136
\texttt{ListOfServices}-messages. You \textbf{do} need to know the ontology
137
name though.
138
139
\begin{verbatim}
140
in:  [0x0030] ListOfServices_req  (nota:bdata ontology_name);
141
142
out: [0x0031] ListOfServices_cnf  (tns:servicelist_t servicelist);
143
\end{verbatim}
144
145
146
\subsection{Events}
147
The Resource Manager also has an events-interface; that is, it can notify of
148
certain things happening, such as new services becoming available or having
149
left.
150
151
To get notifications about a new service registration, use \texttt{
152
  EVENT\_SERVICE\_REGISTERED}; for notifications about services
153
de-registering, use (not surpringly) \texttt{EVENT\_SERVICE\_DEREGISTERED}.
154
155
When registering for events succeeds, the RM will return you
156
(\texttt{NewEvent\_cnf} an \texttt{event\_id}, which is a number that
157
identifies this particular event-notification. When the RM notifies you about
158
something (with \texttt{NewEvent\_ind}, it will include this number. Note
159
these \texttt{NewEvent\_ind} messages could come at any time.
160
161
\begin{verbatim}
162
/* for some reason, the RM defines the codes in octal notation;
163
   0100 ==> 0x40; */
164
in:  [0100] NewEvent_req    (tns:event_t event
165
                             nota:bdata  ontology_name,
166
                             nota:bdata  service_desc);
167
168
out: [0101] NewEvent_cnf    (nota:uns32   event_id,
169
                             tns:status_t status); 
170
171
out: [0102] NewEvent_ind    (nota:uns32   event_id,
172
                             tns:event_t  event); /* event_t param?! */
173
\end{verbatim}
174
175
With the \texttt{DeleteEvent}-messages, you can tell the Resource Manager that
176
you are no longer interested in certain notifications. 
177
\begin{verbatim}
178
in:  [0103] DeleteEvent_req  (nota:uns32  event_id);
179
180
out: [0104] DeleteEvent_cnf  (tns:status_t  status); 
181
\end{verbatim}
182
183
\section{How to find the Resource Manager}
184
As we have seen, you can use the RM to find other service nodes. But how can
185
we find the resource manager itself? This chicken-and-egg problem is solved by
186
giving the resource manager a well-know service-id and port.
187
188
\textbf{Important:} The resource manager can be found on SID \textbf{0} and
189
port \textbf{0}.
190
191
From chapter~\ref{chap:h-in} you may remember what a NoTA-address looks like:
192
\begin{lstlisting}[language=C,numbers=none]
193
struct nota_addr {
194
  sid_t        sid;       /* service identifier */
195
  unsigned int port;      /* port of the sid */
196
  vdid_t       device;    /* virtual device id */
197
};
198
typedef struct nota_addr nota_addr_t;
199
\end{lstlisting}
200
201
So, for the RM we can write\footnote{note that we will ignore the
202
  \texttt{device}-parameter for now}:
203
\begin{lstlisting}[language=C,numbers=none]
204
const nota_addr nota_addr_t NOTA_RM_ADDRESS = { 0, 0, 0 };
205
\end{lstlisting}
206
207
You should make sure that your own services do not conflict with the
208
RM-address.
209
210
Another important thing to remember is that one should communicate with the RM
211
using message sockets, i.e., \texttt{SOCK\_SEQPACKET}.
212
213
\section{Questions}
214
\begin{enumerate}
215
\item What's the purpose of the Resource Manager?
216
\item What's an ontology in the NoTA-context? And what's a service
217
  description?
218
\item How can we find from our application node the Resource Manager?
219
\item How can I find out about if some service is available, if I know it's
220
  ontology and service description?
221
\item How can I find out when the list of registered services changes?
222
\end{enumerate}