blob: e66e8e5ea62a9a8232f532bb8a992b05876a8d0b [file] [log] [blame]
kishoreefa3db52020-03-23 16:09:26 +05301/*
2 * Copyright 2018-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 org.opencord.kafka.integrations;
17
18import com.google.common.collect.Lists;
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
21import org.onlab.packet.VlanId;
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.Port;
24import org.onosproject.net.PortNumber;
25import org.onosproject.net.behaviour.BngProgrammable;
26import org.onosproject.net.pi.runtime.PiCounterCellData;
27import org.opencord.aaa.AaaMachineStatisticsEvent;
28import org.opencord.aaa.AaaStatistics;
29import org.opencord.aaa.AaaSupplicantMachineStats;
30import org.opencord.aaa.AuthenticationEvent;
31import org.opencord.aaa.AuthenticationStatisticsEvent;
32import org.opencord.aaa.RadiusOperationalStatusEvent;
33import org.opencord.bng.BngStatsEvent;
34import org.opencord.bng.BngStatsEventSubject;
35import org.opencord.bng.PppoeBngAttachment;
36import org.opencord.bng.PppoeEvent;
37import org.opencord.bng.PppoeEventSubject;
38import org.opencord.cordmcast.CordMcastStatistics;
39import org.opencord.cordmcast.CordMcastStatisticsEvent;
40import org.opencord.igmpproxy.IgmpStatistics;
41import org.opencord.igmpproxy.IgmpStatisticsEvent;
42import org.opencord.olt.AccessDeviceEvent;
43
44import java.util.HashMap;
45import java.util.List;
46import java.util.Map;
47
48import static org.opencord.kafka.integrations.MockDeviceService.DEVICE_ID_1;
49
50/**
51 * Base class for the KafkaIntegration tests classes.
52 */
53public class KafkaIntegrationTestBase {
54 protected static final PortNumber PORT_NUMBER = PortNumber.portNumber(1);
55 protected static final Port PORT = new MockDeviceService.MockPort();
56 protected static final VlanId CLIENT_C_TAG = VlanId.vlanId((short) 999);
57 protected static final VlanId CLIENT_S_TAG = VlanId.vlanId((short) 111);
58 protected static final Short TPID = 8;
59 protected static final VlanId C_TAG = VlanId.vlanId((short) 999);
60 protected static final VlanId S_TAG = VlanId.vlanId((short) 111);
61 protected static final String ONU_SERIAL = "TWSH00008084";
62 protected static final IpAddress LOCAL_IP = IpAddress.valueOf("127.0.0.1");
63 protected static final MacAddress OLT_MAC = MacAddress.valueOf("c6:b1:cd:40:dc:93");
64 protected static final Short SESSION_ID = 2;
65 protected static final ConnectPoint OLT_CONNECT_POINT = new ConnectPoint(MockDeviceService.DEVICE_ID_1,
66 PORT_NUMBER);
67
68 protected AuthenticationEvent getAuthenticationEvent() {
69 return new AuthenticationEvent(AuthenticationEvent.Type.APPROVED,
70 OLT_CONNECT_POINT);
71 }
72
73 protected AuthenticationStatisticsEvent getAuthenticationStatisticsEvent() {
74 return new AuthenticationStatisticsEvent(
75 AuthenticationStatisticsEvent.Type.STATS_UPDATE,
76 new AaaStatistics());
77 }
78
79 protected RadiusOperationalStatusEvent getRadiusOperationalStatusEvent() {
80 return new RadiusOperationalStatusEvent(
81 RadiusOperationalStatusEvent.Type.RADIUS_OPERATIONAL_STATUS,
82 "AUTHENTICATED");
83 }
84
85 protected AaaMachineStatisticsEvent getAaaMachineStatisticsEvent() {
86 return new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE,
87 new AaaSupplicantMachineStats());
88 }
89
90 protected AccessDeviceEvent getUniAdded() {
91 return new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED,
92 DEVICE_ID_1, PORT, CLIENT_S_TAG, CLIENT_C_TAG, (int) TPID);
93 }
94
95 protected AccessDeviceEvent getUniRemoved() {
96 return new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED,
97 DEVICE_ID_1, PORT, CLIENT_S_TAG, CLIENT_C_TAG, (int) TPID);
98 }
99
100 protected PppoeEvent getPppoeEvent() {
101 return new PppoeEvent(PppoeEvent.EventType.AUTH_SUCCESS,
102 new PppoeEventSubject(OLT_CONNECT_POINT,
103 LOCAL_IP, OLT_MAC,
104 ONU_SERIAL, SESSION_ID, S_TAG, C_TAG));
105 }
106
107 protected BngStatsEvent getBngStatsEvent() {
108 PppoeBngAttachment pppoeBngAttachment = (PppoeBngAttachment) PppoeBngAttachment.builder()
109 .withPppoeSessionId(SESSION_ID)
110 .withCTag(C_TAG)
111 .withIpAddress(LOCAL_IP)
112 .withMacAddress(OLT_MAC)
113 .withOltConnectPoint(OLT_CONNECT_POINT)
114 .withOnuSerial(ONU_SERIAL)
115 .withQinqTpid(TPID)
116 .withSTag(S_TAG)
117 .build();
118 Map<BngProgrammable.BngCounterType, PiCounterCellData> attachmentStats = new HashMap<>();
119 attachmentStats.put(BngProgrammable.BngCounterType.CONTROL_PLANE,
120 new PiCounterCellData(1024, 1024));
121 BngStatsEventSubject subject = new BngStatsEventSubject("PppoeKey",
122 pppoeBngAttachment, attachmentStats);
123 return new BngStatsEvent(BngStatsEvent.EventType.STATS_UPDATED, subject);
124 }
125
126 protected IgmpStatisticsEvent getIgmpStatisticsEvent() {
127 return new IgmpStatisticsEvent(
128 IgmpStatisticsEvent.Type.STATS_UPDATE, new IgmpStatistics());
129 }
130
131 protected CordMcastStatisticsEvent getCordMcastStatisticsEvent() {
132 List<CordMcastStatistics> statsList = Lists.newArrayList(
133 new CordMcastStatistics(IpAddress.valueOf("172.16.34.34"),
134 "192.168.0.21", VlanId.vlanId("100")),
135 new CordMcastStatistics(IpAddress.valueOf("172.16.35.35"),
136 "192.168.0.22", VlanId.vlanId("101"))
137 );
138 return new CordMcastStatisticsEvent(
139 CordMcastStatisticsEvent.Type.STATUS_UPDATE, statsList);
140 }
141}