blob: c97b5a564d398512d68fd9daaa9b4be26b8a1bd3 [file] [log] [blame]
tejeshwer degala3fe1ed52016-04-22 17:04:01 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
tejeshwer degala3fe1ed52016-04-22 17:04:01 +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.onosproject.isis.controller.impl;
17
18import com.google.common.primitives.Bytes;
19import org.jboss.netty.channel.Channel;
20import org.onosproject.isis.controller.IsisInterface;
21import org.onosproject.isis.controller.IsisNetworkType;
22import org.onosproject.isis.controller.IsisRouterType;
23import org.onosproject.isis.io.util.IsisUtil;
24import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
26
27/**
28 * Representation of an ISIS hello pdu sender task.
29 */
30public 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 vk4b5ce002016-05-09 20:18:35 +053048 if (channel != null && channel.isConnected() && channel.isOpen()) {
tejeshwer degala3fe1ed52016-04-22 17:04:01 +053049 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}