/protocols/ss7/hardware/dialogic/java/src/main/java/org/mobicents/ss7/hardware/dialogic/oam/DialogicLinkset.java
Java | 302 lines | 134 code | 57 blank | 111 comment | 7 complexity | a902646c579e1b6ed27434585f9a0bc6 MD5 | raw file
1/* 2 * JBoss, Home of Professional Open Source 3 * Copyright 2011, Red Hat, Inc. and individual contributors 4 * by the @authors tag. See the copyright.txt in the distribution for a 5 * full listing of individual contributors. 6 * 7 * This is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this software; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 */ 22 23package org.mobicents.ss7.hardware.dialogic.oam; 24 25import java.io.IOException; 26import java.nio.ByteBuffer; 27 28import javolution.xml.XMLFormat; 29import javolution.xml.stream.XMLStreamException; 30 31import org.apache.log4j.Logger; 32import org.mobicents.protocols.stream.api.SelectorKey; 33import org.mobicents.protocols.stream.api.SelectorProvider; 34import org.mobicents.protocols.stream.api.StreamSelector; 35import org.mobicents.ss7.hardware.dialogic.InterProcessCommunicator; 36import org.mobicents.ss7.linkset.oam.FormatterHelp; 37import org.mobicents.ss7.linkset.oam.LinkOAMMessages; 38import org.mobicents.ss7.linkset.oam.Linkset; 39import org.mobicents.ss7.linkset.oam.LinksetMode; 40import org.mobicents.ss7.linkset.oam.LinksetSelector; 41import org.mobicents.ss7.linkset.oam.LinksetState; 42import org.mobicents.ss7.linkset.oam.LinksetStream; 43 44/** 45 * <p> 46 * Linkset for <tt>dialogic</tt> based hardware. <tt>dialogic</tt> boards 47 * have MTP2 and MTP3 support on board. 48 * </p> 49 * 50 * @author amit bhayani 51 * 52 */ 53public class DialogicLinkset extends Linkset { 54 55 private static final Logger logger = Logger.getLogger(DialogicLinkset.class); 56 57 private static final String SRC_MODULE = "srcMod"; 58 private static final String DEST_MODULE = "destMod"; 59 60 private InterProcessCommunicator ipc; 61 62 private int sourceModule; 63 private int destModule; 64 65 public DialogicLinkset() { 66 super(); 67 } 68 69 public DialogicLinkset(String linksetName, int opc, int dpc, int ni, int srcMod, int dstMod) { 70 super(linksetName, opc, dpc, ni); 71 this.sourceModule = srcMod; 72 this.destModule = dstMod; 73 } 74 75 public int getSourceModule() { 76 return sourceModule; 77 } 78 79 public void setSourceModule(int sourceModule) { 80 this.sourceModule = sourceModule; 81 } 82 83 public int getDestModule() { 84 return destModule; 85 } 86 87 public void setDestModule(int destModule) { 88 this.destModule = destModule; 89 } 90 91 @Override 92 protected void initialize() { 93 // this.linksetStream = new LinksetStreamImpl(); 94 } 95 96 @Override 97 protected void configure() throws Exception { 98 if (this.mode == LinksetMode.CONFIGURED) { 99 ipc = new InterProcessCommunicator(this.sourceModule, this.destModule); 100 } 101 102 } 103 104 @Override 105 public void activate() throws Exception { 106 if (this.state == LinksetState.AVAILABLE) { 107 throw new Exception(LinkOAMMessages.LINKSET_ALREADY_ACTIVE); 108 } 109 110 this.mode = LinksetMode.CONFIGURED; 111 this.configure(); 112 } 113 114 @Override 115 public void deactivate() throws Exception { 116 throw new Exception(LinkOAMMessages.NOT_IMPLEMENTED); 117 } 118 119 @Override 120 public void activateLink(String linkName) throws Exception { 121 throw new Exception(LinkOAMMessages.OPERATION_NOT_SUPPORTED); 122 } 123 124 @Override 125 public void deactivateLink(String linkName) throws Exception { 126 throw new Exception(LinkOAMMessages.OPERATION_NOT_SUPPORTED); 127 } 128 129 @Override 130 public void createLink(String[] arg0) throws Exception { 131 throw new Exception(LinkOAMMessages.NOT_IMPLEMENTED); 132 } 133 134 @Override 135 public void deleteLink(String arg0) throws Exception { 136 throw new Exception(LinkOAMMessages.NOT_IMPLEMENTED); 137 } 138 139 protected static final XMLFormat<DialogicLinkset> DAHDI_LINK_XML = new XMLFormat<DialogicLinkset>( 140 DialogicLinkset.class) { 141 142 @Override 143 public void read(javolution.xml.XMLFormat.InputElement xml, DialogicLinkset linkset) throws XMLStreamException { 144 145 LINKSET_XML.read(xml, linkset); 146 147 linkset.sourceModule = xml.getAttribute(SRC_MODULE, -1); 148 linkset.destModule = xml.getAttribute(DEST_MODULE, -1); 149 150 try { 151 linkset.configure(); 152 } catch (Exception e) { 153 logger.error("Failed to initialize dialogic card", e); 154 } 155 } 156 157 @Override 158 public void write(DialogicLinkset linkset, javolution.xml.XMLFormat.OutputElement xml) 159 throws XMLStreamException { 160 161 LINKSET_XML.write(linkset, xml); 162 163 xml.setAttribute(SRC_MODULE, linkset.sourceModule); 164 xml.setAttribute(DEST_MODULE, linkset.destModule); 165 } 166 }; 167 168// private class LinksetStreamImpl extends LinksetStream { 169// ByteBuffer rxData = null; 170// 171// @Override 172// public boolean poll(int arg0, int arg1) { 173// rxData = null; 174// try { 175// if (ipc != null) { 176// rxData = ipc.read(null); 177// return true; 178// } 179// } catch (IOException ex) { 180// logger.error("IO error while receiving data from InterProcessCommunicator", ex); 181// } 182// return false; 183// } 184// 185// @Override 186// public String getName() { 187// return linksetName; 188// } 189// 190// public void close() { 191// // TODO Auto-generated method stub 192// 193// } 194// 195// public SelectorProvider provider() { 196// throw new UnsupportedOperationException("Not supported yet."); 197// } 198// 199// public int read(byte[] paramArrayOfByte) throws IOException { 200// if (rxData != null) { 201// System.arraycopy(rxData, 0, paramArrayOfByte, 0, rxData.length); 202// return rxData.length; 203// } 204// 205// return 0; 206// } 207// 208// public SelectorKey register(StreamSelector selector) throws IOException { 209// return ((LinksetSelector) selector).register(this); 210// } 211// 212// public int write(byte[] paramArrayOfByte) throws IOException { 213// ipc.send(paramArrayOfByte); 214// return paramArrayOfByte.length; 215// } 216// 217// @Override 218// public int read(ByteBuffer arg0) throws IOException { 219// // TODO Auto-generated method stub 220// return 0; 221// } 222// 223// @Override 224// public int write(ByteBuffer arg0) throws IOException { 225// // TODO Auto-generated method stub 226// return 0; 227// } 228// } 229 230 @Override 231 public void print(StringBuffer sb, int leftPad, int descPad) { 232 233 // left pad 234 FormatterHelp.createPad(sb, leftPad); 235 236 // Add name 237 sb.append(this.linksetName); 238 239 // check if length is less than Link.NAME_SIZE, add padding 240 if (this.linksetName.length() < Linkset.NAME_SIZE) { 241 FormatterHelp.createPad(sb, Linkset.NAME_SIZE - this.linksetName.length()); 242 } 243 244 // add desc padding 245 FormatterHelp.createPad(sb, descPad); 246 247 // type is dahdi 248 sb.append("dialogic"); 249 250 // add desc padding 251 FormatterHelp.createPad(sb, descPad); 252 253 // add opc 254 sb.append(LINKSET_OPC).append(FormatterHelp.EQUAL_SIGN).append(this.opc); 255 256 // opc can be max 8 (ANSI is max 24bits) digits. Add padding if its not 257 int length = (Integer.toString(this.opc).length()); 258 if (length < 8) { 259 FormatterHelp.createPad(sb, 8 - length); 260 } 261 262 // add desc padding 263 FormatterHelp.createPad(sb, descPad); 264 265 // add apc 266 sb.append(LINKSET_APC).append(FormatterHelp.EQUAL_SIGN).append(this.apc); 267 268 // opc can be max 8 (ANSI is max 24bits) digits. Add padding if its not 269 length = (Integer.toString(this.apc).length()); 270 if (length < 8) { 271 FormatterHelp.createPad(sb, 8 - length); 272 } 273 274 // add desc padding 275 FormatterHelp.createPad(sb, descPad); 276 277 // add NI 278 sb.append(LINKSET_NI).append(FormatterHelp.EQUAL_SIGN).append(this.ni); 279 280 // add desc padding 281 FormatterHelp.createPad(sb, descPad); 282 283 // add Source Module 284 sb.append(SRC_MODULE).append(FormatterHelp.EQUAL_SIGN).append(this.sourceModule); 285 286 // add desc padding 287 FormatterHelp.createPad(sb, descPad); 288 289 // add dest Module 290 sb.append(DEST_MODULE).append(FormatterHelp.EQUAL_SIGN).append(this.destModule); 291 292 // add desc padding 293 FormatterHelp.createPad(sb, descPad); 294 295 // add state 296 sb.append(LINKSET_STATE).append(FormatterHelp.EQUAL_SIGN).append(FormatterHelp.getLinksetState(this.state)); 297 298 sb.append(FormatterHelp.NEW_LINE); 299 300 } 301 302}