summaryrefslogtreecommitdiff
path: root/priv/config/rvi_yocto.config
blob: c5dbb32503da40ba7194f96e01d83ae054d7f914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
%% -*- erlang -*-

%% Copyright (C) 2014,2015,2016 Jaguar Land Rover
%%
%% This program is licensed under the terms and conditions of the
%% Mozilla Public License, version 2.0.  The full text of the
%% Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
%%
%% Configuration file for RVI built and deployed with the
%% Yocto Project
%%
%% See ../CONFIGURE.md for a details on the configuration process
%% itself.
%%

%% Parameters for simpler modification
Env = fun(V, Def) ->
	      case os:getenv(V) of
		  false -> Def;
		  Str when is_integer(Def) -> list_to_integer(Str);
		  Str when is_atom(Def) -> list_to_atom(Str);
		  Str -> Str
	      end
      end.
IPPort = fun(IP, Port) ->
		 IP ++ ":" ++ integer_to_list(Port)
	 end.
MyPort = Env("RVI_PORT", 9000).
MyIP = Env("RVI_MYIP", "127.0.0.1").
MyNodeAddr = Env("RVI_MY_NODE_ADDR", IPPort(MyIP, MyPort)).
BackendIP = Env("RVI_BACKEND", "38.129.64.31").
BackendPort = Env("RVI_BACKEND_PORT", 8807).
LogLevel = Env("RVI_LOGLEVEL", notice).

