use of org.openkilda.server42.control.messaging.Control.CommandPacket in project open-kilda by telstra.
the class Gate method getFlowListCommandPacket.
private CommandPacket getFlowListCommandPacket(String switchIdKey) {
SwitchId switchId = new SwitchId(switchIdKey);
Builder builder = CommandPacket.newBuilder();
builder.setType(Type.LIST_FLOWS);
FlowRttControl.ListFlowsFilter listFlowsFilter = FlowRttControl.ListFlowsFilter.newBuilder().setDstMac(switchId.toMacAddress()).build();
builder.addCommand(Any.pack(listFlowsFilter));
return builder.build();
}
use of org.openkilda.server42.control.messaging.Control.CommandPacket in project open-kilda by telstra.
the class Gate method listen.
@KafkaHandler
void listen(ListFlowsRequest data, @Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) String switchIdKey) {
CommandPacket commandPacket = getFlowListCommandPacket(switchIdKey);
try {
CommandPacketResponse serverResponse = zeroMqClient.send(commandPacket);
if (serverResponse == null) {
log.error("No response from server on {}", data.getHeaders().getCorrelationId());
return;
}
HashSet<String> flowList = new HashSet<>();
for (Any any : serverResponse.getResponseList()) {
flowList.add(any.unpack(Flow.class).getFlowId());
}
ListFlowsResponse response = ListFlowsResponse.builder().headers(data.getHeaders()).flowIds(flowList).build();
template.send(toStorm, response);
} catch (InvalidProtocolBufferException e) {
log.error("Marshalling error on {}", data);
}
}
use of org.openkilda.server42.control.messaging.Control.CommandPacket in project open-kilda by telstra.
the class Gate method listen.
@KafkaHandler
void listen(ListFlowsOnSwitch data, @Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) String switchIdKey) {
CommandPacket commandPacket = getFlowListCommandPacket(switchIdKey);
try {
CommandPacketResponse serverResponse = zeroMqClient.send(commandPacket);
if (serverResponse == null) {
log.error("No response from server on {}", data.getHeaders().getCorrelationId());
return;
}
for (Any any : serverResponse.getResponseList()) {
String flowId = any.unpack(Flow.class).getFlowId();
if (!data.getFlowIds().contains(flowId)) {
removeFlow(flowId, FlowDirection.FORWARD);
removeFlow(flowId, FlowDirection.REVERSE);
}
}
} catch (InvalidProtocolBufferException e) {
log.error("Marshalling error on {}", data);
}
}
use of org.openkilda.server42.control.messaging.Control.CommandPacket in project open-kilda by telstra.
the class Gate method removeFlow.
private void removeFlow(String flowId, FlowDirection direction) throws InvalidProtocolBufferException {
Builder builder = CommandPacket.newBuilder();
Flow flow = Flow.newBuilder().setFlowId(flowId).setDirection(FlowDirection.toBoolean(direction)).build();
FlowRttControl.RemoveFlow removeFlow = FlowRttControl.RemoveFlow.newBuilder().setFlow(flow).build();
builder.setType(Type.REMOVE_FLOW);
builder.addCommand(Any.pack(removeFlow));
CommandPacket packet = builder.build();
zeroMqClient.send(packet);
}
use of org.openkilda.server42.control.messaging.Control.CommandPacket in project open-kilda by telstra.
the class Gate method listen.
@KafkaHandler
void listen(@Payload AddFlow data, @Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) String switchIdKey) {
SwitchId switchId = new SwitchId(switchIdKey);
Builder builder = CommandPacket.newBuilder();
Flow flow = Flow.newBuilder().setFlowId(data.getFlowId()).setEncapsulationType(Flow.EncapsulationType.VLAN).setTunnelId(data.getTunnelId()).setTransitEncapsulationType(Flow.EncapsulationType.VLAN).setInnerTunnelId(data.getInnerTunnelId()).setTransitTunnelId(switchToVlanMap.get(switchIdKey)).setDirection(FlowDirection.toBoolean(data.getDirection())).setUdpSrcPort(flowRttUdpSrcPortOffset + data.getPort()).setDstMac(switchId.toMacAddress()).setHashCode(data.hashCode()).build();
FlowRttControl.AddFlow addFlow = FlowRttControl.AddFlow.newBuilder().setFlow(flow).build();
builder.setType(Type.ADD_FLOW);
builder.addCommand(Any.pack(addFlow));
CommandPacket packet = builder.build();
try {
zeroMqClient.send(packet);
} catch (InvalidProtocolBufferException e) {
log.error("Marshalling error on {}", data);
}
}
Aggregations