use of org.onlab.packet.TpPort in project onos by opennetworkinglab.
the class OpenstackK8sIntegrationManager method setNodePortIngressRules.
private void setNodePortIngressRules(IpAddress k8sNodeIp, String osK8sExtPortName, boolean install) {
OpenstackNode osNode = osNodeByNodeIp(k8sNodeIp);
if (osNode == null) {
return;
}
PortNumber osK8sExtPortNum = portNumberByNodeIpAndPortName(k8sNodeIp, osK8sExtPortName);
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(osK8sExtPortNum).build();
Map<TpPort, TpPort> portRangeMatchMap = buildPortRangeMatches(NODE_PORT_MIN, NODE_PORT_MAX);
portRangeMatchMap.forEach((key, value) -> {
TrafficSelector.Builder tcpSelectorBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(k8sNodeIp, 32)).matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpDstMasked(key, value);
TrafficSelector.Builder udpSelectorBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(k8sNodeIp, 32)).matchIPProtocol(IPv4.PROTOCOL_UDP).matchUdpDstMasked(key, value);
osFlowRuleService.setRule(appId, osNode.intgBridge(), tcpSelectorBuilder.build(), treatment, PRIORITY_CNI_PT_NODE_PORT_IP_RULE, PRE_FLAT_TABLE, install);
osFlowRuleService.setRule(appId, osNode.intgBridge(), udpSelectorBuilder.build(), treatment, PRIORITY_CNI_PT_NODE_PORT_IP_RULE, PRE_FLAT_TABLE, install);
});
}
use of org.onlab.packet.TpPort in project onos by opennetworkinglab.
the class TelemetryVflowListCommand method doExecute.
@Override
protected void doExecute() {
CoreService coreService = get(CoreService.class);
FlowRuleService flowService = get(FlowRuleService.class);
ApplicationId appId = coreService.getAppId(OPENSTACK_TELEMETRY_APP_ID);
List<FlowEntry> flows = Lists.newArrayList(flowService.getFlowEntriesById(appId));
print(FORMAT, "SrcIp", "SrcPort", "DstIp", "DstPort", "Protocol");
for (FlowEntry entry : flows) {
TrafficSelector selector = entry.selector();
IpPrefix srcIp = ((IPCriterion) selector.getCriterion(IPV4_SRC)).ip();
IpPrefix dstIp = ((IPCriterion) selector.getCriterion(IPV4_DST)).ip();
TpPort srcPort = TpPort.tpPort(0);
TpPort dstPort = TpPort.tpPort(0);
String protocolStr = "ANY";
Criterion ipProtocolCriterion = selector.getCriterion(IP_PROTO);
if (ipProtocolCriterion != null) {
short protocol = ((IPProtocolCriterion) selector.getCriterion(IP_PROTO)).protocol();
if (protocol == PROTOCOL_TCP) {
srcPort = ((TcpPortCriterion) selector.getCriterion(TCP_SRC)).tcpPort();
dstPort = ((TcpPortCriterion) selector.getCriterion(TCP_DST)).tcpPort();
protocolStr = TCP;
}
if (protocol == PROTOCOL_UDP) {
srcPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
dstPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
protocolStr = UDP;
}
}
print(FORMAT, srcIp.toString(), srcPort.toString(), dstIp.toString(), dstPort.toString(), protocolStr);
}
}
use of org.onlab.packet.TpPort in project onos by opennetworkinglab.
the class NetconfAccessInfo method valueOf.
/**
* Builds NetconfAccessInfo from json.
* @param root json root node for NetconfAccessinfo
* @return NETCONF access information
* @throws WorkflowException workflow exception
*/
public static NetconfAccessInfo valueOf(JsonNode root) throws WorkflowException {
JsonNode node = root.at(ptr(REMOTE_IP));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid remoteIp for " + root);
}
IpAddress remoteIp = IpAddress.valueOf(node.asText());
node = root.at(ptr(PORT));
if (node == null || !(node instanceof NumericNode)) {
throw new WorkflowException("invalid port for " + root);
}
TpPort tpPort = TpPort.tpPort(node.asInt());
node = root.at(ptr(USER));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid user for " + root);
}
String strUser = node.asText();
node = root.at(ptr(PASSWORD));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid password for " + root);
}
String strPassword = node.asText();
return new NetconfAccessInfo(remoteIp, tpPort, strUser, strPassword);
}
use of org.onlab.packet.TpPort in project onos by opennetworkinglab.
the class PiCriterionTranslatorsTest method testSctpPortCriterion.
@Test
public void testSctpPortCriterion() throws Exception {
TpPort value1 = TpPort.tpPort(random.nextInt(1 << 16));
TpPort value2 = TpPort.tpPort(random.nextInt(1 << 16));
TpPort mask = TpPort.tpPort(random.nextInt(1 << 16));
int bitWidth = 16;
SctpPortCriterion criterion = (SctpPortCriterion) Criteria.matchSctpDst(value1);
PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);
SctpPortCriterion maskedCriterion = (SctpPortCriterion) Criteria.matchSctpDstMasked(value2, mask);
PiTernaryFieldMatch ternaryMatch = (PiTernaryFieldMatch) translateCriterion(maskedCriterion, fieldId, TERNARY, bitWidth);
assertThat(exactMatch.value().asReadOnlyBuffer().getShort(), is((short) criterion.sctpPort().toInt()));
assertThat(ternaryMatch.value().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.sctpPort().toInt()));
assertThat(ternaryMatch.mask().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.mask().toInt()));
}
use of org.onlab.packet.TpPort in project onos by opennetworkinglab.
the class OvsdbControllerConfig method getOvsdbClientService.
// Used for getting OvsdbClientService.
private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
OvsdbController ovsController = handler.get(OvsdbController.class);
DeviceService deviceService = handler.get(DeviceService.class);
DeviceId ofDeviceId = handler.data().deviceId();
String[] mgmtAddress = deviceService.getDevice(ofDeviceId).annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS).split(":");
String targetIp = mgmtAddress[0];
TpPort targetPort = null;
if (mgmtAddress.length > 1) {
targetPort = TpPort.tpPort(Integer.parseInt(mgmtAddress[1]));
}
List<OvsdbNodeId> nodeIds = ovsController.getNodeIds().stream().filter(nodeId -> nodeId.getIpAddress().equals(targetIp)).collect(Collectors.toList());
if (nodeIds.isEmpty()) {
// TODO decide what port?
ovsController.connect(IpAddress.valueOf(targetIp), targetPort == null ? TpPort.tpPort(OvsdbConstant.OVSDBPORT) : targetPort);
// FIXME... connect is async
delay(1000);
}
List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream().filter(nodeId -> nodeId.getIpAddress().equals(targetIp)).map(ovsController::getOvsdbClient).filter(cs -> cs.getBridges().stream().anyMatch(b -> dpidMatches(b, ofDeviceId))).collect(Collectors.toList());
checkState(!clientServices.isEmpty(), "No clientServices found");
// FIXME add connection to management address if null --> done ?
return !clientServices.isEmpty() ? clientServices.get(0) : null;
}
Aggregations