[
 %% All erlang apps needed to fire up a node. Do not touch.
 {include_lib, "rvi_core/priv/config/rvi_common.config"},

 %%
 %% Custom environment settings
 %% for all apps running on the node.
 %%
 {env,
  [

   %% All RVI configuration is done here.
   %%
   %% Please note that the rvi_node.sh launch script
   %% can still override the port range and static nodes
   %% through its command line parameters.
   %%
   %% Value substitution:
   %% All string values under the rvi tuple tree are scanned
   %% for specific dokens during startup. If a token is
   %% found, it will be replaced with a value referenced by it.
   %% Tokens can one of the following:
   %%
   %% $rvi_file(FileName,Default) - File content
   %%   When an $rvi_file() token is encountered, the first line of
   %%   the referenced file is read. The line (without the newline)
   %%   replaces the token.
   %%
   %%   Example:
   %%     { node_service_prefix, "genivi.org/vin/$rvi_file(/etc/vin,default_vin)"},
   %%
   %%     will be substituted with the first line from the file
   %%     /etc/vin:
   %%
   %%     { node_service_prefix, "genivi.org/vin/2GKEG25HXP4093669"},
   %%
   %%     If /etc/vin cannot be opened, the value default_vin
   %%     will be used instead.
   %%
   %%
   %% $rvi_env(EnvironemtnName,Default) - Environment variable
   %%   When an $rvi_env() token is encountered, the value of
   %%   the Linux process environment variable (such as $HOME) is read
   %%   to replace the token.
   %%
   %%   Example:
   %%     { node_service_prefix, "genivi.org/vin/$rvi_env(VIN,default_vin)"},
   %%
   %%     will be substituted with the value of the $VIN environment
   %%     variable:
   %%
   %%     { node_service_prefix, "genivi.org/vin/2GKEG25HXP4093669"},
   %%
   %%     If VIN is not a defined environment variable, the value
   %%     default_vin will be used instead.
   %%
   %%
   %% $rvi_uuid(Default) - Unique machine identifier
   %%   When an $rvi_uuid() token is encountered, the UUID of the root
   %%   disk used by the system is read to replace the token.
   %%   The UUID of the root disk is retrieved by opening /proc/cmdline
   %%   and extracting the root=UUID=[DiskUUID] value.
   %%   This value is generated at system install time and is reasonably
   %%   world wide unique.
   %%
   %%   Example:
   %%     { node_service_prefix, "genivi.org/vin/$uuid(default_vin)"},
   %%
   %%     will be substituted with the value of the root disk UUID:
   %%
   %%     { node_service_prefix,
   %%       "genivi.org/vin/afc0a6d8-0264-4f8a-bb3e-51ff8655b51c"},
   %%
   %%     If the root UUID cannot be retrieved, the value default_vin
   %%     will be used instead.
   %%

   {rvi_core,
    [
     %% Specify the node address that data_link uses to listen to
     %% incoming traffic from other rvi nodes.
     %%
     %% This is the address that is announced to
     %% other rvi nodes during service discovery and should be
     %% forwarded through firewalls and port forwarding to to the port
     %% specified by the configuration entry rvi -> components ->
     %% data_link ->json_rpc_server (see below).
     %%
     %% If this node is sitting behind a firewall and cannot
     %% receive incomign connections on any address, its
     %% node_address should be set to "0.0.0.0:0" to inform
     %% the remote node that it should not attempt to
     %% connect back to self.
     { node_address, MyNodeAddr },

     %% Specify the prefix of all services that this rvi node is hosting.
     %%
     %% All local services regsitering with service edge will be prefixed with
     %% the string below when they are announced to remote rvi nodes
     %% that connect to this node (using the address specified
     %% by node_address above).
     %%
     %% If a locally connected service registers itself as
     %% "hvac/fan_speed", and the node_service_prefix is
     %% "genivi.org/vin/1234/", this node will announce the service
     %% "genivi.org/vin/1234/hvac/fan_speed" as being available
     %% to remotely connected rvi nodes.
     %%
     %% Two rvi nodes should never have the same node_service_prefix
     %% value unless all services add a system-wide unique name
     %% to it.
     %%
     { node_service_prefix, "$rvi_file(/etc/rvi/device_id,genivi.org/node/default_id)/"},

     %% Routing rules determine how to get a message targeting a specific
     %% service to its destination.
     %%
     %% Please note that if a remotely initiated (== client) data link is
     %% available and has announced that the targeted service is available,
     %% that data link will be used regardless of what it is.
     %%
     %% In other words, if you setup routing rules for how to reach out
     %% to a vehicle using SMS, and that vehicle happens to have a 3G
     %% connection up when the message is sent, the 3G connection will be used.
     %%
     %% We will add a blacklist feature in the future to optionally block
     %% such opportunistic routing in the future.
     %%
     { routing_rules,
       [
	%% Service name prefix that rules are specified for
	%% The service prefix with the longest match against the service targeted
	%% by the message will be used.
	%%
	%% Example: Targeted service = genivi.org/backend/sota/get_updates
	%%
	%% Prefix1: { "genivi.org/backend", [...]}
	%% Prefix2: { "genivi.org/backend/sota", [...]}
	%%
	%% Prefix2 will be used.
	%%
	%% This allows you, for example, to setup different servers
	%% for different types of services (SOTA, remote door unlock,
	%% HVAC etc).
	%%

	%% Make sure to have a default if you don't want your message
	%% to error out immediately. With a default the message will
	%% be queued until it times out, waiting for a remote node
	%% to connect and announce that it can handle the targeted service.
	{ "",
	  [
	   { proto_json_rpc, dlink_tcp_rpc}
	  ]
	},

	{ "genivi.org/backend/",
	  %% Which protocol and data link pair to use when transmitting the message
	  %% to the targeted service. If a pair reports a failure, the next pair is tried.
	  [
	   { proto_json_rpc, { dlink_tcp_rpc,
			                   % {"38.129.64.13", 8807}
			       [ { target, IPPort(BackendIP, BackendPort) } ]}}
	  ]
	},

	%% Used to communicate with vehicles
	{ "genivi.org/vin/",
	  [
	   { proto_json_rpc, { dlink_tcp_rpc, [ broadcast, { interface, "wlan0" } ] } },
	   { proto_json_rpc, { server_3g, [ initiate_outbound ]} },

	   %% Protocols can have hinting as well.
	   %% In this case JSON-RPC should only be used if the
	   %% resulting message size can fit in an SMS (140 bytes).

	   { { proto_json_rpc, [ { max_msg_size, 140 } ] } , server_sms }
	  ]
	}
       ]
     },

     { components,
       [
	%% A note about JSON-RPC calls vs gen_server calls:
	%%
	%% All locally connected services communicate with Service Edge
	%% through JSON-RPC.
	%%
	%% Communication between the internal RVI components, however,
	%% can be either JSON-RPC or gen_server calls.
	%%
	%% JSON-RPC calls provide compatability with replacement components
	%% written in languages other than Erlang.
	%%
	%% Gen_server calls provide native erlang inter-process calls that
	%% are about 4x faster than JSON-RPC when transmitting large data volumes.
	%%
	%% If one or more of the components below are replaced with external
	%% components, use JSON-RPC by specifying IP address and port in
	%% json_rpc_address for all interfaced by the external components.
	%%
	%% If you are running an all-native erlang system, use gen_server calls
	%% by specifying gen_server for all components
	%%
	%% Please note that communication between two RVI nodes are
	%% not affected by this since dlink_tcp will use
	%% JSON-RPC to communicate ( using the address/port specified
	%% by proto_json_rpc).
	%%

	{rvi_common,
	 [
	  {rvi_log, gen_server,
	   [{json_rpc_address, MyPort+9}]
	  }
	 ]},
	%% Service_edge.
	%% The service_edge tuple is a top level configuration
	%% container for everything about service edge.
	%% In theory, we can support multiple different service edge
	%% components (written in different languages).
	%%
	%% However, until we've sorted out internal routing, we will
	%% only support the native service_edge_rpc component,
	%% accessed either as a gen_server or through JSON-RPC.
	%%
	{service_edge,
	  [
	    %% Service_edge_rpc component is used as a gen_server
	    { service_edge_rpc, gen_server,
	    [
	      %% JSON-RPC address will be translated to
	      %% an URL looking like this:
	      %% http://127.0.0.1:8801
	      %%
	      %% This URL is used both for communication with
	      %% locally connected services and for intra-component
	      %% communication in case the access method for
	      %% service_edge_rpc is specified as json_rpc.
	      { json_rpc_address, { MyIP, MyPort+1 } },  % {"127.0.0.1",8801}
	      { msgpack_rpc_address, { MyIP, MyPort + 21 } },

	      %% Websocket is used for websocket access, preferably
	      %% through the rvi.js package available for Javascript
	      %% apps in browsers and crosswalk who wants to interface
	      %% RVI.
	      { websocket, [ { port, MyPort+8}]}  % 9008
	    ]
	    }
	  ]
	},
	{ service_discovery,
	  [ { service_discovery_rpc, gen_server,
	      [
	       { json_rpc_address, { MyIP, MyPort+2 }} % {"127.0.0.1",9002}
	      ]
	    }
	  ]
	},
	{ schedule,
	  [ { schedule_rpc, gen_server,
	      [
	       { json_rpc_address, { MyIP, MyPort+3 }}  % {"127.0.0.1",9003}
	      ]
	    }
	  ]
	},
	{ authorize,
	  [ { authorize_rpc, gen_server,
	      [
		{ json_rpc_address, { MyIP, MyPort+4 } } % {"127.0.0.1",9004}
	      ]
	    }
	  ]
	},
	{ protocol,
	  [ { proto_json_rpc, gen_server,
	      [
		{ json_rpc_address, { MyIP, MyPort+5 } } % {"127.0.0.1",9005}
	      ]
	    }
	  ]
	},
	{ data_link,
	  [ { dlink_tcp_rpc, gen_server,
	      [
		{ json_rpc_address, { MyIP, MyPort+6 } },  % 9006
		%% data link TCP server specifies the port we should
		%% listen to for incoming connections
		%% from other rvi nodes.
		%% A specific NIC address can also be specified
		%% through the {ip, "192.168.0.1" } tuple.
		{ server_opts, [ { port, MyPort+7 }]},
		{ persistent_connections, [ IPPort(BackendIP, BackendPort) ]}
	      ]
	    },
	    { dlink_tls_rpc, gen_server,
	      [
	       { json_rpc_address, { MyIP, MyPort+11} },
	       { server_opts, [ {port, MyPort+10} ]}
	      ]
	    }
	  ]
	}
       ]
     }
    ]}
  ]}
].