Open Kilda Java Documentation
Utils.java
Go to the documentation of this file.
1 /* Copyright 2017 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.messaging;
17 
19 
21 
22 import com.fasterxml.jackson.databind.ObjectMapper;
23 
27 public final class Utils {
31  public static final ObjectMapper MAPPER = new ObjectMapper();
35  public static final String TIMESTAMP = "timestamp";
39  public static final String TRANSACTION_ID = "transaction_id";
43  public static final String CORRELATION_ID = "correlation_id";
47  public static final String EXTRA_AUTH = "EXTRA_AUTH";
51  public static final String DESTINATION = "destination";
52 
53  public static final String ROUTE = "route";
57  public static final String PAYLOAD = "payload";
61  public static final String FLOW_ID = "flowid";
65  public static final String FLOW_PATH = "flowpath";
69  public static final String DEFAULT_CORRELATION_ID = "admin-request";
73  public static final String SYSTEM_CORRELATION_ID = "system-request";
77  public static final String HEALTH_CHECK_OPERATIONAL_STATUS = "operational";
81  public static final String HEALTH_CHECK_NON_OPERATIONAL_STATUS = "non-operational";
85  public static final int ETH_TYPE = 0x8100;
89  private static final int MIN_VLAN_ID = 0;
93  private static final int MAX_VLAN_ID = 4095;
94 
98  private Utils() {
99  throw new UnsupportedOperationException();
100  }
101 
108  public static boolean validateVlanRange(final Integer vlanId) {
109  return (vlanId >= MIN_VLAN_ID) && (vlanId <= MAX_VLAN_ID);
110  }
111 
119  public static boolean validateOutputVlanType(final Integer outputVlanId, final OutputVlanType outputVlanType) {
120  return (outputVlanId != null && outputVlanId != 0)
121  ? (OutputVlanType.PUSH.equals(outputVlanType) || OutputVlanType.REPLACE.equals(outputVlanType))
122  : (OutputVlanType.POP.equals(outputVlanType) || OutputVlanType.NONE.equals(outputVlanType));
123  }
124 
132  public static boolean validateInputVlanType(final Integer inputVlanId, final OutputVlanType outputVlanType) {
133  return (inputVlanId != null && inputVlanId != 0)
134  ? (OutputVlanType.POP.equals(outputVlanType) || OutputVlanType.REPLACE.equals(outputVlanType))
135  : (OutputVlanType.PUSH.equals(outputVlanType) || OutputVlanType.NONE.equals(outputVlanType));
136  }
137 
144  public static boolean validateSwitchId(SwitchId switchId) {
145  // TODO: check valid switch id
146  return switchId != null;
147  }
148 }
149 
static final String PAYLOAD
Definition: Utils.java:57
static boolean validateVlanRange(final Integer vlanId)
Definition: Utils.java:108
static final ObjectMapper MAPPER
Definition: Utils.java:31
static final String SYSTEM_CORRELATION_ID
Definition: Utils.java:73
static final String DESTINATION
Definition: Utils.java:51
static final int ETH_TYPE
Definition: Utils.java:85
static boolean validateSwitchId(SwitchId switchId)
Definition: Utils.java:144
static final String HEALTH_CHECK_NON_OPERATIONAL_STATUS
Definition: Utils.java:81
static final String TRANSACTION_ID
Definition: Utils.java:39
static final String DEFAULT_CORRELATION_ID
Definition: Utils.java:69
static final String CORRELATION_ID
Definition: Utils.java:43
static final String HEALTH_CHECK_OPERATIONAL_STATUS
Definition: Utils.java:77
static final String EXTRA_AUTH
Definition: Utils.java:47
static final String FLOW_PATH
Definition: Utils.java:65
static boolean validateOutputVlanType(final Integer outputVlanId, final OutputVlanType outputVlanType)
Definition: Utils.java:119
static final String ROUTE
Definition: Utils.java:53
static final String TIMESTAMP
Definition: Utils.java:35
static final String FLOW_ID
Definition: Utils.java:61
static boolean validateInputVlanType(final Integer inputVlanId, final OutputVlanType outputVlanType)
Definition: Utils.java:132