Open Kilda Java Documentation
FlowMapper.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.northbound.converter;
17 
31 
32 import org.mapstruct.Mapper;
33 import org.mapstruct.Mapping;
34 import org.mapstruct.Mappings;
35 
36 import java.util.ArrayList;
37 import java.util.List;
38 
39 @Mapper(componentModel = "spring")
40 public interface FlowMapper {
41 
42  VerificationOutput toVerificationOutput(FlowVerificationResponse response);
43 
44  @Mappings({
45  @Mapping(source = "flowId", target = "id"),
46  @Mapping(source = "path", target = "path"),
47  @Mapping(source = "rerouted", target = "rerouted")
48  })
49  FlowReroutePayload toReroutePayload(String flowId, PathInfoData path, boolean rerouted);
50 
51  @Mappings({
52  @Mapping(source = "flowId", target = "id"),
53  @Mapping(source = "state", target = "status")
54  })
55  FlowIdStatusPayload toFlowIdStatusPayload(BidirectionalFlow flow);
56 
57  @Mappings({
58  @Mapping(source = "flowId", target = "id"),
59  @Mapping(source = "forward", target = "forwardPath"),
60  @Mapping(source = "reverse", target = "reversePath")
61  })
62  FlowPathPayload toFlowPathPayload(BidirectionalFlow flow);
63 
67  default FlowPayload toFlowPayload(Flow flow) {
68  return new FlowPayload(
69  flow.getFlowId(),
71  flow.getSourceSwitch(),
72  flow.getSourcePort(),
73  flow.getSourceVlan()),
75  flow.getDestinationSwitch(),
76  flow.getDestinationPort(),
77  flow.getDestinationVlan()),
78  flow.getBandwidth(),
79  flow.isIgnoreBandwidth(),
80  flow.getDescription(),
81  flow.getLastUpdated(),
82  flow.getState().getState());
83  }
84 
92  default List<PathNodePayload> toPathNodePayloadList(Flow flow) {
93  List<PathNode> path = new ArrayList<>(flow.getFlowPath().getPath());
94  // add input and output nodes
95  path.add(0, new PathNode(flow.getSourceSwitch(), flow.getSourcePort(), 0));
96  path.add(new PathNode(flow.getDestinationSwitch(), flow.getDestinationPort(), 0));
97 
98  List<PathNodePayload> resultList = new ArrayList<>();
99  for (int i = 1; i < path.size(); i += 2) {
100  PathNode inputNode = path.get(i - 1);
101  PathNode outputNode = path.get(i);
102 
103  resultList.add(
104  new PathNodePayload(inputNode.getSwitchId(), inputNode.getPortNo(), outputNode.getPortNo()));
105  }
106  return resultList;
107  }
108 
113  if (error == null) {
114  return null;
115  }
116 
117  String message;
118  switch (error) {
119  case TIMEOUT:
120  message = "No ping for reasonable time";
121  break;
122  case WRITE_FAILURE:
123  message = "Can't send ping";
124  break;
125  case NOT_CAPABLE:
126  message = "Unable to perform flow verification due to unsupported switch (at least one)";
127  break;
128  default:
129  message = error.toString();
130  }
131 
132  return message;
133  }
134 }
target
Definition: nodes.py:50
default FlowPayload toFlowPayload(Flow flow)
Definition: FlowMapper.java:67
source
Definition: nodes.py:53
default List< PathNodePayload > toPathNodePayloadList(Flow flow)
Definition: FlowMapper.java:92
default String getVerificationError(FlowVerificationErrorCode error)