karthik1977 | bc5ea1e | 2023-01-02 19:25:14 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2023-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.netflow.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 | /** |
| 26 | * Channel handler deals with the netfow exporter connection and dispatches messages |
| 27 | * from netfow exporter to the appropriate locations. |
| 28 | */ |
| 29 | public class NeflowChannelHandler extends SimpleChannelHandler { |
| 30 | |
| 31 | private Channel channel; |
| 32 | |
| 33 | /** |
| 34 | * Create a new netflow channelHandler instance. |
| 35 | */ |
| 36 | NeflowChannelHandler() { |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Netflow channel connect to netflow exporter. |
| 41 | * |
| 42 | * @param ctx channel handler context |
| 43 | * @param event channel state event |
| 44 | * @throws Exception on error while connecting channel |
| 45 | */ |
| 46 | @Override |
| 47 | public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent event) throws Exception { |
| 48 | channel = event.getChannel(); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Netflow channel disconnect to netflow exporter. |
| 53 | * |
| 54 | * @param ctx channel handler context |
| 55 | * @param event channel state event |
| 56 | * @throws Exception on error while disconnecting channel |
| 57 | */ |
| 58 | @Override |
| 59 | public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent event) throws Exception { |
| 60 | channel = event.getChannel(); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Netflow channel exception to netflow exporter. |
| 65 | * |
| 66 | * @param ctx channel handler context |
| 67 | * @param event channel exception event |
| 68 | * @throws Exception on error while parsing exception |
| 69 | */ |
| 70 | @Override |
| 71 | public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent event) throws Exception { |
| 72 | //TODO exception handler |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Netflow message receive from netflow exporter. |
| 77 | * |
| 78 | * @param ctx channel handler context |
| 79 | * @param event channel message event |
| 80 | * @throws Exception on error while parsing exception |
| 81 | */ |
| 82 | @Override |
| 83 | public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception { |
| 84 | //TODO Netflow message store to netflow distributed store |
| 85 | NetFlowPacket packet = (NetFlowPacket) event.getMessage(); |
| 86 | } |
| 87 | |
| 88 | } |