tejeshwer degala | 3fe1ed5 | 2016-04-22 17:04:01 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
tejeshwer degala | 3fe1ed5 | 2016-04-22 17:04:01 +0530 | [diff] [blame] | 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.isis.controller.impl; |
| 17 | |
| 18 | import com.google.common.primitives.Bytes; |
| 19 | import org.jboss.netty.channel.Channel; |
| 20 | import org.onosproject.isis.controller.IsisInterface; |
| 21 | import org.onosproject.isis.controller.IsisNetworkType; |
| 22 | import org.onosproject.isis.controller.IsisRouterType; |
| 23 | import org.onosproject.isis.io.util.IsisUtil; |
| 24 | import org.slf4j.Logger; |
| 25 | import org.slf4j.LoggerFactory; |
| 26 | |
| 27 | /** |
| 28 | * Representation of an ISIS hello pdu sender task. |
| 29 | */ |
| 30 | public class IsisHelloPduSender implements Runnable { |
| 31 | private static final Logger log = LoggerFactory.getLogger(IsisHelloPduSender.class); |
| 32 | private Channel channel = null; |
| 33 | private IsisInterface isisInterface = null; |
| 34 | |
| 35 | /** |
| 36 | * Creates an instance of Hello PDU Sender task. |
| 37 | * |
| 38 | * @param channel netty channel instance |
| 39 | * @param isisInterface ISIS interface instance |
| 40 | */ |
| 41 | public IsisHelloPduSender(Channel channel, IsisInterface isisInterface) { |
| 42 | this.channel = channel; |
| 43 | this.isisInterface = isisInterface; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public void run() { |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 48 | if (channel != null && channel.isConnected() && channel.isOpen()) { |
tejeshwer degala | 3fe1ed5 | 2016-04-22 17:04:01 +0530 | [diff] [blame] | 49 | try { |
| 50 | byte[] helloPdu = null; |
| 51 | byte[] interfaceIndex = {(byte) isisInterface.interfaceIndex()}; |
| 52 | |
| 53 | if (isisInterface.networkType() == IsisNetworkType.P2P) { |
| 54 | helloPdu = IsisUtil.getP2pHelloPdu(isisInterface, true); |
| 55 | helloPdu = Bytes.concat(helloPdu, interfaceIndex); |
| 56 | channel.write(helloPdu); |
| 57 | } else if (isisInterface.networkType() == IsisNetworkType.BROADCAST) { |
| 58 | switch (IsisRouterType.get(isisInterface.reservedPacketCircuitType())) { |
| 59 | case L1: |
| 60 | helloPdu = IsisUtil.getL1HelloPdu(isisInterface, true); |
| 61 | helloPdu = Bytes.concat(helloPdu, interfaceIndex); |
| 62 | channel.write(helloPdu); |
| 63 | break; |
| 64 | case L2: |
| 65 | helloPdu = IsisUtil.getL2HelloPdu(isisInterface, true); |
| 66 | helloPdu = Bytes.concat(helloPdu, interfaceIndex); |
| 67 | channel.write(helloPdu); |
| 68 | break; |
| 69 | case L1L2: |
| 70 | helloPdu = IsisUtil.getL1HelloPdu(isisInterface, true); |
| 71 | helloPdu = Bytes.concat(helloPdu, interfaceIndex); |
| 72 | channel.write(helloPdu); |
| 73 | |
| 74 | helloPdu = IsisUtil.getL2HelloPdu(isisInterface, true); |
| 75 | helloPdu = Bytes.concat(helloPdu, interfaceIndex); |
| 76 | channel.write(helloPdu); |
| 77 | break; |
| 78 | default: |
| 79 | log.debug("IsisHelloPduSender::Unknown circuit type...!!!"); |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | } catch (Exception e) { |
| 84 | log.debug("Exception @IsisHelloPduSender:: {}", e.getMessage()); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |