karthik1977 | 6806c98 | 2024-02-17 18:46:43 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2024-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 | */ |
| 16 | package org.onosproject.sflow.impl; |
| 17 | |
| 18 | import org.jboss.netty.channel.ChannelHandlerContext; |
| 19 | import org.jboss.netty.channel.ChannelStateEvent; |
| 20 | import org.jboss.netty.channel.ExceptionEvent; |
| 21 | import org.jboss.netty.channel.MessageEvent; |
| 22 | import org.jboss.netty.channel.Channel; |
| 23 | import org.jboss.netty.channel.SimpleChannelHandler; |
| 24 | |
| 25 | import org.slf4j.Logger; |
| 26 | import org.slf4j.LoggerFactory; |
| 27 | |
| 28 | import org.onosproject.sflow.SflowController; |
| 29 | |
| 30 | /** |
| 31 | * Channel handler deals with the netfow exporter connection and dispatches messages |
| 32 | * from netfow exporter to the appropriate locations. |
| 33 | */ |
| 34 | public class SflowChannelHandler extends SimpleChannelHandler { |
| 35 | |
| 36 | private static final Logger log = LoggerFactory.getLogger(SflowChannelHandler.class); |
| 37 | |
| 38 | private Channel channel; |
| 39 | |
| 40 | private SflowController controller; |
| 41 | |
| 42 | /** |
| 43 | * Create a new sFlow channelHandler instance. |
| 44 | * |
| 45 | * @param controller sFlow controller. |
| 46 | */ |
| 47 | SflowChannelHandler(SflowController controller) { |
| 48 | this.controller = controller; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * sFlow channel connect to sFlow exporter. |
| 53 | * |
| 54 | * @param ctx channel handler context |
| 55 | * @param event channel state event |
| 56 | * @throws Exception on error while connecting channel |
| 57 | */ |
| 58 | @Override |
| 59 | public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent event) throws Exception { |
| 60 | channel = event.getChannel(); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * sFlow channel disconnect to sFlow exporter. |
| 65 | * |
| 66 | * @param ctx channel handler context |
| 67 | * @param event channel state event |
| 68 | * @throws Exception on error while disconnecting channel |
| 69 | */ |
| 70 | @Override |
| 71 | public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent event) throws Exception { |
| 72 | channel = event.getChannel(); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * sFlow channel exception to sFlow exporter. |
| 77 | * |
| 78 | * @param ctx channel handler context |
| 79 | * @param event channel exception event |
| 80 | * @throws Exception on error while parsing exception |
| 81 | */ |
| 82 | @Override |
| 83 | public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent event) throws Exception { |
| 84 | //TODO exception handler |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * sFlow message receive from sFlow exporter. |
| 89 | * |
| 90 | * @param ctx channel handler context |
| 91 | * @param event channel message event |
| 92 | * @throws Exception on error while parsing exception |
| 93 | */ |
| 94 | @Override |
| 95 | public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception { |
| 96 | channel = event.getChannel(); |
| 97 | } |
| 98 | |
| 99 | } |
| 100 | |