Committed by
Gerrit Code Review
[ONOS-4163] PCE service API
Change-Id: Iab8faeb85e9dcd6ec62a65f1ea8168b1be9ca39c
Showing
3 changed files
with
290 additions
and
6 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 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.pce.pceservice; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | +import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS; | ||
| 20 | + | ||
| 21 | +import java.util.Iterator; | ||
| 22 | +import java.util.List; | ||
| 23 | + | ||
| 24 | +import org.apache.felix.scr.annotations.Activate; | ||
| 25 | +import org.apache.felix.scr.annotations.Component; | ||
| 26 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 27 | +import org.apache.felix.scr.annotations.Reference; | ||
| 28 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 29 | +import org.apache.felix.scr.annotations.Service; | ||
| 30 | +import org.onosproject.core.ApplicationId; | ||
| 31 | +import org.onosproject.core.CoreService; | ||
| 32 | +import org.onosproject.core.IdGenerator; | ||
| 33 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 34 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 35 | +import org.onosproject.incubator.net.tunnel.TunnelService; | ||
| 36 | +import org.onosproject.net.DeviceId; | ||
| 37 | +import org.onosproject.net.intent.Constraint; | ||
| 38 | +import org.onosproject.pce.pceservice.api.PceService; | ||
| 39 | +import org.onosproject.store.serializers.KryoNamespaces; | ||
| 40 | +import org.onosproject.store.service.DistributedSet; | ||
| 41 | +import org.onosproject.store.service.Serializer; | ||
| 42 | +import org.onosproject.store.service.StorageService; | ||
| 43 | +import org.slf4j.Logger; | ||
| 44 | +import org.slf4j.LoggerFactory; | ||
| 45 | + | ||
| 46 | +/** | ||
| 47 | + * Implementation of PCE service. | ||
| 48 | + */ | ||
| 49 | +@Component(immediate = true) | ||
| 50 | +@Service | ||
| 51 | +public class PceManager implements PceService { | ||
| 52 | + private static final Logger log = LoggerFactory.getLogger(PceManager.class); | ||
| 53 | + | ||
| 54 | + public static final String PCE_SERVICE_APP = "org.onosproject.pce"; | ||
| 55 | + | ||
| 56 | + private static final String LOCAL_LSP_ID_GEN_TOPIC = "pcep-local-lsp-id"; | ||
| 57 | + private IdGenerator localLspIdIdGen; | ||
| 58 | + protected DistributedSet<Short> localLspIdFreeList; | ||
| 59 | + | ||
| 60 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 61 | + protected CoreService coreService; | ||
| 62 | + | ||
| 63 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 64 | + protected TunnelService tunnelService; | ||
| 65 | + | ||
| 66 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 67 | + protected StorageService storageService; | ||
| 68 | + | ||
| 69 | + private ApplicationId appId; | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * Creates new instance of PceManager. | ||
| 73 | + */ | ||
| 74 | + public PceManager() { | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Activate | ||
| 78 | + protected void activate() { | ||
| 79 | + appId = coreService.registerApplication(PCE_SERVICE_APP); | ||
| 80 | + log.info("Started"); | ||
| 81 | + | ||
| 82 | + localLspIdIdGen = coreService.getIdGenerator(LOCAL_LSP_ID_GEN_TOPIC); | ||
| 83 | + localLspIdFreeList = storageService.<Short>setBuilder() | ||
| 84 | + .withName("pcepLocalLspIdDeletedList") | ||
| 85 | + .withSerializer(Serializer.using(KryoNamespaces.API)) | ||
| 86 | + .build() | ||
| 87 | + .asDistributedSet(); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @Deactivate | ||
| 91 | + protected void deactivate() { | ||
| 92 | + log.info("Stopped"); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + //[TODO:] handle requests in queue | ||
| 96 | + @Override | ||
| 97 | + public boolean setupPath(DeviceId src, DeviceId dst, String tunnelName, List<Constraint> constraints, | ||
| 98 | + LspType lspType) { | ||
| 99 | + checkNotNull(src); | ||
| 100 | + checkNotNull(dst); | ||
| 101 | + checkNotNull(tunnelName); | ||
| 102 | + checkNotNull(constraints); | ||
| 103 | + checkNotNull(lspType); | ||
| 104 | + | ||
| 105 | + // TODO: compute and setup path. | ||
| 106 | + | ||
| 107 | + return true; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + | ||
| 111 | + @Override | ||
| 112 | + public boolean updatePath(TunnelId tunnelId, List<Constraint> constraints) { | ||
| 113 | + checkNotNull(tunnelId); | ||
| 114 | + checkNotNull(constraints); | ||
| 115 | + | ||
| 116 | + // TODO: compute and update path. | ||
| 117 | + | ||
| 118 | + return true; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + @Override | ||
| 122 | + public boolean releasePath(TunnelId tunnelId) { | ||
| 123 | + checkNotNull(tunnelId); | ||
| 124 | + // 1. Query Tunnel from Tunnel manager. | ||
| 125 | + Tunnel tunnel = tunnelService.queryTunnel(tunnelId); | ||
| 126 | + | ||
| 127 | + if (tunnel == null) { | ||
| 128 | + return false; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + // 2. Call tunnel service. | ||
| 132 | + return tunnelService.downTunnel(appId, tunnel.tunnelId()); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + @Override | ||
| 136 | + public Iterable<Tunnel> queryAllPath() { | ||
| 137 | + return tunnelService.queryTunnel(MPLS); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + @Override | ||
| 141 | + public Tunnel queryPath(TunnelId tunnelId) { | ||
| 142 | + return tunnelService.queryTunnel(tunnelId); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * Returns the next local LSP identifier to be used either by getting from | ||
| 147 | + * freed list if available otherwise generating a new one. | ||
| 148 | + * | ||
| 149 | + * @return value of local LSP identifier | ||
| 150 | + */ | ||
| 151 | + private short getNextLocalLspId() { | ||
| 152 | + // If there is any free id use it. Otherwise generate new id. | ||
| 153 | + if (localLspIdFreeList.isEmpty()) { | ||
| 154 | + return (short) localLspIdIdGen.getNewId(); | ||
| 155 | + } | ||
| 156 | + Iterator<Short> it = localLspIdFreeList.iterator(); | ||
| 157 | + Short value = it.next(); | ||
| 158 | + localLspIdFreeList.remove(value); | ||
| 159 | + return value; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 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.pce.pceservice; | ||
| 17 | + | ||
| 18 | +import org.onosproject.net.resource.ResourceConsumer; | ||
| 19 | + | ||
| 20 | +import com.google.common.annotations.Beta; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * Tunnel resource consumer identifier suitable to be used as a consumer id for | ||
| 24 | + * resource allocations. | ||
| 25 | + */ | ||
| 26 | +@Beta | ||
| 27 | +public final class TunnelConsumerId implements ResourceConsumer { | ||
| 28 | + | ||
| 29 | + private final long value; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * Creates a tunnel resource consumer identifier from the specified long value. | ||
| 33 | + * | ||
| 34 | + * @param value long value to be used as tunnel resource consumer id | ||
| 35 | + * @return tunnel resource consumer identifier | ||
| 36 | + */ | ||
| 37 | + public static TunnelConsumerId valueOf(long value) { | ||
| 38 | + return new TunnelConsumerId(value); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * Initializes object for serializer. | ||
| 43 | + */ | ||
| 44 | + public TunnelConsumerId() { | ||
| 45 | + this.value = 0; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Constructs the tunnel resource consumer id corresponding to a given long | ||
| 50 | + * value. | ||
| 51 | + * | ||
| 52 | + * @param value the underlying value in long representation of this tunnel | ||
| 53 | + * resource consumer id | ||
| 54 | + */ | ||
| 55 | + public TunnelConsumerId(long value) { | ||
| 56 | + this.value = value; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * Returns the tunnel resource consumer id value in long format. | ||
| 61 | + * | ||
| 62 | + * @return value the tunnel resource consumer id's long value | ||
| 63 | + */ | ||
| 64 | + public long value() { | ||
| 65 | + return value; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + @Override | ||
| 69 | + public int hashCode() { | ||
| 70 | + return Long.hashCode(value); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + @Override | ||
| 74 | + public boolean equals(Object obj) { | ||
| 75 | + if (obj == this) { | ||
| 76 | + return true; | ||
| 77 | + } | ||
| 78 | + if (!(obj instanceof TunnelConsumerId)) { | ||
| 79 | + return false; | ||
| 80 | + } | ||
| 81 | + TunnelConsumerId that = (TunnelConsumerId) obj; | ||
| 82 | + return this.value == that.value; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @Override | ||
| 86 | + public String toString() { | ||
| 87 | + return "0x" + Long.toHexString(value); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | +} |
| ... | @@ -20,24 +20,56 @@ import java.util.List; | ... | @@ -20,24 +20,56 @@ import java.util.List; |
| 20 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.net.intent.Constraint; | 21 | import org.onosproject.net.intent.Constraint; |
| 22 | import org.onosproject.pce.pceservice.LspType; | 22 | import org.onosproject.pce.pceservice.LspType; |
| 23 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 24 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 23 | 25 | ||
| 24 | /** | 26 | /** |
| 25 | - * Service to compute path based on constraints, release path and update path with new constraints. | 27 | + * Service to compute path based on constraints, release path, |
| 28 | + * update path with new constraints and query existing tunnels. | ||
| 26 | */ | 29 | */ |
| 27 | public interface PceService { | 30 | public interface PceService { |
| 28 | 31 | ||
| 29 | /** | 32 | /** |
| 30 | - * Creates new path based on constraints and lsp type. | 33 | + * Creates new path based on constraints and LSP type. |
| 31 | * | 34 | * |
| 32 | * @param src source device | 35 | * @param src source device |
| 33 | * @param dst destination device | 36 | * @param dst destination device |
| 37 | + * @param tunnelName name of the tunnel | ||
| 34 | * @param constraints list of constraints to be applied on path | 38 | * @param constraints list of constraints to be applied on path |
| 35 | * @param lspType type of path to be setup | 39 | * @param lspType type of path to be setup |
| 36 | * @return false on failure and true on successful path creation | 40 | * @return false on failure and true on successful path creation |
| 37 | */ | 41 | */ |
| 38 | - boolean setupPath(DeviceId src, DeviceId dst, List<Constraint> constraints, LspType lspType); | 42 | + boolean setupPath(DeviceId src, DeviceId dst, String tunnelName, List<Constraint> constraints, LspType lspType); |
| 39 | 43 | ||
| 40 | - //TODO: updatePath | 44 | + /** |
| 41 | - //TODO: releasePath | 45 | + * Updates an existing path. |
| 42 | - //TODO: queryPath | 46 | + * |
| 47 | + * @param tunnelId tunnel identifier | ||
| 48 | + * @param constraints list of constraints to be applied on path | ||
| 49 | + * @return false on failure and true on successful path update | ||
| 50 | + */ | ||
| 51 | + boolean updatePath(TunnelId tunnelId, List<Constraint> constraints); | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * Releases an existing path. | ||
| 55 | + * | ||
| 56 | + * @param tunnelId tunnel identifier | ||
| 57 | + * @return false on failure and true on successful path removal | ||
| 58 | + */ | ||
| 59 | + boolean releasePath(TunnelId tunnelId); | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * Queries all paths. | ||
| 63 | + * | ||
| 64 | + * @return iterable of existing tunnels | ||
| 65 | + */ | ||
| 66 | + Iterable<Tunnel> queryAllPath(); | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * Queries particular path based on tunnel identifier. | ||
| 70 | + * | ||
| 71 | + * @param tunnelId tunnel identifier | ||
| 72 | + * @return tunnel if path exists, otherwise null | ||
| 73 | + */ | ||
| 74 | + Tunnel queryPath(TunnelId tunnelId); | ||
| 43 | } | 75 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment