|
| 1 | +package org.onosproject.ecord.carrierethernet.app; |
| 2 | + |
| 3 | +import org.onlab.packet.VlanId; |
| 4 | +import org.onlab.util.Bandwidth; |
| 5 | +import org.onosproject.net.ConnectPoint; |
| 6 | + |
| 7 | +import java.util.HashSet; |
| 8 | +import java.util.List; |
| 9 | +import java.util.Set; |
| 10 | + |
| 11 | +import static org.onosproject.ecord.carrierethernet.app.CarrierEthernetVirtualConnection.MAX_NUM_UNI; |
| 12 | + |
| 13 | +/** |
| 14 | + * Utilities to build EthernetVirtualConnections. |
| 15 | + */ |
| 16 | +public final class CarrierEthernetEvcUtils { |
| 17 | + |
| 18 | + // no instantiation |
| 19 | + private CarrierEthernetEvcUtils() { |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * Return the CE-VLAN ID for the CE evc based on the CLI-supplied argument. |
| 24 | + * |
| 25 | + * @param argCeVlanId vlanID |
| 26 | + * @return CE-VLAN ID for the CE evc |
| 27 | + */ |
| 28 | + public static VlanId generateCeVlanId(short argCeVlanId) { |
| 29 | + return ((argCeVlanId == -1) ? null : VlanId.vlanId(argCeVlanId)); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Return the CE evc type based on the CLI-supplied arguments. |
| 34 | + * |
| 35 | + * @param evcTypeString EVC type |
| 36 | + * @param uniList UNIs list |
| 37 | + * @return the CE evc type |
| 38 | + */ |
| 39 | + public static CarrierEthernetConnection.Type generateEvcType(String evcTypeString, List<String> uniList) { |
| 40 | + if (evcTypeString == null) { |
| 41 | + return ((uniList.size() > 2) ? |
| 42 | + CarrierEthernetConnection.Type.MULTIPOINT_TO_MULTIPOINT : |
| 43 | + CarrierEthernetConnection.Type.POINT_TO_POINT); |
| 44 | + } else { |
| 45 | + // TODO: Catch exception |
| 46 | + return CarrierEthernetConnection.Type.valueOf(evcTypeString); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Return the EVC maxNumUni parameter based on the CLI-supplied arguments. |
| 52 | + * |
| 53 | + * @param maxNumUni maximum numbers of UNIs |
| 54 | + * @param evcTypeString EVC Type |
| 55 | + * @param uniList UNIs list |
| 56 | + * @return the maxNumUni parameter |
| 57 | + */ |
| 58 | + public static Integer generateMaxNumUni(int maxNumUni, String evcTypeString, List<String> uniList) { |
| 59 | + if (maxNumUni == -1) { |
| 60 | + if (evcTypeString == null) { |
| 61 | + return ((uniList.size() > 2) ? |
| 62 | + MAX_NUM_UNI : 2); |
| 63 | + } else { |
| 64 | + // TODO: Catch exception |
| 65 | + CarrierEthernetConnection.Type evcType = |
| 66 | + CarrierEthernetConnection.Type.valueOf(evcTypeString); |
| 67 | + return (evcType.equals(CarrierEthernetConnection.Type.POINT_TO_POINT) ? 2 : |
| 68 | + MAX_NUM_UNI); |
| 69 | + } |
| 70 | + } else { |
| 71 | + return maxNumUni; |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Return the BW profile type based on the CLI-supplied arguments. |
| 77 | + * |
| 78 | + * @param ceVlanId vlanID |
| 79 | + * @return the BWP profile type |
| 80 | + */ |
| 81 | + public static CarrierEthernetBandwidthProfile.Type generateBandwidthProfileType(short ceVlanId) { |
| 82 | + // TODO: Add the CoS BW profile case |
| 83 | + return ((ceVlanId == -1) ? |
| 84 | + CarrierEthernetBandwidthProfile.Type.INTERFACE : CarrierEthernetBandwidthProfile.Type.EVC); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Return the BW profile id based on the CLI-supplied arguments. |
| 89 | + * |
| 90 | + * @param uniId UNI id |
| 91 | + * @param evcCfgId EVC configuration Id |
| 92 | + * @param ceVlanId vlanID |
| 93 | + * @return the BW profile id |
| 94 | + */ |
| 95 | + public static String generateBandwidthProfileId(String uniId, String evcCfgId, int ceVlanId) { |
| 96 | + // TODO: Add the CoS BW profile case |
| 97 | + return ((ceVlanId == -1) ? uniId : evcCfgId); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Return the set of UNIs for the CE EVC based on the CLI-supplied arguments. |
| 102 | + * |
| 103 | + * @param evcTypeString Type of the UNI |
| 104 | + * @param uniList list of remaning UNIs |
| 105 | + * @param ceVlanId vlanID |
| 106 | + * @param firstUni first UNI id |
| 107 | + * @param evcCfgId EVC configuration Id |
| 108 | + * @param cir The CIR in Mbps |
| 109 | + * @param eir The EIR in Mbps |
| 110 | + * @param cbs The CBS in Byte |
| 111 | + * @param ebs The EBS in Byte |
| 112 | + * @return the set of UNIs for the CE EVC |
| 113 | + */ |
| 114 | + public static Set<CarrierEthernetUni> generateUniSet(String evcTypeString, List<String> uniList, |
| 115 | + short ceVlanId, String firstUni, String evcCfgId, |
| 116 | + Double cir, Double eir, Long cbs, Long ebs) { |
| 117 | + |
| 118 | + Set<CarrierEthernetUni> uniSet = new HashSet<>(); |
| 119 | + |
| 120 | + CarrierEthernetConnection.Type evcType = generateEvcType(evcTypeString, uniList); |
| 121 | + |
| 122 | + // We assume that first UNI supplied is always root |
| 123 | + uniSet.add(CarrierEthernetUni.builder() |
| 124 | + .cp(ConnectPoint.deviceConnectPoint(firstUni)) |
| 125 | + .role(CarrierEthernetUni.Role.ROOT) |
| 126 | + .ceVlanId(generateCeVlanId(ceVlanId)) |
| 127 | + .bwp(CarrierEthernetBandwidthProfile.builder() |
| 128 | + .id(generateBandwidthProfileId(firstUni, evcCfgId, ceVlanId)) |
| 129 | + .type(generateBandwidthProfileType(ceVlanId)) |
| 130 | + .cir(Bandwidth.mbps(cir)) |
| 131 | + .eir(Bandwidth.mbps(eir)) |
| 132 | + .cbs(cbs) |
| 133 | + .ebs(ebs) |
| 134 | + .build()) |
| 135 | + .build()); |
| 136 | + |
| 137 | + final CarrierEthernetUni.Role role; |
| 138 | + // For E-Line and E-LAN all UNIs are roots. For E-Tree all UNIs are leafs except from one |
| 139 | + role = ((evcType == CarrierEthernetConnection.Type.ROOT_MULTIPOINT) ? |
| 140 | + CarrierEthernetUni.Role.LEAF : CarrierEthernetUni.Role.ROOT); |
| 141 | + |
| 142 | + uniList.forEach(argUni -> uniSet.add( |
| 143 | + CarrierEthernetUni.builder() |
| 144 | + .cp(ConnectPoint.deviceConnectPoint(argUni)) |
| 145 | + .role(role) |
| 146 | + .ceVlanId(generateCeVlanId(ceVlanId)) |
| 147 | + .bwp(CarrierEthernetBandwidthProfile.builder() |
| 148 | + .id(generateBandwidthProfileId(argUni, evcCfgId, ceVlanId)) |
| 149 | + .type(generateBandwidthProfileType(ceVlanId)) |
| 150 | + .cir(Bandwidth.mbps(cir)) |
| 151 | + .eir(Bandwidth.mbps(eir)) |
| 152 | + .cbs(cbs) |
| 153 | + .ebs(ebs) |
| 154 | + .build()) |
| 155 | + .build())); |
| 156 | + |
| 157 | + return uniSet; |
| 158 | + } |
| 159 | +} |
0 commit comments