blob: 38fca339e88b37bde1cb3289bf442b9cfec523a1 [file] [log] [blame]
kishoreefa3db52020-03-23 16:09:26 +05301/*
Joey Armstrong89c55e02023-01-09 18:09:41 -05002 * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors
kishoreefa3db52020-03-23 16:09:26 +05303 *
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);
Matteo Scandolo5e406d22020-08-24 15:17:54 -070067 protected static final String SUBSCRIBER_ID = ONU_SERIAL + "-1";
kishoreefa3db52020-03-23 16:09:26 +053068
69 protected AuthenticationEvent getAuthenticationEvent() {
70 return new AuthenticationEvent(AuthenticationEvent.Type.APPROVED,
71 OLT_CONNECT_POINT);
72 }
73
74 protected AuthenticationStatisticsEvent getAuthenticationStatisticsEvent() {
75 return new AuthenticationStatisticsEvent(
76 AuthenticationStatisticsEvent.Type.STATS_UPDATE,
77 new AaaStatistics());
78 }
79
80 protected RadiusOperationalStatusEvent getRadiusOperationalStatusEvent() {
81 return new RadiusOperationalStatusEvent(
82 RadiusOperationalStatusEvent.Type.RADIUS_OPERATIONAL_STATUS,
83 "AUTHENTICATED");
84 }
85
86 protected AaaMachineStatisticsEvent getAaaMachineStatisticsEvent() {
87 return new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE,
88 new AaaSupplicantMachineStats());
89 }
90
91 protected AccessDeviceEvent getUniAdded() {
92 return new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED,
93 DEVICE_ID_1, PORT, CLIENT_S_TAG, CLIENT_C_TAG, (int) TPID);
94 }
95
96 protected AccessDeviceEvent getUniRemoved() {
97 return new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED,
98 DEVICE_ID_1, PORT, CLIENT_S_TAG, CLIENT_C_TAG, (int) TPID);
99 }
100
101 protected PppoeEvent getPppoeEvent() {
102 return new PppoeEvent(PppoeEvent.EventType.AUTH_SUCCESS,
103 new PppoeEventSubject(OLT_CONNECT_POINT,
104 LOCAL_IP, OLT_MAC,
105 ONU_SERIAL, SESSION_ID, S_TAG, C_TAG));
106 }
107
108 protected BngStatsEvent getBngStatsEvent() {
109 PppoeBngAttachment pppoeBngAttachment = (PppoeBngAttachment) PppoeBngAttachment.builder()
110 .withPppoeSessionId(SESSION_ID)
111 .withCTag(C_TAG)
112 .withIpAddress(LOCAL_IP)
113 .withMacAddress(OLT_MAC)
114 .withOltConnectPoint(OLT_CONNECT_POINT)
115 .withOnuSerial(ONU_SERIAL)
116 .withQinqTpid(TPID)
117 .withSTag(S_TAG)
118 .build();
119 Map<BngProgrammable.BngCounterType, PiCounterCellData> attachmentStats = new HashMap<>();
120 attachmentStats.put(BngProgrammable.BngCounterType.CONTROL_PLANE,
121 new PiCounterCellData(1024, 1024));
122 BngStatsEventSubject subject = new BngStatsEventSubject("PppoeKey",
123 pppoeBngAttachment, attachmentStats);
124 return new BngStatsEvent(BngStatsEvent.EventType.STATS_UPDATED, subject);
125 }
126
127 protected IgmpStatisticsEvent getIgmpStatisticsEvent() {
128 return new IgmpStatisticsEvent(
129 IgmpStatisticsEvent.Type.STATS_UPDATE, new IgmpStatistics());
130 }
131
132 protected CordMcastStatisticsEvent getCordMcastStatisticsEvent() {
133 List<CordMcastStatistics> statsList = Lists.newArrayList(
134 new CordMcastStatistics(IpAddress.valueOf("172.16.34.34"),
Andrea Campanellabbb36592020-07-01 16:50:48 +0200135 "192.168.0.21", VlanId.vlanId("100"), VlanId.vlanId("200")),
kishoreefa3db52020-03-23 16:09:26 +0530136 new CordMcastStatistics(IpAddress.valueOf("172.16.35.35"),
Andrea Campanellabbb36592020-07-01 16:50:48 +0200137 "192.168.0.22", VlanId.vlanId("101"), VlanId.vlanId("201"))
kishoreefa3db52020-03-23 16:09:26 +0530138 );
139 return new CordMcastStatisticsEvent(
140 CordMcastStatisticsEvent.Type.STATUS_UPDATE, statsList);
141 }
142}