blob: 45981617ee4e8e99f76db17db888424f62adff64 [file] [log] [blame]
Mahir Gunyelb24b9d02021-05-13 08:58:16 -07001/*
2 * Copyright 2020-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package events
17
18import (
19 "fmt"
20 "strconv"
21
khenaidoo26721882021-08-11 17:42:52 -040022 "github.com/opencord/voltha-protos/v5/go/common"
23 "github.com/opencord/voltha-protos/v5/go/voltha"
Mahir Gunyelb24b9d02021-05-13 08:58:16 -070024)
25
26type ContextType string
27
28const (
29 // ContextAdminState is for the admin state of the Device in the context of the event
30 ContextAdminState ContextType = "admin-state"
31 // ContextConnectState is for the connect state of the Device in the context of the event
32 ContextConnectState ContextType = "connect-state"
33 // ContextOperState is for the operational state of the Device in the context of the event
34 ContextOperState ContextType = "oper-state"
35 // ContextPrevdminState is for the previous admin state of the Device in the context of the event
36 ContextPrevAdminState ContextType = "prev-admin-state"
37 // ContextPrevConnectState is for the previous connect state of the Device in the context of the event
38 ContextPrevConnectState ContextType = "prev-connect-state"
39 // ContextPrevOperState is for the previous operational state of the Device in the context of the event
40 ContextPrevOperState ContextType = "prev-oper-state"
41 // ContextDeviceID is for the previous operational state of the Device in the context of the event
42 ContextDeviceID ContextType = "id"
43 // ContextParentID is for the parent id in the context of the event
44 ContextParentID ContextType = "parent-id"
45 // ContextSerialNumber is for the serial number of the Device in the context of the event
46 ContextSerialNumber ContextType = "serial-number"
47 // ContextIsRoot is for the root flag of Device in the context of the event
48 ContextIsRoot ContextType = "is-root"
49 // ContextParentPort is for the parent interface id of child in the context of the event
50 ContextParentPort ContextType = "parent-port"
51)
52
53type EventName string
54
55const (
56 DeviceStateChangeEvent EventName = "DEVICE_STATE_CHANGE"
57)
58
59type EventAction string
60
61const (
62 Raise EventAction = "RAISE_EVENT"
63 Clear EventAction = "CLEAR_EVENT"
64)
65
66//CreateDeviceStateChangeEvent forms and returns a new DeviceStateChange Event
67func CreateDeviceStateChangeEvent(serialNumber string, deviceID string, parentID string,
khenaidoo26721882021-08-11 17:42:52 -040068 prevOperStatus common.OperStatus_Types, prevConnStatus common.ConnectStatus_Types, prevAdminStatus common.AdminState_Types,
69 operStatus common.OperStatus_Types, connStatus common.ConnectStatus_Types, adminStatus common.AdminState_Types,
Mahir Gunyelb24b9d02021-05-13 08:58:16 -070070 parentPort uint32, isRoot bool) *voltha.DeviceEvent {
71
72 context := make(map[string]string)
73 /* Populating event context */
74 context[string(ContextSerialNumber)] = serialNumber
75 context[string(ContextDeviceID)] = deviceID
76 context[string(ContextParentID)] = parentID
77 context[string(ContextPrevOperState)] = prevOperStatus.String()
78 context[string(ContextPrevConnectState)] = prevConnStatus.String()
79 context[string(ContextPrevAdminState)] = prevAdminStatus.String()
80 context[string(ContextOperState)] = operStatus.String()
81 context[string(ContextConnectState)] = connStatus.String()
82 context[string(ContextAdminState)] = adminStatus.String()
83 context[string(ContextIsRoot)] = strconv.FormatBool(isRoot)
84 context[string(ContextParentPort)] = strconv.FormatUint(uint64(parentPort), 10)
85
86 return &voltha.DeviceEvent{
87 Context: context,
88 ResourceId: deviceID,
89 DeviceEventName: fmt.Sprintf("%s_%s", string(DeviceStateChangeEvent), string(Raise)),
90 }
91}