hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.odtn.internal; |
| 18 | |
| 19 | import java.util.HashMap; |
| 20 | import java.util.Map; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery; |
| 23 | import org.onosproject.odtn.TapiResolver; |
| 24 | import org.onosproject.odtn.utils.tapi.TapiCepRef; |
| 25 | import org.onosproject.odtn.utils.tapi.TapiConnection; |
| 26 | import org.onosproject.odtn.utils.tapi.TapiNepPair; |
| 27 | import org.onosproject.odtn.utils.tapi.TapiNepRef; |
| 28 | |
| 29 | import static org.onlab.osgi.DefaultServiceDirectory.getService; |
| 30 | import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.DEVICE_ID; |
| 31 | import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.ODTN_PORT_TYPE; |
| 32 | import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.CONNECTION_ID; |
| 33 | |
| 34 | import org.slf4j.Logger; |
| 35 | import org.slf4j.LoggerFactory; |
| 36 | |
| 37 | /** |
| 38 | * DCS-dependent Tapi path computation engine implementation. |
| 39 | */ |
| 40 | public class DefaultTapiPathComputer implements TapiPathComputer { |
| 41 | |
| 42 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 43 | protected TapiResolver resolver; |
| 44 | |
| 45 | public static DefaultTapiPathComputer create() { |
| 46 | DefaultTapiPathComputer self = new DefaultTapiPathComputer(); |
| 47 | self.resolver = getService(TapiResolver.class); |
| 48 | return self; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public TapiConnection pathCompute(TapiNepPair neps) { |
| 53 | log.info("Path compute with: {}", neps); |
| 54 | return pathComputeDetail(neps); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Compute and decide multi-hop route/path from e2e intent. |
| 59 | * <p> |
| 60 | * FIXME this can work only for Phase1.0, we need some features to: |
| 61 | * - define Route and select media channel |
| 62 | * - with pre-defined topology and forwarding constraint of each devices or domains |
| 63 | * - get all ConnectionEndPoint in the defined route and return them |
| 64 | * as list of Cep pair for each connection to be created |
| 65 | */ |
| 66 | private TapiConnection pathComputeDetail(TapiNepPair neps) { |
| 67 | return mockPathCompute(neps); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /** |
| 72 | * Mock to create path computation result. |
| 73 | * |
| 74 | * neps.left connection neps.right |
| 75 | * ■----------------------------------------------------■ |
| 76 | * \ / |
| 77 | * \ / |
| 78 | * \ leftLowerConnection / rightLowerConnection |
| 79 | * \ / |
| 80 | * \ / |
| 81 | * ■ ■ |
| 82 | * leftLineNep rightLineNep |
| 83 | */ |
| 84 | private TapiConnection mockPathCompute(TapiNepPair neps) { |
| 85 | TapiNepRef leftLineNep = mockGetTransponderLinePort(neps.left()); |
| 86 | TapiNepRef rightLineNep = mockGetTransponderLinePort(neps.right()); |
| 87 | |
| 88 | TapiConnection leftLowerConnection = TapiConnection.create( |
| 89 | TapiCepRef.create(neps.left(), neps.left().getCepIds().get(0)), |
| 90 | TapiCepRef.create(leftLineNep, leftLineNep.getCepIds().get(0)) |
| 91 | ); |
| 92 | |
| 93 | TapiConnection rightLowerConnection = TapiConnection.create( |
| 94 | TapiCepRef.create(neps.right(), neps.right().getCepIds().get(0)), |
| 95 | TapiCepRef.create(rightLineNep, rightLineNep.getCepIds().get(0)) |
| 96 | ); |
| 97 | |
| 98 | TapiConnection connection = TapiConnection.create( |
| 99 | TapiCepRef.create(neps.left(), neps.left().getCepIds().get(0)), |
| 100 | TapiCepRef.create(neps.right(), neps.right().getCepIds().get(0)) |
| 101 | ); |
| 102 | connection.addLowerConnection(leftLowerConnection) |
| 103 | .addLowerConnection(rightLowerConnection); |
| 104 | |
| 105 | return connection; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Mock to select line port from client port. |
| 110 | */ |
| 111 | private TapiNepRef mockGetTransponderLinePort(TapiNepRef cliNepRef) { |
| 112 | DeviceId deviceId = cliNepRef.getConnectPoint().deviceId(); |
| 113 | Map<String, String> filter = new HashMap<>(); |
| 114 | filter.put(DEVICE_ID, deviceId.toString()); |
| 115 | filter.put(ODTN_PORT_TYPE, OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.value()); |
| 116 | filter.put(CONNECTION_ID, cliNepRef.getConnectionId()); |
| 117 | return resolver.getNepRefs(filter).stream().findAny().get(); |
| 118 | } |
| 119 | |
| 120 | } |