blob: fe3a01793f4ed70c3036d34260f0a304d5782dfb [file] [log] [blame]
Gamze Abakacb0e6772021-06-10 08:32:12 +00001/*
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
22 "github.com/opencord/voltha-protos/v4/go/voltha"
23)
24
25type ContextType string
26
27const (
28 // ContextAdminState is for the admin state of the Device in the context of the event
29 ContextAdminState ContextType = "admin-state"
30 // ContextConnectState is for the connect state of the Device in the context of the event
31 ContextConnectState ContextType = "connect-state"
32 // ContextOperState is for the operational state of the Device in the context of the event
33 ContextOperState ContextType = "oper-state"
34 // ContextPrevdminState is for the previous admin state of the Device in the context of the event
35 ContextPrevAdminState ContextType = "prev-admin-state"
36 // ContextPrevConnectState is for the previous connect state of the Device in the context of the event
37 ContextPrevConnectState ContextType = "prev-connect-state"
38 // ContextPrevOperState is for the previous operational state of the Device in the context of the event
39 ContextPrevOperState ContextType = "prev-oper-state"
40 // ContextDeviceID is for the previous operational state of the Device in the context of the event
41 ContextDeviceID ContextType = "id"
42 // ContextParentID is for the parent id in the context of the event
43 ContextParentID ContextType = "parent-id"
44 // ContextSerialNumber is for the serial number of the Device in the context of the event
45 ContextSerialNumber ContextType = "serial-number"
46 // ContextIsRoot is for the root flag of Device in the context of the event
47 ContextIsRoot ContextType = "is-root"
48 // ContextParentPort is for the parent interface id of child in the context of the event
49 ContextParentPort ContextType = "parent-port"
50)
51
52type EventName string
53
54const (
55 DeviceStateChangeEvent EventName = "DEVICE_STATE_CHANGE"
56)
57
58type EventAction string
59
60const (
61 Raise EventAction = "RAISE_EVENT"
62 Clear EventAction = "CLEAR_EVENT"
63)
64
65//CreateDeviceStateChangeEvent forms and returns a new DeviceStateChange Event
66func CreateDeviceStateChangeEvent(serialNumber string, deviceID string, parentID string,
67 prevOperStatus voltha.OperStatus_Types, prevConnStatus voltha.ConnectStatus_Types, prevAdminStatus voltha.AdminState_Types,
68 operStatus voltha.OperStatus_Types, connStatus voltha.ConnectStatus_Types, adminStatus voltha.AdminState_Types,
69 parentPort uint32, isRoot bool) *voltha.DeviceEvent {
70
71 context := make(map[string]string)
72 /* Populating event context */
73 context[string(ContextSerialNumber)] = serialNumber
74 context[string(ContextDeviceID)] = deviceID
75 context[string(ContextParentID)] = parentID
76 context[string(ContextPrevOperState)] = prevOperStatus.String()
77 context[string(ContextPrevConnectState)] = prevConnStatus.String()
78 context[string(ContextPrevAdminState)] = prevAdminStatus.String()
79 context[string(ContextOperState)] = operStatus.String()
80 context[string(ContextConnectState)] = connStatus.String()
81 context[string(ContextAdminState)] = adminStatus.String()
82 context[string(ContextIsRoot)] = strconv.FormatBool(isRoot)
83 context[string(ContextParentPort)] = strconv.FormatUint(uint64(parentPort), 10)
84
85 return &voltha.DeviceEvent{
86 Context: context,
87 ResourceId: deviceID,
88 DeviceEventName: fmt.Sprintf("%s_%s", string(DeviceStateChangeEvent), string(Raise)),
89 }
90}