2 * Copyright (c) 2016 Cisco Systems Inc and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.unimgr.mef.nrp.common;
10 import org.opendaylight.unimgr.mef.nrp.api.EndPoint;
11 import org.opendaylight.unimgr.utils.SipHandler;
12 import org.opendaylight.yang.gen.v1.urn.mef.yang.nrp_interface.rev170227.nrp.create.connectivity.service.end.point.attrs.NrpCgEthFrameFlowCpaAspec;
13 import org.opendaylight.yang.gen.v1.urn.mef.yang.tapicommon.rev170227.UniversalId;
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
18 import java.util.regex.Matcher;
19 import java.util.regex.Pattern;
22 * Class representing port (replacement for FcPort)
24 * @author marek.ryznar@amartus.com
26 public class ServicePort {
27 private static final String pattern = ".+?(?=((((\\d+)/)+)\\d+))";
28 private static final Pattern interface_name_pattern = Pattern.compile(pattern);
29 private static final String default_interface_name = "GigabitEthernet";
32 private TopologyId topoId;
33 //represents device ie dev-68 in netconf topology
34 private NodeId nodeId;
37 //defines cTag VLAN ID
38 private Long vlanId=null;
40 public ServicePort(TopologyId topoId, NodeId nodeId, TpId tpId){
46 public TopologyId getTopology() {
50 public void setTopology(TopologyId topoId) {
54 public NodeId getNode() {
58 public void setNode(NodeId nodeId) {
66 public void setTp(TpId tpId) {
70 public Long getVlanId() {
74 public void setVlanId(Long vlanId) {
78 public static ServicePort toServicePort(EndPoint endPoint, String topologyName){
79 UniversalId sip = endPoint.getEndpoint().getServiceInterfacePoint();
80 TopologyId topologyId = new TopologyId(topologyName);
81 NodeId nodeId = new NodeId(SipHandler.getDeviceName(sip));
82 TpId tpId = new TpId(SipHandler.getPortName(sip));
83 ServicePort servicePort = new ServicePort(topologyId,nodeId,tpId);
84 if(hasVlan(endPoint)){
85 servicePort.setVlanId(Long.valueOf(getVlan(endPoint)));
90 public static boolean hasVlan(EndPoint endPoint){
91 if( (endPoint.getAttrs() != null) && (endPoint.getAttrs().getNrpCgEthFrameFlowCpaAspec()!=null) ){
92 NrpCgEthFrameFlowCpaAspec attr = endPoint.getAttrs().getNrpCgEthFrameFlowCpaAspec();
93 if( (attr.getCeVlanIdList()!=null) && !(attr.getCeVlanIdList().getVlanIdList().isEmpty()) ){
103 private static int getVlan(EndPoint endPoint){
104 return endPoint.getAttrs().getNrpCgEthFrameFlowCpaAspec().getCeVlanIdList().getVlanIdList().get(0).getVlanId().getValue().intValue();
107 public String getInterfaceName(){
108 TpId tpId = this.getTp();
109 Matcher matcher = interface_name_pattern.matcher(tpId.getValue());
110 return matcher.find() ? matcher.group() : default_interface_name;